mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 09:37: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 logging
|
||||
|
||||
|
||||
def get_handlers():
|
||||
"""Obtain pointers to all StreamHandlers."""
|
||||
handlers = {}
|
||||
|
@ -18,6 +19,7 @@ def get_handlers():
|
|||
|
||||
return handlers
|
||||
|
||||
|
||||
def dont_print_garbage(f):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
restore = {}
|
||||
handlers = get_handlers()
|
||||
devnull = open(os.devnull, 'w')
|
||||
devnull = open(os.devnull, "w")
|
||||
|
||||
# redirect all the streams
|
||||
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.test import Client, TestCase
|
||||
|
@ -6,6 +6,7 @@ from django.urls import reverse
|
|||
|
||||
from .common import dont_print_garbage
|
||||
|
||||
|
||||
@patch("djangooidc.views.CLIENT", autospec=True)
|
||||
class ViewsTest(TestCase):
|
||||
def setUp(self):
|
||||
|
@ -16,11 +17,11 @@ class ViewsTest(TestCase):
|
|||
|
||||
def user_info(*args):
|
||||
return {
|
||||
"sub": "51234512345123",
|
||||
"sub": "TEST",
|
||||
"email": "test@example.com",
|
||||
"first_name": "Testy",
|
||||
"last_name": "Tester",
|
||||
"phone": "814564000"
|
||||
"phone": "814564000",
|
||||
}
|
||||
|
||||
def test_error_page(self, mock_client):
|
||||
|
@ -81,8 +82,8 @@ class ViewsTest(TestCase):
|
|||
def test_logout_redirect_url(self, mock_client):
|
||||
# setup
|
||||
session = self.client.session
|
||||
session["id_token_raw"] = "83450234852349"
|
||||
session["state"] = "7534298229506"
|
||||
session["id_token_raw"] = "TEST" # nosec B105
|
||||
session["state"] = "TEST" # nosec B105
|
||||
session.save()
|
||||
# mock
|
||||
mock_client.callback.side_effect = self.user_info
|
||||
|
@ -95,8 +96,10 @@ class ViewsTest(TestCase):
|
|||
# test
|
||||
response = self.client.get(reverse("logout"))
|
||||
# assert
|
||||
expected = "http://example.com/log_me_out?id_token_hint=83450234852349&state" \
|
||||
"=7534298229506&post_logout_redirect_uri=http%3A%2F%2Fexample.com%2Fback"
|
||||
expected = (
|
||||
"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
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(actual, expected)
|
||||
|
|
|
@ -21,6 +21,7 @@ try:
|
|||
CLIENT = Client(OP)
|
||||
logger.debug("client initialized %s" % CLIENT)
|
||||
except Exception as err:
|
||||
CLIENT = None # type: ignore
|
||||
logger.warning(err)
|
||||
logger.warning("Unable to configure OpenID Connect provider. Users cannot log in.")
|
||||
|
||||
|
|
|
@ -378,9 +378,9 @@ LOGGING = {
|
|||
# root logger catches anything, unless
|
||||
# defined by a more specific logger
|
||||
"root": {
|
||||
"handlers": ["console"],
|
||||
"level": "INFO"
|
||||
}
|
||||
"handlers": ["console"],
|
||||
"level": "INFO",
|
||||
},
|
||||
}
|
||||
|
||||
# endregion
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue