diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index e2de9d6236..c58c914ccc 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -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() diff --git a/common/djangoapps/embargo/tests/test_api.py b/common/djangoapps/embargo/tests/test_api.py index 383173fbee..217aab0927 100644 --- a/common/djangoapps/embargo/tests/test_api.py +++ b/common/djangoapps/embargo/tests/test_api.py @@ -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): diff --git a/common/djangoapps/embargo/tests/test_middleware.py b/common/djangoapps/embargo/tests/test_middleware.py index 369a3d29b0..953989ff5b 100644 --- a/common/djangoapps/embargo/tests/test_middleware.py +++ b/common/djangoapps/embargo/tests/test_middleware.py @@ -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) diff --git a/common/djangoapps/embargo/tests/test_views.py b/common/djangoapps/embargo/tests/test_views.py index 48a8c94653..09b3a48781 100644 --- a/common/djangoapps/embargo/tests/test_views.py +++ b/common/djangoapps/embargo/tests/test_views.py @@ -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): diff --git a/common/djangoapps/enrollment/tests/test_views.py b/common/djangoapps/enrollment/tests/test_views.py index 312c3de28f..722709bc29 100644 --- a/common/djangoapps/enrollment/tests/test_views.py +++ b/common/djangoapps/enrollment/tests/test_views.py @@ -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 diff --git a/common/djangoapps/student/tests/test_enrollment.py b/common/djangoapps/student/tests/test_enrollment.py index d8fa1c120a..acabe344c3 100644 --- a/common/djangoapps/student/tests/test_enrollment.py +++ b/common/djangoapps/student/tests/test_enrollment.py @@ -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 diff --git a/common/djangoapps/student/tests/test_login_registration_forms.py b/common/djangoapps/student/tests/test_login_registration_forms.py index f0f338721d..d7f8713069 100644 --- a/common/djangoapps/student/tests/test_login_registration_forms.py +++ b/common/djangoapps/student/tests/test_login_registration_forms.py @@ -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) diff --git a/common/djangoapps/student/tests/test_verification_status.py b/common/djangoapps/student/tests/test_verification_status.py index 022a0ec0f4..447fccdd96 100644 --- a/common/djangoapps/student/tests/test_verification_status.py +++ b/common/djangoapps/student/tests/test_verification_status.py @@ -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() diff --git a/common/djangoapps/util/testing.py b/common/djangoapps/util/testing.py index c33ce68148..20d8799be2 100644 --- a/common/djangoapps/util/testing.py +++ b/common/djangoapps/util/testing.py @@ -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)) diff --git a/lms/djangoapps/shoppingcart/tests/test_views.py b/lms/djangoapps/shoppingcart/tests/test_views.py index 60a12ee310..175fce6622 100644 --- a/lms/djangoapps/shoppingcart/tests/test_views.py +++ b/lms/djangoapps/shoppingcart/tests/test_views.py @@ -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) diff --git a/lms/djangoapps/student_account/test/test_views.py b/lms/djangoapps/student_account/test/test_views.py index 493d8bd1e5..782b18b307 100644 --- a/lms/djangoapps/student_account/test/test_views.py +++ b/lms/djangoapps/student_account/test/test_views.py @@ -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) diff --git a/lms/djangoapps/verify_student/tests/test_fake_software_secure.py b/lms/djangoapps/verify_student/tests/test_fake_software_secure.py index 8bb513d093..f33b69a2a9 100644 --- a/lms/djangoapps/verify_student/tests/test_fake_software_secure.py +++ b/lms/djangoapps/verify_student/tests/test_fake_software_secure.py @@ -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) diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index e1405a58fd..c6d8922dfb 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -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")