Commit 62fcc6f2 by David Baumgold

Use ddt for shib tests

parent 4e796c57
...@@ -5,6 +5,7 @@ Tests for Shibboleth Authentication ...@@ -5,6 +5,7 @@ Tests for Shibboleth Authentication
""" """
import unittest import unittest
from mock import patch from mock import patch
from ddt import ddt, data
from django.conf import settings from django.conf import settings
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
...@@ -74,6 +75,7 @@ def gen_all_identities(): ...@@ -74,6 +75,7 @@ def gen_all_identities():
yield _build_identity_dict(mail, display_name, given_name, surname) yield _build_identity_dict(mail, display_name, given_name, surname)
@ddt
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE, SESSION_ENGINE='django.contrib.sessions.backends.cache') @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE, SESSION_ENGINE='django.contrib.sessions.backends.cache')
class ShibSPTest(ModuleStoreTestCase): class ShibSPTest(ModuleStoreTestCase):
""" """
...@@ -271,13 +273,13 @@ class ShibSPTest(ModuleStoreTestCase): ...@@ -271,13 +273,13 @@ class ShibSPTest(ModuleStoreTestCase):
self._base_test_extauth_auto_activate_user_with_flag(log_user_string="user.id: 1") self._base_test_extauth_auto_activate_user_with_flag(log_user_string="user.id: 1")
@unittest.skipUnless(settings.FEATURES.get('AUTH_USE_SHIB'), "AUTH_USE_SHIB not set") @unittest.skipUnless(settings.FEATURES.get('AUTH_USE_SHIB'), "AUTH_USE_SHIB not set")
def test_registration_form(self): @data(*gen_all_identities())
def test_registration_form(self, identity):
""" """
Tests the registration form showing up with the proper parameters. Tests the registration form showing up with the proper parameters.
Uses django test client for its session support Uses django test client for its session support
""" """
for identity in gen_all_identities():
client = DjangoTestClient() client = DjangoTestClient()
# identity k/v pairs will show up in request.META # identity k/v pairs will show up in request.META
response = client.get(path='/shib-login/', data={}, follow=False, **identity) response = client.get(path='/shib-login/', data={}, follow=False, **identity)
...@@ -301,7 +303,8 @@ class ShibSPTest(ModuleStoreTestCase): ...@@ -301,7 +303,8 @@ class ShibSPTest(ModuleStoreTestCase):
client.session['ExternalAuthMap'].delete() client.session['ExternalAuthMap'].delete()
@unittest.skipUnless(settings.FEATURES.get('AUTH_USE_SHIB'), "AUTH_USE_SHIB not set") @unittest.skipUnless(settings.FEATURES.get('AUTH_USE_SHIB'), "AUTH_USE_SHIB not set")
def test_registration_form_submit(self): @data(*gen_all_identities())
def test_registration_form_submit(self, identity):
""" """
Tests user creation after the registration form that pops is submitted. If there is no shib Tests user creation after the registration form that pops is submitted. If there is no shib
ExternalAuthMap in the session, then the created user should take the username and email from the ExternalAuthMap in the session, then the created user should take the username and email from the
...@@ -309,7 +312,6 @@ class ShibSPTest(ModuleStoreTestCase): ...@@ -309,7 +312,6 @@ class ShibSPTest(ModuleStoreTestCase):
Uses django test client for its session support Uses django test client for its session support
""" """
for identity in gen_all_identities():
# First we pop the registration form # First we pop the registration form
client = DjangoTestClient() client = DjangoTestClient()
response1 = client.get(path='/shib-login/', data={}, follow=False, **identity) response1 = client.get(path='/shib-login/', data={}, follow=False, **identity)
...@@ -386,7 +388,8 @@ class ShibSPTest(ModuleStoreTestCase): ...@@ -386,7 +388,8 @@ class ShibSPTest(ModuleStoreTestCase):
user.delete() user.delete()
@unittest.skipUnless(settings.FEATURES.get('AUTH_USE_SHIB'), "AUTH_USE_SHIB not set") @unittest.skipUnless(settings.FEATURES.get('AUTH_USE_SHIB'), "AUTH_USE_SHIB not set")
def test_course_specific_login_and_reg(self): @data("", "shib:https://idp.stanford.edu/")
def test_course_specific_login_and_reg(self, domain):
""" """
Tests that the correct course specific login and registration urls work for shib Tests that the correct course specific login and registration urls work for shib
""" """
...@@ -398,7 +401,6 @@ class ShibSPTest(ModuleStoreTestCase): ...@@ -398,7 +401,6 @@ class ShibSPTest(ModuleStoreTestCase):
) )
# Test for cases where course is found # Test for cases where course is found
for domain in ["", "shib:https://idp.stanford.edu/"]:
# set domains # set domains
# temporarily set the branch to draft-preferred so we can update the course # temporarily set the branch to draft-preferred so we can update the course
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment