Fix tests in CI

This commit is contained in:
Seamus Johnston 2022-09-30 08:08:19 -05:00
parent 8ea7b98a37
commit b5ea6c8e39
No known key found for this signature in database
GPG key ID: 2F21225985069105
4 changed files with 19 additions and 12 deletions

View file

@ -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():

View file

@ -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)
@ -118,4 +121,4 @@ class ViewsTest(TestCase):
response = self.client.get(reverse("openid_logout_callback"))
# assert
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, reverse("logout"))
self.assertEqual(response.url, reverse("logout"))

View file

@ -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.")

View file

@ -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