unit tests

This commit is contained in:
Rachid Mrad 2024-03-19 16:48:36 -04:00
parent 592e1bee06
commit e4c1b06f63
No known key found for this signature in database

View file

@ -133,17 +133,29 @@ class ViewsTest(TestCase):
we do not throw an exception. Rather, we attempt to login again."""
with less_console_noise():
# MOCK
# mock the acr_value to some string
# mock the callback function to raise the StateMismatch Exception
mock_client.get_default_acr_value.side_effect = self.create_acr
mock_client.callback.side_effect = StateMismatch()
# TEST
# test the login callback
response = self.client.get(reverse("openid_login_callback"))
# ASSERTIONS
# assert that the user is redirected to the start of the login process
# ASSERT
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "/")
# Check that the redirect_attempted flag is set in the session
self.assertTrue(self.client.session.get("redirect_attempted", False))
def test_login_callback_with_no_session_state_attempt_again_only_once(self, mock_client):
"""We only attempt to relogin once. After that, it's the error page for you."""
with less_console_noise():
# MOCK
mock_client.get_default_acr_value.side_effect = self.create_acr
mock_client.callback.side_effect = StateMismatch()
session = self.client.session
session['redirect_attempted'] = True
session.save()
# TEST
response = self.client.get(reverse("openid_login_callback"))
# ASSERT
self.assertEqual(response.status_code, 500)
def test_login_callback_reads_next(self, mock_client):
"""If the next value is set in the session, test that login_callback returns