mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +02:00
unit tests
This commit is contained in:
parent
592e1bee06
commit
e4c1b06f63
1 changed files with 17 additions and 5 deletions
|
@ -133,17 +133,29 @@ class ViewsTest(TestCase):
|
||||||
we do not throw an exception. Rather, we attempt to login again."""
|
we do not throw an exception. Rather, we attempt to login again."""
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
# MOCK
|
# 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.get_default_acr_value.side_effect = self.create_acr
|
||||||
mock_client.callback.side_effect = StateMismatch()
|
mock_client.callback.side_effect = StateMismatch()
|
||||||
# TEST
|
# TEST
|
||||||
# test the login callback
|
|
||||||
response = self.client.get(reverse("openid_login_callback"))
|
response = self.client.get(reverse("openid_login_callback"))
|
||||||
# ASSERTIONS
|
# ASSERT
|
||||||
# assert that the user is redirected to the start of the login process
|
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(response.url, "/")
|
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):
|
def test_login_callback_reads_next(self, mock_client):
|
||||||
"""If the next value is set in the session, test that login_callback returns
|
"""If the next value is set in the session, test that login_callback returns
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue