Commit 39ff841d by Calen Pennington

Don't pass arguments to setUp (for UrlResetMixin)

The TestCase API doesn't accept arguments, so passing arguments for some
TestCase subclasses makes adding new inheritance/mixins tricky. Instead,
prefer configuration via class attributes for TestCases.
parent 6ba7133b
......@@ -33,9 +33,11 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase):
"""
Course Mode View tests
"""
URLCONF_MODULES = ['course_modes.urls']
@patch.dict(settings.FEATURES, {'MODE_CREATION_FOR_TESTING': True})
def setUp(self):
super(CourseModeViewTest, self).setUp('course_modes.urls')
super(CourseModeViewTest, self).setUp()
self.course = CourseFactory.create()
self.user = UserFactory.create(username="Bob", email="bob@example.com", password="edx")
self.client.login(username=self.user.username, password="edx")
......@@ -392,9 +394,11 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase):
class TrackSelectionEmbargoTest(UrlResetMixin, ModuleStoreTestCase):
"""Test embargo restrictions on the track selection page. """
URLCONF_MODULES = ['embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(TrackSelectionEmbargoTest, self).setUp('embargo')
super(TrackSelectionEmbargoTest, self).setUp()
# Create a course and course modes
self.course = CourseFactory.create()
......
......@@ -238,9 +238,11 @@ class EmbargoCheckAccessApiTests(ModuleStoreTestCase):
class EmbargoMessageUrlApiTests(UrlResetMixin, ModuleStoreTestCase):
"""Test the embargo API calls for retrieving the blocking message URLs. """
URLCONF_MODULES = ['embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(EmbargoMessageUrlApiTests, self).setUp('embargo')
super(EmbargoMessageUrlApiTests, self).setUp()
self.course = CourseFactory.create()
def tearDown(self):
......
......@@ -35,9 +35,11 @@ class EmbargoMiddlewareAccessTests(UrlResetMixin, ModuleStoreTestCase):
USERNAME = 'fred'
PASSWORD = 'secret'
URLCONF_MODULES = ['embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(EmbargoMiddlewareAccessTests, self).setUp('embargo')
super(EmbargoMiddlewareAccessTests, self).setUp()
self.user = UserFactory(username=self.USERNAME, password=self.PASSWORD)
self.course = CourseFactory.create()
self.client.login(username=self.USERNAME, password=self.PASSWORD)
......
......@@ -32,9 +32,11 @@ class CourseAccessMessageViewTest(UrlResetMixin, TestCase):
"""
URLCONF_MODULES = ['embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(CourseAccessMessageViewTest, self).setUp('embargo')
super(CourseAccessMessageViewTest, self).setUp()
@ddt.data(*messages.ENROLL_MESSAGES.keys())
def test_enrollment_messages(self, msg_key):
......
......@@ -890,10 +890,12 @@ class EnrollmentEmbargoTest(EnrollmentTestMixin, UrlResetMixin, ModuleStoreTestC
EMAIL = "bob@example.com"
PASSWORD = "edx"
URLCONF_MODULES = ['embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
""" Create a course and user, then log in. """
super(EnrollmentEmbargoTest, self).setUp('embargo')
super(EnrollmentEmbargoTest, self).setUp()
self.course = CourseFactory.create()
# Load a CourseOverview. This initial load should result in a cache
......
......@@ -32,6 +32,7 @@ class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase):
USERNAME = "Bob"
EMAIL = "bob@example.com"
PASSWORD = "edx"
URLCONF_MODULES = ['embargo']
@classmethod
def setUpClass(cls):
......@@ -42,7 +43,7 @@ class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase):
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
""" Create a course and user, then log in. """
super(EnrollmentTest, self).setUp('embargo')
super(EnrollmentTest, self).setUp()
self.user = UserFactory.create(username=self.USERNAME, email=self.EMAIL, password=self.PASSWORD)
self.client.login(username=self.USERNAME, password=self.PASSWORD)
self.course_limited.max_student_enrollments_allowed = 1
......
......@@ -40,6 +40,8 @@ def _finish_auth_url(params):
class LoginFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStoreTestCase):
"""Test rendering of the login form. """
URLCONF_MODULES = ['lms.urls']
@classmethod
def setUpClass(cls):
super(LoginFormTest, cls).setUpClass()
......@@ -47,7 +49,7 @@ class LoginFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStoreTes
@patch.dict(settings.FEATURES, {"ENABLE_COMBINED_LOGIN_REGISTRATION": False})
def setUp(self):
super(LoginFormTest, self).setUp('lms.urls')
super(LoginFormTest, self).setUp()
self.url = reverse("signin_user")
self.course_id = unicode(self.course.id)
......@@ -155,6 +157,8 @@ class LoginFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStoreTes
class RegisterFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStoreTestCase):
"""Test rendering of the registration form. """
URLCONF_MODULES = ['lms.urls']
@classmethod
def setUpClass(cls):
super(RegisterFormTest, cls).setUpClass()
......@@ -162,7 +166,7 @@ class RegisterFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStore
@patch.dict(settings.FEATURES, {"ENABLE_COMBINED_LOGIN_REGISTRATION": False})
def setUp(self):
super(RegisterFormTest, self).setUp('lms.urls')
super(RegisterFormTest, self).setUp()
self.url = reverse("register_user")
self.course_id = unicode(self.course.id)
......
......@@ -35,9 +35,11 @@ class TestCourseVerificationStatus(UrlResetMixin, ModuleStoreTestCase):
PAST = datetime.now(UTC) - timedelta(days=5)
FUTURE = datetime.now(UTC) + timedelta(days=5)
URLCONF_MODULES = ['verify_student.urls']
def setUp(self):
# Invoke UrlResetMixin
super(TestCourseVerificationStatus, self).setUp('verify_student.urls')
super(TestCourseVerificationStatus, self).setUp()
self.user = UserFactory(password="edx")
self.course = CourseFactory.create()
......
......@@ -29,6 +29,8 @@ class UrlResetMixin(object):
that affect the contents of urls.py
"""
URLCONF_MODULES = None
def _reset_urls(self, urlconf_modules):
"""Reset `urls.py` for a set of Django apps."""
for urlconf in urlconf_modules:
......@@ -39,29 +41,29 @@ class UrlResetMixin(object):
# Resolve a URL so that the new urlconf gets loaded
resolve('/')
def setUp(self, *args, **kwargs):
def setUp(self):
"""Reset Django urls before tests and after tests
If you need to reset `urls.py` from a particular Django app (or apps),
specify these modules in *args.
specify these modules by setting the URLCONF_MODULES class attribute.
Examples:
# Reload only the root urls.py
super(MyTestCase, self).setUp()
URLCONF_MODULES = None
# Reload urls from my_app
super(MyTestCase, self).setUp("my_app.urls")
URLCONF_MODULES = ['myapp.url']
# Reload urls from my_app and another_app
super(MyTestCase, self).setUp("my_app.urls", "another_app.urls")
URLCONF_MODULES = ['myapp.url', 'another_app.urls']
"""
super(UrlResetMixin, self).setUp(**kwargs)
super(UrlResetMixin, self).setUp()
urlconf_modules = [settings.ROOT_URLCONF]
if args:
urlconf_modules.extend(args)
if self.URLCONF_MODULES is not None:
urlconf_modules.extend(self.URLCONF_MODULES)
self._reset_urls(urlconf_modules)
self.addCleanup(lambda: self._reset_urls(urlconf_modules))
......
......@@ -1843,9 +1843,11 @@ class RedeemCodeEmbargoTests(UrlResetMixin, ModuleStoreTestCase):
USERNAME = 'bob'
PASSWORD = 'test'
URLCONF_MODULES = ['embargo']
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(RedeemCodeEmbargoTests, self).setUp('embargo')
super(RedeemCodeEmbargoTests, self).setUp()
self.course = CourseFactory.create()
self.user = UserFactory.create(username=self.USERNAME, password=self.PASSWORD)
result = self.client.login(username=self.user.username, password=self.PASSWORD)
......
......@@ -62,8 +62,10 @@ class StudentAccountUpdateTest(UrlResetMixin, TestCase):
INVALID_KEY = u"123abc"
URLCONF_MODULES = ['student_accounts.urls']
def setUp(self):
super(StudentAccountUpdateTest, self).setUp("student_account.urls")
super(StudentAccountUpdateTest, self).setUp()
# Create/activate a new account
activation_key = create_account(self.USERNAME, self.OLD_PASSWORD, self.OLD_EMAIL)
......@@ -213,9 +215,11 @@ class StudentAccountLoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMi
EMAIL = "bob@example.com"
PASSWORD = "password"
URLCONF_MODULES = ['embargo']
@mock.patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(StudentAccountLoginAndRegistrationTest, self).setUp('embargo')
super(StudentAccountLoginAndRegistrationTest, self).setUp()
# For these tests, three third party auth providers are enabled by default:
self.configure_google_provider(enabled=True)
......
......@@ -14,10 +14,13 @@ class SoftwareSecureFakeViewTest(UrlResetMixin, TestCase):
"""
Base class to test the fake software secure view.
"""
URLCONF_MODULES = ['verify_student.urls']
def setUp(self, **kwargs):
enable_software_secure_fake = kwargs.get('enable_software_secure_fake', False)
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_SOFTWARE_SECURE_FAKE': enable_software_secure_fake}):
super(SoftwareSecureFakeViewTest, self).setUp('verify_student.urls')
super(SoftwareSecureFakeViewTest, self).setUp()
self.user = UserFactory.create(username="test", password="test")
self.attempt = SoftwareSecurePhotoVerification.objects.create(user=self.user)
......
......@@ -104,9 +104,11 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
YESTERDAY = NOW - timedelta(days=1)
TOMORROW = NOW + timedelta(days=1)
URLCONF_MODULES = ['embargo']
@mock.patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(TestPayAndVerifyView, self).setUp('embargo')
super(TestPayAndVerifyView, self).setUp()
self.user = UserFactory.create(username=self.USERNAME, password=self.PASSWORD)
result = self.client.login(username=self.USERNAME, password=self.PASSWORD)
self.assertTrue(result, msg="Could not log in")
......
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