diff --git a/cms/djangoapps/contentstore/tests/test_utils.py b/cms/djangoapps/contentstore/tests/test_utils.py index cc2881aa22..37c68a88d5 100644 --- a/cms/djangoapps/contentstore/tests/test_utils.py +++ b/cms/djangoapps/contentstore/tests/test_utils.py @@ -12,6 +12,7 @@ from contentstore import utils from contentstore.tests.utils import CourseTestCase from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from opaque_keys.edx.locations import SlashSeparatedCourseKey from xmodule.modulestore.django import modulestore @@ -164,7 +165,7 @@ class ExtraPanelTabTestCase(TestCase): self.assertEqual(actual_tabs, expected_tabs) -class CourseImageTestCase(TestCase): +class CourseImageTestCase(ModuleStoreTestCase): """Tests for course image URLs.""" def test_get_image_url(self): diff --git a/cms/djangoapps/contentstore/tests/utils.py b/cms/djangoapps/contentstore/tests/utils.py index 27bb81bf27..49fab3360a 100644 --- a/cms/djangoapps/contentstore/tests/utils.py +++ b/cms/djangoapps/contentstore/tests/utils.py @@ -67,7 +67,6 @@ class AjaxEnabledTestClient(Client): return self.get(path, data or {}, follow, HTTP_ACCEPT="application/json", **extra) -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CourseTestCase(ModuleStoreTestCase): """ Base class for Studio tests that require a logged in user and a course. @@ -81,6 +80,7 @@ class CourseTestCase(ModuleStoreTestCase): will be cleared out before each test case execution and deleted afterwards. """ + self.user_password = super(CourseTestCase, self).setUp() self.client = AjaxEnabledTestClient() diff --git a/cms/djangoapps/contentstore/views/tests/test_preview.py b/cms/djangoapps/contentstore/views/tests/test_preview.py index aa964cd253..c67d99d3be 100644 --- a/cms/djangoapps/contentstore/views/tests/test_preview.py +++ b/cms/djangoapps/contentstore/views/tests/test_preview.py @@ -22,7 +22,7 @@ from cms.djangoapps.xblock_config.models import StudioConfig from xmodule.modulestore.django import modulestore -class GetPreviewHtmlTestCase(TestCase): +class GetPreviewHtmlTestCase(ModuleStoreTestCase): """ Tests for get_preview_fragment. diff --git a/cms/djangoapps/contentstore/views/tests/test_tabs.py b/cms/djangoapps/contentstore/views/tests/test_tabs.py index 312c48139e..fd6e5aacac 100644 --- a/cms/djangoapps/contentstore/views/tests/test_tabs.py +++ b/cms/djangoapps/contentstore/views/tests/test_tabs.py @@ -6,6 +6,7 @@ from contentstore.tests.utils import CourseTestCase from django.test import TestCase from xmodule.x_module import STUDENT_VIEW from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.tabs import CourseTabList, WikiTab from contentstore.utils import reverse_course_url from xmodule.modulestore.django import modulestore @@ -192,7 +193,7 @@ class TabsPageTests(CourseTestCase): self.assertIn('', html) -class PrimitiveTabEdit(TestCase): +class PrimitiveTabEdit(ModuleStoreTestCase): """Tests for the primitive tab edit data manipulations""" def test_delete(self): diff --git a/common/djangoapps/course_about/tests/test_api.py b/common/djangoapps/course_about/tests/test_api.py index bfa690393d..52c133e759 100644 --- a/common/djangoapps/course_about/tests/test_api.py +++ b/common/djangoapps/course_about/tests/test_api.py @@ -17,14 +17,8 @@ from xmodule.modulestore.tests.django_utils import ( from xmodule.modulestore.tests.factories import CourseFactory, CourseAboutFactory from student.tests.factories import UserFactory -# Since we don't need any XML course fixtures, use a modulestore configuration -# that disables the XML modulestore. - -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - @ddt.ddt -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class CourseInfoTest(ModuleStoreTestCase, APITestCase): """ diff --git a/common/djangoapps/course_about/tests/test_data.py b/common/djangoapps/course_about/tests/test_data.py index e73c597464..2f075fa00a 100644 --- a/common/djangoapps/course_about/tests/test_data.py +++ b/common/djangoapps/course_about/tests/test_data.py @@ -16,12 +16,7 @@ from course_about import data from course_about.errors import CourseNotFoundError from xmodule.modulestore.django import modulestore -# Since we don't need any XML course fixtures, use a modulestore configuration -# that disables the XML modulestore. -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class CourseAboutDataTest(ModuleStoreTestCase): """ diff --git a/common/djangoapps/course_about/tests/test_views.py b/common/djangoapps/course_about/tests/test_views.py index 074048be33..62f5fda499 100644 --- a/common/djangoapps/course_about/tests/test_views.py +++ b/common/djangoapps/course_about/tests/test_views.py @@ -22,14 +22,8 @@ from course_about import api from course_about.errors import CourseNotFoundError, CourseAboutError from xmodule.modulestore.django import modulestore -# Since we don't need any XML course fixtures, use a modulestore configuration -# that disables the XML modulestore. - -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - @ddt.ddt -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class CourseInfoTest(ModuleStoreTestCase, APITestCase): """ diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index bce5d52434..434eee61a9 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -18,13 +18,7 @@ from student.models import CourseEnrollment from course_modes.models import CourseMode, Mode -# Since we don't need any XML course fixtures, use a modulestore configuration -# that disables the XML modulestore. -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - - @ddt.ddt -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase): @patch.dict(settings.FEATURES, {'MODE_CREATION_FOR_TESTING': True}) diff --git a/common/djangoapps/embargo/tests/test_forms.py b/common/djangoapps/embargo/tests/test_forms.py index 7728ad219b..e613b253d2 100644 --- a/common/djangoapps/embargo/tests/test_forms.py +++ b/common/djangoapps/embargo/tests/test_forms.py @@ -16,7 +16,6 @@ from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class EmbargoCourseFormTest(ModuleStoreTestCase): """Test the course form properly validates course IDs""" diff --git a/common/djangoapps/embargo/tests/test_middleware.py b/common/djangoapps/embargo/tests/test_middleware.py index 8ca248a4a6..6c0ef7cd08 100644 --- a/common/djangoapps/embargo/tests/test_middleware.py +++ b/common/djangoapps/embargo/tests/test_middleware.py @@ -24,13 +24,7 @@ from config_models.models import cache from embargo.models import EmbargoedCourse, EmbargoedState, IPFilter -# Since we don't need any XML course fixtures, use a modulestore configuration -# that disables the XML modulestore. -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - - @ddt.ddt -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class EmbargoMiddlewareTests(ModuleStoreTestCase): """ diff --git a/common/djangoapps/enrollment/tests/test_data.py b/common/djangoapps/enrollment/tests/test_data.py index aba98599ce..4959695193 100644 --- a/common/djangoapps/enrollment/tests/test_data.py +++ b/common/djangoapps/enrollment/tests/test_data.py @@ -19,13 +19,8 @@ from student.tests.factories import UserFactory, CourseModeFactory from student.models import CourseEnrollment, EnrollmentClosedError, CourseFullError, AlreadyEnrolledError from enrollment import data -# Since we don't need any XML course fixtures, use a modulestore configuration -# that disables the XML modulestore. -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - @ddt.ddt -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class EnrollmentDataTest(ModuleStoreTestCase): """ diff --git a/common/djangoapps/enrollment/tests/test_views.py b/common/djangoapps/enrollment/tests/test_views.py index 93d67fdefc..39175cee9b 100644 --- a/common/djangoapps/enrollment/tests/test_views.py +++ b/common/djangoapps/enrollment/tests/test_views.py @@ -20,13 +20,8 @@ from enrollment.errors import CourseEnrollmentError from student.tests.factories import UserFactory, CourseModeFactory from student.models import CourseEnrollment -# Since we don't need any XML course fixtures, use a modulestore configuration -# that disables the XML modulestore. -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - @ddt.ddt -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class EnrollmentTest(ModuleStoreTestCase, APITestCase): """ diff --git a/common/djangoapps/external_auth/tests/test_shib.py b/common/djangoapps/external_auth/tests/test_shib.py index ba6a81f519..7cebbaf6ff 100644 --- a/common/djangoapps/external_auth/tests/test_shib.py +++ b/common/djangoapps/external_auth/tests/test_shib.py @@ -73,7 +73,7 @@ def gen_all_identities(): @ddt -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE, SESSION_ENGINE='django.contrib.sessions.backends.cache') +@override_settings(SESSION_ENGINE='django.contrib.sessions.backends.cache') class ShibSPTest(ModuleStoreTestCase): """ Tests for the Shibboleth SP, which communicates via request.META diff --git a/common/djangoapps/geoinfo/tests/test_middleware.py b/common/djangoapps/geoinfo/tests/test_middleware.py index b50e96166e..2864e7338c 100644 --- a/common/djangoapps/geoinfo/tests/test_middleware.py +++ b/common/djangoapps/geoinfo/tests/test_middleware.py @@ -14,7 +14,6 @@ from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from student.tests.factories import UserFactory, AnonymousUserFactory -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CountryMiddlewareTests(TestCase): """ Tests of CountryMiddleware. diff --git a/common/djangoapps/reverification/tests/test_models.py b/common/djangoapps/reverification/tests/test_models.py index 8ffddc8a17..22d5456bd2 100644 --- a/common/djangoapps/reverification/tests/test_models.py +++ b/common/djangoapps/reverification/tests/test_models.py @@ -14,7 +14,6 @@ from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestMidcourseReverificationWindow(ModuleStoreTestCase): """ Tests for MidcourseReverificationWindow objects """ diff --git a/common/djangoapps/student/tests/test_bulk_email_settings.py b/common/djangoapps/student/tests/test_bulk_email_settings.py index a2e9651d69..886729d56f 100644 --- a/common/djangoapps/student/tests/test_bulk_email_settings.py +++ b/common/djangoapps/student/tests/test_bulk_email_settings.py @@ -24,12 +24,12 @@ from xmodule.modulestore.tests.factories import CourseFactory from bulk_email.models import CourseAuthorization # pylint: disable=import-error -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class TestStudentDashboardEmailView(ModuleStoreTestCase): """ Check for email view displayed with flag """ + def setUp(self): super(TestStudentDashboardEmailView, self).setUp() @@ -92,12 +92,13 @@ class TestStudentDashboardEmailView(ModuleStoreTestCase): self.assertTrue(self.email_modal_link in response.content) -@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase): """ Check for email view on student dashboard, with XML backed course. """ + MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE + def setUp(self): self.course_name = 'edX/toy/2012_Fall' diff --git a/common/djangoapps/student/tests/test_enrollment.py b/common/djangoapps/student/tests/test_enrollment.py index b99126c494..7e4fcd3fa6 100644 --- a/common/djangoapps/student/tests/test_enrollment.py +++ b/common/djangoapps/student/tests/test_enrollment.py @@ -8,25 +8,19 @@ from mock import patch from django.test.utils import override_settings from django.conf import settings from django.core.urlresolvers import reverse -from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, mixed_store_config -) +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from student.tests.factories import UserFactory, CourseModeFactory from student.models import CourseEnrollment -# Since we don't need any XML course fixtures, use a modulestore configuration -# that disables the XML modulestore. -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - @ddt.ddt -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class EnrollmentTest(ModuleStoreTestCase): """ Test student enrollment, especially with different course modes. """ + USERNAME = "Bob" EMAIL = "bob@example.com" PASSWORD = "edx" diff --git a/common/djangoapps/student/tests/test_login.py b/common/djangoapps/student/tests/test_login.py index 273cc2af47..d54ccde391 100644 --- a/common/djangoapps/student/tests/test_login.py +++ b/common/djangoapps/student/tests/test_login.py @@ -319,11 +319,11 @@ class LoginTest(TestCase): self.assertNotIn(log_string, format_string) -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class ExternalAuthShibTest(ModuleStoreTestCase): """ Tests how login_user() interacts with ExternalAuth, in particular Shib """ + def setUp(self): super(ExternalAuthShibTest, self).setUp() self.course = CourseFactory.create( diff --git a/common/djangoapps/student/tests/test_login_registration_forms.py b/common/djangoapps/student/tests/test_login_registration_forms.py index fd992caf4d..bd8103252a 100644 --- a/common/djangoapps/student/tests/test_login_registration_forms.py +++ b/common/djangoapps/student/tests/test_login_registration_forms.py @@ -12,9 +12,7 @@ from django.test.utils import override_settings from util.testing import UrlResetMixin from xmodule.modulestore.tests.factories import CourseFactory from student.tests.factories import CourseModeFactory -from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, mixed_store_config -) +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # This relies on third party auth being enabled and configured @@ -23,10 +21,6 @@ from xmodule.modulestore.tests.django_utils import ( THIRD_PARTY_AUTH_BACKENDS = ["google-oauth2", "facebook"] THIRD_PARTY_AUTH_PROVIDERS = ["Google", "Facebook"] -# Since we don't need any XML course fixtures, use a modulestore configuration -# that disables the XML modulestore. -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - def _third_party_login_url(backend_name, auth_entry, course_id=None, redirect_url=None): """Construct the login URL to start third party authentication. """ @@ -43,7 +37,6 @@ def _third_party_login_url(backend_name, auth_entry, course_id=None, redirect_ur @ddt.ddt -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class LoginFormTest(UrlResetMixin, ModuleStoreTestCase): """Test rendering of the login form. """ @@ -156,7 +149,6 @@ class LoginFormTest(UrlResetMixin, ModuleStoreTestCase): @ddt.ddt -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class RegisterFormTest(UrlResetMixin, ModuleStoreTestCase): """Test rendering of the registration form. """ diff --git a/common/djangoapps/student/tests/test_verification_status.py b/common/djangoapps/student/tests/test_verification_status.py index ae5575863c..dfaa1908e1 100644 --- a/common/djangoapps/student/tests/test_verification_status.py +++ b/common/djangoapps/student/tests/test_verification_status.py @@ -17,17 +17,13 @@ from student.helpers import ( ) from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from student.tests.factories import UserFactory, CourseEnrollmentFactory from course_modes.tests.factories import CourseModeFactory from verify_student.models import SoftwareSecurePhotoVerification # pylint: disable=F0401 from util.testing import UrlResetMixin -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - - -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @patch.dict(settings.FEATURES, {'AUTOMATIC_VERIFY_STUDENT_IDENTITY_FOR_TESTING': True}) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @ddt.ddt diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index 44a64cc5a6..4a4a619ca5 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -28,7 +28,6 @@ from student.views import (process_survey_link, _cert_info, from student.tests.factories import UserFactory, CourseModeFactory from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE # These imports refer to lms djangoapps. # Their testcases are only run under lms. @@ -180,7 +179,6 @@ class CourseEndingTest(TestCase): self.assertIsNone(_cert_info(user, course2, cert_status)) -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class DashboardTest(ModuleStoreTestCase): """ Tests for dashboard utility functions @@ -615,7 +613,6 @@ class EnrollInCourseTest(TestCase): self.assert_enrollment_mode_change_event_was_emitted(user, course_id, "honor") -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class ChangeEnrollmentViewTest(ModuleStoreTestCase): """Tests the student.views.change_enrollment view""" @@ -698,7 +695,6 @@ class ChangeEnrollmentViewTest(ModuleStoreTestCase): self.assertEqual(enrollment_mode, u'honor') -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class PaidRegistrationTest(ModuleStoreTestCase): """ Tests for paid registration functionality (not verified student), involves shoppingcart @@ -731,7 +727,6 @@ class PaidRegistrationTest(ModuleStoreTestCase): shoppingcart.models.Order.get_cart_for_user(self.user), self.course.id)) -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class AnonymousLookupTable(ModuleStoreTestCase): """ Tests for anonymous_id_functions diff --git a/common/djangoapps/third_party_auth/tests/test_change_enrollment.py b/common/djangoapps/third_party_auth/tests/test_change_enrollment.py index b94418f6d5..159cac6c75 100644 --- a/common/djangoapps/third_party_auth/tests/test_change_enrollment.py +++ b/common/djangoapps/third_party_auth/tests/test_change_enrollment.py @@ -16,14 +16,10 @@ from django.test.utils import override_settings from xmodule.modulestore.tests.factories import CourseFactory from student.tests.factories import UserFactory, CourseModeFactory from student.models import CourseEnrollment -from xmodule.modulestore.tests.django_utils import ( - ModuleStoreTestCase, mixed_store_config -) +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from openedx.core.djangoapps.user_api.models import UserOrgTag -MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) - THIRD_PARTY_AUTH_CONFIGURED = ( settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH') and getattr(settings, 'THIRD_PARTY_AUTH', {}) @@ -31,7 +27,6 @@ THIRD_PARTY_AUTH_CONFIGURED = ( @unittest.skipUnless(THIRD_PARTY_AUTH_CONFIGURED, "Third party auth must be configured") -@override_settings(MODULESTORE=MODULESTORE_CONFIG) @ddt.ddt class PipelineEnrollmentTest(ModuleStoreTestCase): """Test that the pipeline auto-enrolls students upon successful authentication. """ diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index bc5d296b70..93090ae555 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -12,6 +12,7 @@ from mock import patch from django.conf import settings from django.contrib.auth.models import User from django.test import TestCase +from django.test.utils import override_settings from request_cache.middleware import RequestCache from xmodule.contentstore.django import _CONTENTSTORE @@ -189,15 +190,14 @@ class ModuleStoreTestCase(TestCase): Usage: 1. Create a subclass of `ModuleStoreTestCase` - 2. Use Django's @override_settings decorator to use - the desired modulestore configuration. + 2. (optional) If you need a specific variety of modulestore, or particular ModuleStore + options, set the MODULESTORE class attribute of your test class to the + appropriate modulestore config. For example: - MIXED_CONFIG = mixed_store_config(data_dir, mappings) - - @override_settings(MODULESTORE=MIXED_CONFIG) class FooTest(ModuleStoreTestCase): + MODULESTORE = mixed_store_config(data_dir, mappings) # ... 3. Use factories (e.g. `CourseFactory`, `ItemFactory`) to populate @@ -219,6 +219,9 @@ class ModuleStoreTestCase(TestCase): `clear_existing_modulestores()` directly in your `setUp()` method. """ + + MODULESTORE = TEST_DATA_MOCK_MODULESTORE + def setUp(self, **kwargs): """ Creates a test User if `create_user` is True. @@ -227,6 +230,18 @@ class ModuleStoreTestCase(TestCase): Args: create_user - specifies whether or not to create a test User. Default is True. """ + settings_override = override_settings(MODULESTORE=self.MODULESTORE) + settings_override.__enter__() + self.addCleanup(settings_override.__exit__, None, None, None) + + # Clear out any existing modulestores, + # which will cause them to be re-created + clear_existing_modulestores() + + self.addCleanup(self.drop_mongo_collections) + + self.addCleanup(RequestCache().clear_request_cache) + super(ModuleStoreTestCase, self).setUp() self.store = modulestore() @@ -293,43 +308,6 @@ class ModuleStoreTestCase(TestCase): if hasattr(module_store, 'close_connections'): module_store.close_connections() - @classmethod - def setUpClass(cls): - """ - Delete the existing modulestores, causing them to be reloaded. - """ - # Clear out any existing modulestores, - # which will cause them to be re-created - # the next time they are accessed. - clear_existing_modulestores() - TestCase.setUpClass() - - def _pre_setup(self): - """ - Flush the ModuleStore. - """ - # Flush the Mongo modulestore - self.drop_mongo_collections() - - # Call superclass implementation - super(ModuleStoreTestCase, self)._pre_setup() - - def _post_teardown(self): - """ - Flush the ModuleStore after each test. - """ - self.drop_mongo_collections() - # Clear out the existing modulestores, - # which will cause them to be re-created - # the next time they are accessed. - # We do this at *both* setup and teardown just to be safe. - clear_existing_modulestores() - # clear RequestCache to emulate its clearance after each http request. - RequestCache().clear_request_cache() - - # Call superclass implementation - super(ModuleStoreTestCase, self)._post_teardown() - def create_sample_course(self, org, course, run, block_info_tree=None, course_fields=None): """ create a course in the default modulestore from the collection of BlockInfo diff --git a/lms/djangoapps/branding/tests/test_page.py b/lms/djangoapps/branding/tests/test_page.py index e8ca879150..cfe5238b03 100644 --- a/lms/djangoapps/branding/tests/test_page.py +++ b/lms/djangoapps/branding/tests/test_page.py @@ -41,7 +41,6 @@ def mock_render_to_response(*args, **kwargs): RENDER_MOCK = Mock(side_effect=mock_render_to_response) -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class AnonymousIndexPageTest(ModuleStoreTestCase): """ Tests that anonymous users can access the '/' page, Need courses with start date @@ -115,7 +114,6 @@ class AnonymousIndexPageTest(ModuleStoreTestCase): self.assertEqual(response._headers.get("location")[1], "/login") # pylint: disable=protected-access -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test to simulate and verify fix for disappearing courses in @@ -163,7 +161,6 @@ class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase): self.assertIn('course that has pre requisite', resp.content) -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class IndexPageCourseCardsSortingTests(ModuleStoreTestCase): """ Test for Index page course cards sorting diff --git a/lms/djangoapps/bulk_email/tests/test_course_optout.py b/lms/djangoapps/bulk_email/tests/test_course_optout.py index 29f5f7362c..3f0fc7ea16 100644 --- a/lms/djangoapps/bulk_email/tests/test_course_optout.py +++ b/lms/djangoapps/bulk_email/tests/test_course_optout.py @@ -19,7 +19,6 @@ from xmodule.modulestore.tests.factories import CourseFactory @patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message')) -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestOptoutCourseEmails(ModuleStoreTestCase): """ diff --git a/lms/djangoapps/bulk_email/tests/test_email.py b/lms/djangoapps/bulk_email/tests/test_email.py index 04b2ad508d..5dba89ff1e 100644 --- a/lms/djangoapps/bulk_email/tests/test_email.py +++ b/lms/djangoapps/bulk_email/tests/test_email.py @@ -92,7 +92,6 @@ class EmailSendFromDashboardTestCase(ModuleStoreTestCase): patch.stopall() -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) @patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message')) class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase): @@ -300,7 +299,6 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) self.assertItemsEqual(outbox_contents, should_send_contents) -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) @skipIf(os.environ.get("TRAVIS") == 'true', "Skip this test in Travis CI.") class TestEmailSendFromDashboard(EmailSendFromDashboardTestCase): diff --git a/lms/djangoapps/bulk_email/tests/test_err_handling.py b/lms/djangoapps/bulk_email/tests/test_err_handling.py index 263f6cb915..ddc728f52c 100644 --- a/lms/djangoapps/bulk_email/tests/test_err_handling.py +++ b/lms/djangoapps/bulk_email/tests/test_err_handling.py @@ -38,7 +38,6 @@ class EmailTestException(Exception): @patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message')) -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) class TestEmailErrors(ModuleStoreTestCase): """ diff --git a/lms/djangoapps/bulk_email/tests/test_forms.py b/lms/djangoapps/bulk_email/tests/test_forms.py index 0c4ef31f8c..2328dd271e 100644 --- a/lms/djangoapps/bulk_email/tests/test_forms.py +++ b/lms/djangoapps/bulk_email/tests/test_forms.py @@ -18,7 +18,6 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore import ModuleStoreEnum -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CourseAuthorizationFormTest(ModuleStoreTestCase): """Test the CourseAuthorizationAdminForm form for Mongo-backed courses.""" @@ -123,9 +122,9 @@ class CourseAuthorizationFormTest(ModuleStoreTestCase): form.save() -@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE) class CourseAuthorizationXMLFormTest(ModuleStoreTestCase): """Check that XML courses cannot be authorized for email.""" + MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': True}) def test_xml_course_authorization(self): @@ -146,7 +145,6 @@ class CourseAuthorizationXMLFormTest(ModuleStoreTestCase): form.save() -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CourseEmailTemplateFormTest(ModuleStoreTestCase): """Test the CourseEmailTemplateForm that is used in the Django admin subsystem.""" diff --git a/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py b/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py index a4d2ffbbd7..a123236681 100644 --- a/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py +++ b/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py @@ -27,7 +27,6 @@ from class_dashboard.views import has_instructor_access_for_class USER_COUNT = 11 -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestGetProblemGradeDistribution(ModuleStoreTestCase): """ Tests related to class_dashboard/dashboard_data.py diff --git a/lms/djangoapps/class_dashboard/tests/test_views.py b/lms/djangoapps/class_dashboard/tests/test_views.py index b082e80cf2..765eb4e92e 100644 --- a/lms/djangoapps/class_dashboard/tests/test_views.py +++ b/lms/djangoapps/class_dashboard/tests/test_views.py @@ -14,7 +14,6 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from class_dashboard import views -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestViews(ModuleStoreTestCase): """ Tests related to class_dashboard/views.py diff --git a/lms/djangoapps/course_wiki/tests/test_access.py b/lms/djangoapps/course_wiki/tests/test_access.py index 25b5007cec..54f47b2355 100644 --- a/lms/djangoapps/course_wiki/tests/test_access.py +++ b/lms/djangoapps/course_wiki/tests/test_access.py @@ -17,7 +17,6 @@ from course_wiki.utils import user_is_article_course_staff, course_wiki_slug from course_wiki import settings -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestWikiAccessBase(ModuleStoreTestCase): """Base class for testing wiki access.""" def setUp(self): diff --git a/lms/djangoapps/course_wiki/tests/test_middleware.py b/lms/djangoapps/course_wiki/tests/test_middleware.py index af4ed3264f..3035709e12 100644 --- a/lms/djangoapps/course_wiki/tests/test_middleware.py +++ b/lms/djangoapps/course_wiki/tests/test_middleware.py @@ -14,7 +14,6 @@ from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from course_wiki.views import get_or_create_root -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class TestWikiAccessMiddleware(ModuleStoreTestCase): """Tests for WikiAccessMiddleware.""" diff --git a/lms/djangoapps/course_wiki/tests/tests.py b/lms/djangoapps/course_wiki/tests/tests.py index fc19afba65..fbecd44b54 100644 --- a/lms/djangoapps/course_wiki/tests/tests.py +++ b/lms/djangoapps/course_wiki/tests/tests.py @@ -2,14 +2,13 @@ from django.core.urlresolvers import reverse from django.test.utils import override_settings from courseware.tests.tests import LoginEnrollmentTestCase -from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from mock import patch -@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) -class WikiRedirectTestCase(LoginEnrollmentTestCase): +class WikiRedirectTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): """ Tests for wiki course redirection. """ diff --git a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py index 8b8f4f9758..587b5bff15 100644 --- a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py +++ b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py @@ -200,17 +200,17 @@ class CommandsTestBase(TestCase): assert_in('edX-simple-2012_Fall/sequential/Lecture_2.xml', names) -@override_settings(MODULESTORE=TEST_DATA_MIXED_XML_MODULESTORE) class CommandsXMLTestCase(CommandsTestBase, ModuleStoreTestCase): """ Test case for management commands using the xml modulestore. """ + MODULESTORE = TEST_DATA_MIXED_XML_MODULESTORE -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) class CommandsMongoTestCase(CommandsTestBase, ModuleStoreTestCase): """ Test case for management commands using the mixed mongo modulestore. """ + MODULESTORE = TEST_DATA_MONGO_MODULESTORE diff --git a/lms/djangoapps/courseware/tests/__init__.py b/lms/djangoapps/courseware/tests/__init__.py index b38f408e2f..1071b26044 100644 --- a/lms/djangoapps/courseware/tests/__init__.py +++ b/lms/djangoapps/courseware/tests/__init__.py @@ -24,7 +24,6 @@ from lms.djangoapps.lms_xblock.field_data import LmsFieldData from lms.djangoapps.lms_xblock.runtime import quote_slashes -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) class BaseTestXmodule(ModuleStoreTestCase): """Base class for testing Xmodules with mongo store. @@ -41,6 +40,8 @@ class BaseTestXmodule(ModuleStoreTestCase): This class should not contain any tests, because CATEGORY should be defined in child class. """ + MODULESTORE = TEST_DATA_MONGO_MODULESTORE + USER_COUNT = 2 COURSE_DATA = {} diff --git a/lms/djangoapps/courseware/tests/test_about.py b/lms/djangoapps/courseware/tests/test_about.py index 937bfa050f..2f9f62ec9a 100644 --- a/lms/djangoapps/courseware/tests/test_about.py +++ b/lms/djangoapps/courseware/tests/test_about.py @@ -33,7 +33,6 @@ REG_STR = "