mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 01:27:03 +02:00
Fix tests in CI
This commit is contained in:
parent
8ea7b98a37
commit
b5ea6c8e39
4 changed files with 19 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
def get_handlers():
|
def get_handlers():
|
||||||
"""Obtain pointers to all StreamHandlers."""
|
"""Obtain pointers to all StreamHandlers."""
|
||||||
handlers = {}
|
handlers = {}
|
||||||
|
@ -18,6 +19,7 @@ def get_handlers():
|
||||||
|
|
||||||
return handlers
|
return handlers
|
||||||
|
|
||||||
|
|
||||||
def dont_print_garbage(f):
|
def dont_print_garbage(f):
|
||||||
"""
|
"""
|
||||||
Decorator to place on tests to silence console logging.
|
Decorator to place on tests to silence console logging.
|
||||||
|
@ -27,10 +29,11 @@ def dont_print_garbage(f):
|
||||||
|
|
||||||
It can easily be removed to debug a failing test.
|
It can easily be removed to debug a failing test.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
restore = {}
|
restore = {}
|
||||||
handlers = get_handlers()
|
handlers = get_handlers()
|
||||||
devnull = open(os.devnull, 'w')
|
devnull = open(os.devnull, "w")
|
||||||
|
|
||||||
# redirect all the streams
|
# redirect all the streams
|
||||||
for handler in handlers.values():
|
for handler in handlers.values():
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from unittest.mock import patch, Mock
|
from unittest.mock import patch
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.test import Client, TestCase
|
from django.test import Client, TestCase
|
||||||
|
@ -6,6 +6,7 @@ from django.urls import reverse
|
||||||
|
|
||||||
from .common import dont_print_garbage
|
from .common import dont_print_garbage
|
||||||
|
|
||||||
|
|
||||||
@patch("djangooidc.views.CLIENT", autospec=True)
|
@patch("djangooidc.views.CLIENT", autospec=True)
|
||||||
class ViewsTest(TestCase):
|
class ViewsTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -16,11 +17,11 @@ class ViewsTest(TestCase):
|
||||||
|
|
||||||
def user_info(*args):
|
def user_info(*args):
|
||||||
return {
|
return {
|
||||||
"sub": "51234512345123",
|
"sub": "TEST",
|
||||||
"email": "test@example.com",
|
"email": "test@example.com",
|
||||||
"first_name": "Testy",
|
"first_name": "Testy",
|
||||||
"last_name": "Tester",
|
"last_name": "Tester",
|
||||||
"phone": "814564000"
|
"phone": "814564000",
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_error_page(self, mock_client):
|
def test_error_page(self, mock_client):
|
||||||
|
@ -81,8 +82,8 @@ class ViewsTest(TestCase):
|
||||||
def test_logout_redirect_url(self, mock_client):
|
def test_logout_redirect_url(self, mock_client):
|
||||||
# setup
|
# setup
|
||||||
session = self.client.session
|
session = self.client.session
|
||||||
session["id_token_raw"] = "83450234852349"
|
session["id_token_raw"] = "TEST" # nosec B105
|
||||||
session["state"] = "7534298229506"
|
session["state"] = "TEST" # nosec B105
|
||||||
session.save()
|
session.save()
|
||||||
# mock
|
# mock
|
||||||
mock_client.callback.side_effect = self.user_info
|
mock_client.callback.side_effect = self.user_info
|
||||||
|
@ -95,8 +96,10 @@ class ViewsTest(TestCase):
|
||||||
# test
|
# test
|
||||||
response = self.client.get(reverse("logout"))
|
response = self.client.get(reverse("logout"))
|
||||||
# assert
|
# assert
|
||||||
expected = "http://example.com/log_me_out?id_token_hint=83450234852349&state" \
|
expected = (
|
||||||
"=7534298229506&post_logout_redirect_uri=http%3A%2F%2Fexample.com%2Fback"
|
"http://example.com/log_me_out?id_token_hint=TEST&state"
|
||||||
|
"=TEST&post_logout_redirect_uri=http%3A%2F%2Fexample.com%2Fback"
|
||||||
|
)
|
||||||
actual = response.url
|
actual = response.url
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
|
@ -21,6 +21,7 @@ try:
|
||||||
CLIENT = Client(OP)
|
CLIENT = Client(OP)
|
||||||
logger.debug("client initialized %s" % CLIENT)
|
logger.debug("client initialized %s" % CLIENT)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
CLIENT = None # type: ignore
|
||||||
logger.warning(err)
|
logger.warning(err)
|
||||||
logger.warning("Unable to configure OpenID Connect provider. Users cannot log in.")
|
logger.warning("Unable to configure OpenID Connect provider. Users cannot log in.")
|
||||||
|
|
||||||
|
|
|
@ -378,9 +378,9 @@ LOGGING = {
|
||||||
# root logger catches anything, unless
|
# root logger catches anything, unless
|
||||||
# defined by a more specific logger
|
# defined by a more specific logger
|
||||||
"root": {
|
"root": {
|
||||||
"handlers": ["console"],
|
"handlers": ["console"],
|
||||||
"level": "INFO"
|
"level": "INFO",
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue