diff --git a/mozilla_django_oidc/test.py b/mozilla_django_oidc/test.py new file mode 100644 index 00000000..7f812e1e --- /dev/null +++ b/mozilla_django_oidc/test.py @@ -0,0 +1,11 @@ +from django.test.client import Client + + +class OIDCClient(Client): + oidc_id_token = 'some_oidc_token' + + def __init__(self, enforce_csrf_checks=False, **defaults): + super(OIDCClient, self).__init__(enforce_csrf_checks=enforce_csrf_checks, **defaults) + session = self.session + session['oidc_id_token'] = self.oidc_id_token + session.save() diff --git a/tests/test_oidc_client.py b/tests/test_oidc_client.py new file mode 100644 index 00000000..b539a6c4 --- /dev/null +++ b/tests/test_oidc_client.py @@ -0,0 +1,23 @@ +from unittest import TestCase + +from django.test.client import Client + +from mozilla_django_oidc.test import OIDCClient + + +class TestOIDCClient(TestCase): + def test_inherits_from_django_test_client(self): + self.assertIsInstance(OIDCClient(), Client) + + def test_oidc_id_token_is_set_to_some_token_by_default(self): + self.assertEqual(OIDCClient.oidc_id_token, 'some_oidc_token') + + def test_sets_oidc_id_token_for_session(self): + self.assertEqual(OIDCClient().session['oidc_id_token'], 'some_oidc_token') + + def test_sets_specified_id_token_for_session(self): + class StubOIDCClient(OIDCClient): + oidc_id_token = 'some_other_oidc_token' + + client = StubOIDCClient() + self.assertEqual(client.session['oidc_id_token'], 'some_other_oidc_token')