diff --git a/cms/djangoapps/contentstore/tests/utils.py b/cms/djangoapps/contentstore/tests/utils.py index 439eccad98..a147ad30f6 100644 --- a/cms/djangoapps/contentstore/tests/utils.py +++ b/cms/djangoapps/contentstore/tests/utils.py @@ -2,23 +2,24 @@ ''' Utilities for contentstore tests ''' - import json -from django.test.client import Client +from django.conf import settings from django.contrib.auth.models import User +from django.test.client import Client +from django.test.utils import override_settings +from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation +from contentstore.utils import reverse_url +from student.models import Registration +from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore from xmodule.contentstore.django import contentstore from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.xml_importer import import_from_xml -from student.models import Registration -from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation -from contentstore.utils import reverse_url -from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore -from django.conf import settings TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT @@ -66,7 +67,12 @@ 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. + Also provides helper methods for manipulating and verifying the course. + """ def setUp(self): """ These tests need a user in the DB so that the django Test Client can log them in. diff --git a/common/djangoapps/course_groups/tests/test_cohorts.py b/common/djangoapps/course_groups/tests/test_cohorts.py index 7e87ee4ba9..b4a16af27c 100644 --- a/common/djangoapps/course_groups/tests/test_cohorts.py +++ b/common/djangoapps/course_groups/tests/test_cohorts.py @@ -1,33 +1,25 @@ -import django.test -from django.contrib.auth.models import User from django.conf import settings +from django.contrib.auth.models import User from django.http import Http404 - +from django.test import TestCase from django.test.utils import override_settings from mock import call, patch - -from student.models import CourseEnrollment -from student.tests.factories import UserFactory -from course_groups.models import CourseUserGroup -from course_groups import cohorts -from course_groups.tests.helpers import topic_name_to_id, config_course_cohorts, CohortFactory - -from xmodule.modulestore.django import modulestore, clear_existing_modulestores from opaque_keys.edx.locations import SlashSeparatedCourseKey -from xmodule.modulestore.tests.django_utils import mixed_store_config +from course_groups import cohorts +from course_groups.models import CourseUserGroup +from course_groups.tests.helpers import topic_name_to_id, config_course_cohorts, CohortFactory +from student.models import CourseEnrollment +from student.tests.factories import UserFactory +from xmodule.modulestore.django import modulestore, clear_existing_modulestores +from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE + # NOTE: running this with the lms.envs.test config works without # manually overriding the modulestore. However, running with # cms.envs.test doesn't. - -TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT -TEST_MAPPING = {'edX/toy/2012_Fall': 'xml'} -TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, TEST_MAPPING) - - @patch("course_groups.cohorts.tracker") -class TestCohortSignals(django.test.TestCase): +class TestCohortSignals(TestCase): def setUp(self): self.course_key = SlashSeparatedCourseKey("dummy", "dummy", "dummy") @@ -123,9 +115,11 @@ class TestCohortSignals(django.test.TestCase): self.assertFalse(mock_tracker.emit.called) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) -class TestCohorts(django.test.TestCase): - +@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE) +class TestCohorts(TestCase): + """ + Test the cohorts feature + """ def setUp(self): """ Make sure that course is reloaded every time--clear out the modulestore. diff --git a/common/djangoapps/course_groups/tests/test_views.py b/common/djangoapps/course_groups/tests/test_views.py index 78fe1b623b..580b469c88 100644 --- a/common/djangoapps/course_groups/tests/test_views.py +++ b/common/djangoapps/course_groups/tests/test_views.py @@ -1,25 +1,31 @@ +""" +Tests for course group views +""" +from collections import namedtuple import json +from django.contrib.auth.models import User +from django.http import Http404 from django.test.client import RequestFactory from django.test.utils import override_settings -from course_groups.tests.helpers import config_course_cohorts, CohortFactory -from collections import namedtuple +from opaque_keys.edx.locations import SlashSeparatedCourseKey -from django.http import Http404 -from django.contrib.auth.models import User -from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE +from course_groups.cohorts import ( + get_cohort, CohortAssignmentType, get_cohort_by_name, DEFAULT_COHORT_NAME +) +from course_groups.models import CourseUserGroup +from course_groups.tests.helpers import config_course_cohorts, CohortFactory +from course_groups.views import ( + list_cohorts, add_cohort, users_in_cohort, add_users_to_cohort, remove_user_from_cohort +) +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from student.models import CourseEnrollment from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from opaque_keys.edx.locations import SlashSeparatedCourseKey - -from course_groups.models import CourseUserGroup -from course_groups.views import list_cohorts, add_cohort, users_in_cohort, add_users_to_cohort, remove_user_from_cohort -from course_groups.cohorts import get_cohort, CohortAssignmentType, get_cohort_by_name, DEFAULT_COHORT_NAME -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CohortViewsTestCase(ModuleStoreTestCase): """ Base class which sets up a course and staff/non-staff users. diff --git a/common/djangoapps/embargo/tests/test_forms.py b/common/djangoapps/embargo/tests/test_forms.py index b8aa08f353..a909a7a6e7 100644 --- a/common/djangoapps/embargo/tests/test_forms.py +++ b/common/djangoapps/embargo/tests/test_forms.py @@ -13,10 +13,10 @@ from embargo.models import EmbargoedCourse, EmbargoedState, IPFilter from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class EmbargoCourseFormTest(ModuleStoreTestCase): """Test the course form properly validates course IDs""" diff --git a/common/djangoapps/external_auth/tests/test_shib.py b/common/djangoapps/external_auth/tests/test_shib.py index ac2f49c3d2..c5f86b9b9f 100644 --- a/common/djangoapps/external_auth/tests/test_shib.py +++ b/common/djangoapps/external_auth/tests/test_shib.py @@ -4,9 +4,8 @@ Tests for Shibboleth Authentication @jbau """ import unittest -from mock import patch -from ddt import ddt, data +from ddt import ddt, data from django.conf import settings from django.http import HttpResponseRedirect from django.test import TestCase @@ -15,22 +14,21 @@ from django.test.utils import override_settings from django.core.urlresolvers import reverse from django.contrib.auth.models import AnonymousUser, User from django.utils.importlib import import_module - -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config -from xmodule.modulestore.django import modulestore -from xmodule.modulestore import ModuleStoreEnum -from opaque_keys.edx.locations import SlashSeparatedCourseKey - -from external_auth.models import ExternalAuthMap -from external_auth.views import shib_login, course_specific_login, course_specific_register, _flatten_to_ascii - -from student.views import create_account, change_enrollment -from student.models import UserProfile, Registration, CourseEnrollment -from student.tests.factories import UserFactory from edxmako.tests import mako_middleware_process_request +from external_auth.models import ExternalAuthMap +from external_auth.views import ( + shib_login, course_specific_login, course_specific_register, _flatten_to_ascii +) +from mock import patch + +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE +from student.views import create_account, change_enrollment +from student.models import UserProfile, CourseEnrollment +from student.tests.factories import UserFactory +from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore import ModuleStoreEnum -TEST_DATA_MIXED_MODULESTORE = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}) # Shib is supposed to provide 'REMOTE_USER', 'givenName', 'sn', 'mail', 'Shib-Identity-Provider' # attributes via request.META. We can count on 'Shib-Identity-Provider', and 'REMOTE_USER' being present @@ -75,7 +73,7 @@ def gen_all_identities(): @ddt -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE, SESSION_ENGINE='django.contrib.sessions.backends.cache') +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE, 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/external_auth/tests/test_ssl.py b/common/djangoapps/external_auth/tests/test_ssl.py index a81168d98e..1bcecdded0 100644 --- a/common/djangoapps/external_auth/tests/test_ssl.py +++ b/common/djangoapps/external_auth/tests/test_ssl.py @@ -2,7 +2,6 @@ Provides unit tests for SSL based authentication portions of the external_auth app. """ - import unittest from django.conf import settings @@ -13,17 +12,16 @@ from django.core.urlresolvers import reverse from django.test.client import Client from django.test.client import RequestFactory from django.test.utils import override_settings -from mock import Mock - -import external_auth.views from edxmako.middleware import MakoMiddleware from external_auth.models import ExternalAuthMap -from opaque_keys import InvalidKeyError +import external_auth.views +from mock import Mock + +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from student.models import CourseEnrollment from student.roles import CourseStaffRole from student.tests.factories import UserFactory -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 FEATURES_WITH_SSL_AUTH = settings.FEATURES.copy() @@ -35,8 +33,6 @@ FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE['BYPASS_ACTIVATION_EMAIL_FOR_EXTAUTH'] = Tr FEATURES_WITHOUT_SSL_AUTH = settings.FEATURES.copy() FEATURES_WITHOUT_SSL_AUTH['AUTH_USE_CERTIFICATES'] = False -TEST_DATA_MIXED_MODULESTORE = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}) - @override_settings(FEATURES=FEATURES_WITH_SSL_AUTH) class SSLClientTest(ModuleStoreTestCase): @@ -325,7 +321,7 @@ class SSLClientTest(ModuleStoreTestCase): @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE, - MODULESTORE=TEST_DATA_MIXED_MODULESTORE) + MODULESTORE=TEST_DATA_MOCK_MODULESTORE) def test_ssl_lms_redirection(self): """ Auto signup auth user and ensure they return to the original diff --git a/common/djangoapps/geoinfo/tests/test_middleware.py b/common/djangoapps/geoinfo/tests/test_middleware.py index 3e6b7159ac..860f21f08c 100644 --- a/common/djangoapps/geoinfo/tests/test_middleware.py +++ b/common/djangoapps/geoinfo/tests/test_middleware.py @@ -1,22 +1,20 @@ """ Tests for CountryMiddleware. """ - -from mock import Mock, patch +from mock import patch import pygeoip +from django.contrib.sessions.middleware import SessionMiddleware from django.test import TestCase from django.test.utils import override_settings from django.test.client import RequestFactory -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE -from student.models import CourseEnrollment -from student.tests.factories import UserFactory, AnonymousUserFactory - -from django.contrib.sessions.middleware import SessionMiddleware from geoinfo.middleware import CountryMiddleware +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE +from student.tests.factories import UserFactory, AnonymousUserFactory -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) + +@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 ca548f4ffb..8ffddc8a17 100644 --- a/common/djangoapps/reverification/tests/test_models.py +++ b/common/djangoapps/reverification/tests/test_models.py @@ -7,14 +7,14 @@ import pytz from django.core.exceptions import ValidationError from django.test.utils import override_settings -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from reverification.models import MidcourseReverificationWindow from reverification.tests.factories import MidcourseReverificationWindowFactory from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@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 a0e5a1b401..4410320aae 100644 --- a/common/djangoapps/student/tests/test_bulk_email_settings.py +++ b/common/djangoapps/student/tests/test_bulk_email_settings.py @@ -4,25 +4,27 @@ that bulk email is always disabled for non-Mongo backed courses, regardless of email feature flag, and that the view is conditionally available when Course Auth is turned on. """ - -from django.test.utils import override_settings -from django.conf import settings -from django.core.urlresolvers import reverse import unittest -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE -from student.tests.factories import UserFactory, CourseEnrollmentFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE +from django.conf import settings +from django.core.urlresolvers import reverse +from django.test.utils import override_settings +from mock import patch from opaque_keys.edx.locations import SlashSeparatedCourseKey -from bulk_email.models import CourseAuthorization +from student.tests.factories import UserFactory, CourseEnrollmentFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE +) +from xmodule.modulestore.tests.factories import CourseFactory -from mock import patch +# This import is for an lms djangoapp. +# Its testcases are only run under lms. +from bulk_email.models import CourseAuthorization # pylint: disable=import-error -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class TestStudentDashboardEmailView(ModuleStoreTestCase): """ @@ -88,7 +90,7 @@ class TestStudentDashboardEmailView(ModuleStoreTestCase): self.assertTrue(self.email_modal_link in response.content) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase): """ diff --git a/common/djangoapps/student/tests/test_login.py b/common/djangoapps/student/tests/test_login.py index 5b51587362..828e951cbb 100644 --- a/common/djangoapps/student/tests/test_login.py +++ b/common/djangoapps/student/tests/test_login.py @@ -3,7 +3,6 @@ Tests for student activation and login ''' import json import unittest -from mock import patch from django.test import TestCase from django.test.client import Client @@ -12,23 +11,21 @@ from django.conf import settings from django.core.cache import cache from django.core.urlresolvers import reverse, NoReverseMatch from django.http import HttpResponseBadRequest, HttpResponse +from external_auth.models import ExternalAuthMap import httpretty +from mock import patch +from opaque_keys.edx.locations import SlashSeparatedCourseKey from social.apps.django_app.default.models import UserSocialAuth + +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from student.tests.factories import UserFactory, RegistrationFactory, UserProfileFactory from student.views import ( _parse_course_id_from_string, _get_course_enrollment_domain, login_oauth_token, ) - from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config -from xmodule.modulestore.django import modulestore - -from external_auth.models import ExternalAuthMap -from opaque_keys.edx.locations import SlashSeparatedCourseKey - -TEST_DATA_MIXED_MODULESTORE = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}) +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase class LoginTest(TestCase): @@ -345,7 +342,7 @@ class UtilFnTest(TestCase): self.assertIsNone(_parse_course_id_from_string(NON_COURSE_URL)) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class ExternalAuthShibTest(ModuleStoreTestCase): """ Tests how login_user() interacts with ExternalAuth, in particular Shib diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index 4c4177d18b..898d2cc0b9 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -5,35 +5,38 @@ when you run "manage.py test". Replace this with more appropriate tests for your application. """ -import logging -import unittest from datetime import datetime, timedelta +import logging import pytz +import unittest from django.conf import settings -from django.test import TestCase -from django.test.utils import override_settings -from django.test.client import RequestFactory, Client from django.contrib.auth.models import User, AnonymousUser -from django.core.urlresolvers import reverse from django.contrib.sessions.middleware import SessionMiddleware - -from xmodule.modulestore.tests.factories import CourseFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE +from django.core.urlresolvers import reverse +from django.test import TestCase +from django.test.client import RequestFactory, Client +from django.test.utils import override_settings +from mock import Mock, patch from opaque_keys.edx.locations import SlashSeparatedCourseKey -from mock import Mock, patch - -from student.models import anonymous_id_for_user, user_by_anonymous_id, CourseEnrollment, unique_id_for_user +from student.models import ( + anonymous_id_for_user, user_by_anonymous_id, CourseEnrollment, unique_id_for_user +) from student.views import (process_survey_link, _cert_info, change_enrollment, complete_course_mode_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. +from bulk_email.models import Optout # pylint: disable=import-error +from certificates.models import CertificateStatuses # pylint: disable=import-error +from certificates.tests.factories import GeneratedCertificateFactory # pylint: disable=import-error +import shoppingcart # pylint: disable=import-error -from certificates.models import CertificateStatuses -from certificates.tests.factories import GeneratedCertificateFactory -import shoppingcart -from bulk_email.models import Optout log = logging.getLogger(__name__) @@ -176,7 +179,7 @@ class CourseEndingTest(TestCase): self.assertIsNone(_cert_info(user, course2, cert_status)) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class DashboardTest(ModuleStoreTestCase): """ Tests for dashboard utility functions @@ -580,7 +583,7 @@ class EnrollInCourseTest(TestCase): self.assert_enrollment_mode_change_event_was_emitted(user, course_id, "honor") -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@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""" @@ -663,7 +666,7 @@ class ChangeEnrollmentViewTest(ModuleStoreTestCase): self.assertEqual(enrollment_mode, u'honor') -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class PaidRegistrationTest(ModuleStoreTestCase): """ Tests for paid registration functionality (not verified student), involves shoppingcart @@ -696,7 +699,7 @@ class PaidRegistrationTest(ModuleStoreTestCase): shoppingcart.models.Order.get_cart_for_user(self.user), self.course.id)) -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class AnonymousLookupTable(ModuleStoreTestCase): """ Tests for anonymous_id_functions diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index bac06d756e..422c43220e 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -2,21 +2,25 @@ """ Modulestore configuration for test cases. """ -from uuid import uuid4 -from django.test import TestCase -from django.contrib.auth.models import User -from xmodule.contentstore.django import _CONTENTSTORE -from xmodule.modulestore.django import modulestore, clear_existing_modulestores -from xmodule.modulestore import ModuleStoreEnum import datetime import pytz +from tempfile import mkdtemp +from uuid import uuid4 + +from django.conf import settings +from django.contrib.auth.models import User +from django.test import TestCase from request_cache.middleware import RequestCache -from xmodule.tabs import CoursewareTab, CourseInfoTab, StaticTab, DiscussionTab, ProgressTab, WikiTab -from xmodule.modulestore.tests.sample_courses import default_block_info_tree, TOY_BLOCK_INFO_TREE + +from xmodule.contentstore.django import _CONTENTSTORE +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.django import modulestore, clear_existing_modulestores from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST +from xmodule.modulestore.tests.sample_courses import default_block_info_tree, TOY_BLOCK_INFO_TREE +from xmodule.tabs import CoursewareTab, CourseInfoTab, StaticTab, DiscussionTab, ProgressTab, WikiTab -def mixed_store_config(data_dir, mappings, include_xml=True): +def mixed_store_config(data_dir, mappings, include_xml=False, xml_course_dirs=None): """ Return a `MixedModuleStore` configuration, which provides access to both Mongo- and XML-backed courses. @@ -36,9 +40,12 @@ def mixed_store_config(data_dir, mappings, include_xml=True): Keyword Args: include_xml (boolean): If True, include an XML modulestore in the configuration. - Note that this will require importing multiple XML courses from disk, - so unless your tests really needs XML course fixtures or is explicitly - testing mixed modulestore, set this to False. + xml_course_dirs (list): The directories containing XML courses to load from disk. + + note: For the courses to be loaded into the XML modulestore and accessible do the following: + include_xml should be True + xml_course_dirs should be the list of courses you want to load + mappings should be configured, pointing the xml courses to the xml modulestore """ stores = [ @@ -47,7 +54,7 @@ def mixed_store_config(data_dir, mappings, include_xml=True): ] if include_xml: - stores.append(xml_store_config(data_dir)['default']) + stores.append(xml_store_config(data_dir, course_dirs=xml_course_dirs)['default']) store = { 'default': { @@ -80,7 +87,7 @@ def draft_mongo_store_config(data_dir): 'host': MONGO_HOST, 'port': MONGO_PORT_NUM, 'db': 'test_xmodule', - 'collection': 'modulestore{0}'.format(uuid4().hex[:5]), + 'collection': 'modulestore_{0}'.format(uuid4().hex[:5]), }, 'OPTIONS': modulestore_options } @@ -107,7 +114,7 @@ def split_mongo_store_config(data_dir): 'host': MONGO_HOST, 'port': MONGO_PORT_NUM, 'db': 'test_xmodule', - 'collection': 'modulestore{0}'.format(uuid4().hex[:5]), + 'collection': 'modulestore_{0}'.format(uuid4().hex[:5]), }, 'OPTIONS': modulestore_options } @@ -119,6 +126,9 @@ def split_mongo_store_config(data_dir): def xml_store_config(data_dir, course_dirs=None): """ Defines default module store using XMLModuleStore. + + Note: you should pass in a list of course_dirs that you care about, + otherwise all courses in the data_dir will be processed. """ store = { 'default': { @@ -134,6 +144,39 @@ def xml_store_config(data_dir, course_dirs=None): return store +TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT + +# This is an XML only modulestore with only the toy course loaded +TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR, course_dirs=['toy']) + +# This modulestore will provide both a mixed mongo editable modulestore, and +# an XML store with just the toy course loaded. +TEST_DATA_MIXED_TOY_MODULESTORE = mixed_store_config( + TEST_DATA_DIR, {'edX/toy/2012_Fall': 'xml', }, include_xml=True, xml_course_dirs=['toy'] +) + +# This modulestore will provide both a mixed mongo editable modulestore, and +# an XML store with common/test/data/2014 loaded, which is a course that is closed. +TEST_DATA_MIXED_CLOSED_MODULESTORE = mixed_store_config( + TEST_DATA_DIR, {'edX/detached_pages/2014': 'xml', }, include_xml=True, xml_course_dirs=['2014'] +) + +# This modulestore will provide both a mixed mongo editable modulestore, and +# an XML store with common/test/data/graded loaded, which is a course that is graded. +TEST_DATA_MIXED_GRADED_MODULESTORE = mixed_store_config( + TEST_DATA_DIR, {'edX/graded/2012_Fall': 'xml', }, include_xml=True, xml_course_dirs=['graded'] +) + +# All store requests now go through mixed +# Use this modulestore if you specifically want to test mongo and not a mocked modulestore. +# This modulestore definition below will not load any xml courses. +TEST_DATA_MONGO_MODULESTORE = mixed_store_config(mkdtemp(), {}, include_xml=False) + +# Unit tests that are not specifically testing the modulestore implementation but just need course context can use a mocked modulestore. +# Use this modulestore if you do not care about the underlying implementation. +# TODO: acutally mock out the modulestore for this in a subsequent PR. +TEST_DATA_MOCK_MODULESTORE = mixed_store_config(mkdtemp(), {}, include_xml=False) + class ModuleStoreTestCase(TestCase): """ diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_assetstore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_assetstore.py index 52feb63ed7..4d10ac87f3 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_assetstore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_assetstore.py @@ -3,17 +3,17 @@ Tests for assetstore using any of the modulestores for metadata. May extend to t too. """ from datetime import datetime, timedelta +import ddt +from nose.plugins.attrib import attr import pytz import unittest -import ddt from xmodule.assetstore import AssetMetadata from xmodule.modulestore import ModuleStoreEnum - from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.test_cross_modulestore_import_export import ( MIXED_MODULESTORE_BOTH_SETUP, MODULESTORE_SETUPS, MongoContentstoreBuilder, - XmlModulestoreBuilder, MixedModulestoreBuilder, MongoModulestoreBuilder + XmlModulestoreBuilder, MixedModulestoreBuilder ) @@ -43,6 +43,7 @@ class AssetStoreTestData(object): ) +@attr('mongo') @ddt.ddt class TestMongoAssetMetadataStorage(unittest.TestCase): """ diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py b/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py index 7fdae012b1..c8f5b5f0ea 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py @@ -11,16 +11,17 @@ and then for each combination of modulestores, performing the sequence: 4) Compare all modules in the source and destination modulestores to make sure that they line up """ -import ddt -import itertools -import random from contextlib import contextmanager, nested +import itertools +from path import path +import random from shutil import rmtree from tempfile import mkdtemp -from path import path + +import ddt +from nose.plugins.attrib import attr from xmodule.tests import CourseComparisonTest - from xmodule.modulestore.mongo.base import ModuleStoreEnum from xmodule.modulestore.mongo.draft import DraftModuleStore from xmodule.modulestore.mixed import MixedModuleStore @@ -289,6 +290,7 @@ COURSE_DATA_NAMES = ( @ddt.ddt +@attr('mongo') class CrossStoreXMLRoundtrip(CourseComparisonTest): """ This class exists to test XML import and export between different modulestore diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py index 87e1dc34d7..19e8664955 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -2,25 +2,26 @@ """ Unit tests for the Mixed Modulestore, with DDT for the various stores (Split, Draft, XML) """ +from collections import namedtuple import datetime import ddt -import itertools -import pymongo - -from collections import namedtuple from importlib import import_module -from pytz import UTC +import itertools +import mimetypes from uuid import uuid4 # Mixed modulestore depends on django, so we'll manually configure some django settings # before importing the module # TODO remove this import and the configuration -- xmodule should not depend on django! from django.conf import settings +from nose.plugins.attrib import attr +import pymongo +from pytz import UTC + from xmodule.modulestore.edit_info import EditInfoMixin from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.modulestore.tests.test_cross_modulestore_import_export import MongoContentstoreBuilder from xmodule.contentstore.content import StaticContent -import mimetypes from opaque_keys.edx.keys import CourseKey from xmodule.modulestore.xml_importer import import_from_xml from nose import SkipTest @@ -43,6 +44,7 @@ from xmodule.tests import DATA_DIR, CourseComparisonTest @ddt.ddt +@attr('mongo') class TestMixedModuleStore(CourseComparisonTest): """ Quasi-superclass which tests Location based apps against both split and mongo dbs (Locator and diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_publish.py b/common/lib/xmodule/xmodule/modulestore/tests/test_publish.py index ff0ddc2e04..b067a8bc5c 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_publish.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_publish.py @@ -1,12 +1,15 @@ """ Test the publish code (mostly testing that publishing doesn't result in orphans) """ +from nose.plugins.attrib import attr + +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.tests.test_split_w_old_mongo import SplitWMongoCourseBoostrapper from xmodule.modulestore.tests.factories import check_mongo_calls, mongo_uses_error_check -from xmodule.modulestore import ModuleStoreEnum +@attr('mongo') class TestPublish(SplitWMongoCourseBoostrapper): """ Test the publish code (primary causing orphans) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py b/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py index 835375ae7e..442a98d857 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py @@ -2,14 +2,18 @@ Tests for split_migrator """ -import uuid import random +import uuid + import mock +from nose.plugins.attrib import attr + from xblock.fields import Reference, ReferenceList, ReferenceValueDict from xmodule.modulestore.split_migrator import SplitMigrator from xmodule.modulestore.tests.test_split_w_old_mongo import SplitWMongoCourseBoostrapper +@attr('mongo') class TestMigration(SplitWMongoCourseBoostrapper): """ Test the split migrator diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py index f41ec6acad..4b399de147 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py @@ -2,13 +2,15 @@ Test split modulestore w/o using any django stuff. """ import datetime +from importlib import import_module +from path import path import random import re import unittest import uuid + from contracts import contract -from importlib import import_module -from path import path +from nose.plugins.attrib import attr from xblock.fields import Reference, ReferenceList, ReferenceValueDict from xmodule.course_module import CourseDescriptor @@ -33,6 +35,7 @@ BRANCH_NAME_DRAFT = ModuleStoreEnum.BranchName.draft BRANCH_NAME_PUBLISHED = ModuleStoreEnum.BranchName.published +@attr('mongo') class SplitModuleTest(unittest.TestCase): ''' The base set of tests manually populates a db w/ courses which have diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_split_w_old_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_split_w_old_mongo.py index bab04573e4..939d2d09b8 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_w_old_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_w_old_mongo.py @@ -1,18 +1,21 @@ -import unittest -import mock import datetime -import uuid import random +import unittest +import uuid + +from nose.plugins.attrib import attr +import mock -from xmodule.modulestore.inheritance import InheritanceMixin from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator -from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore -from xmodule.modulestore.mongo import DraftMongoModuleStore from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.inheritance import InheritanceMixin +from xmodule.modulestore.mongo import DraftMongoModuleStore +from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST from xmodule.modulestore.tests.test_cross_modulestore_import_export import MemoryCache +@attr('mongo') class SplitWMongoCourseBoostrapper(unittest.TestCase): """ Helper for tests which need to construct split mongo & old mongo based courses to get interesting internal structure. diff --git a/lms/djangoapps/branding/tests.py b/lms/djangoapps/branding/tests.py index a18c2afad3..520b00a4b5 100644 --- a/lms/djangoapps/branding/tests.py +++ b/lms/djangoapps/branding/tests.py @@ -2,20 +2,19 @@ Tests for branding page """ import datetime -from django.http import HttpResponseRedirect -from pytz import UTC from django.conf import settings from django.contrib.auth.models import AnonymousUser +from django.http import HttpResponseRedirect from django.test.utils import override_settings from django.test.client import RequestFactory +from pytz import UTC -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.factories import CourseFactory -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE -import student.views from branding.views import index +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from edxmako.tests import mako_middleware_process_request +import student.views +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory FEATURES_WITH_STARTDATE = settings.FEATURES.copy() FEATURES_WITH_STARTDATE['DISABLE_START_DATES'] = False @@ -23,7 +22,7 @@ FEATURES_WO_STARTDATE = settings.FEATURES.copy() FEATURES_WO_STARTDATE['DISABLE_START_DATES'] = True -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class AnonymousIndexPageTest(ModuleStoreTestCase): """ Tests that anonymous users can access the '/' page, Need courses with start date diff --git a/lms/djangoapps/bulk_email/tests/test_course_optout.py b/lms/djangoapps/bulk_email/tests/test_course_optout.py index ed3a73855a..88926561e0 100644 --- a/lms/djangoapps/bulk_email/tests/test_course_optout.py +++ b/lms/djangoapps/bulk_email/tests/test_course_optout.py @@ -3,6 +3,7 @@ Unit tests for student optouts from course email """ import json +from mock import patch from django.core import mail from django.core.management import call_command @@ -10,16 +11,14 @@ from django.core.urlresolvers import reverse from django.conf import settings from django.test.utils import override_settings -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory from student.models import CourseEnrollment from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from mock import patch - -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@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 0231449ceb..dad65d6e66 100644 --- a/lms/djangoapps/bulk_email/tests/test_email.py +++ b/lms/djangoapps/bulk_email/tests/test_email.py @@ -3,7 +3,6 @@ Unit tests for sending course email """ import json - from mock import patch from django.conf import settings @@ -12,16 +11,15 @@ from django.core.urlresolvers import reverse from django.core.management import call_command from django.test.utils import override_settings -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE -from student.tests.factories import CourseEnrollmentFactory, UserFactory -from courseware.tests.factories import StaffFactory, InstructorFactory - -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory from bulk_email.models import Optout +from courseware.tests.factories import StaffFactory, InstructorFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from instructor_task.subtasks import update_subtask_status from student.roles import CourseStaffRole from student.models import CourseEnrollment +from student.tests.factories import CourseEnrollmentFactory, UserFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory STAFF_COUNT = 3 STUDENT_COUNT = 10 @@ -44,7 +42,7 @@ class MockCourseEmailResult(object): return mock_update_subtask_status -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) class TestEmailSendFromDashboard(ModuleStoreTestCase): """ diff --git a/lms/djangoapps/bulk_email/tests/test_err_handling.py b/lms/djangoapps/bulk_email/tests/test_err_handling.py index 6734fbc9d5..fc889f36aa 100644 --- a/lms/djangoapps/bulk_email/tests/test_err_handling.py +++ b/lms/djangoapps/bulk_email/tests/test_err_handling.py @@ -2,28 +2,21 @@ """ Unit tests for handling email sending errors """ -import json - from itertools import cycle -from mock import patch -from smtplib import SMTPDataError, SMTPServerDisconnected, SMTPConnectError from celery.states import SUCCESS, RETRY - from django.test.utils import override_settings from django.conf import settings from django.core.management import call_command from django.core.urlresolvers import reverse from django.db import DatabaseError - -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory +import json +from mock import patch +from smtplib import SMTPDataError, SMTPServerDisconnected, SMTPConnectError from bulk_email.models import CourseEmail, SEND_TO_ALL from bulk_email.tasks import perform_delegate_email_batches, send_course_email +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from instructor_task.models import InstructorTask from instructor_task.subtasks import ( initialize_subtask_info, @@ -33,6 +26,10 @@ from instructor_task.subtasks import ( DuplicateTaskException, MAX_DATABASE_LOCK_RETRIES, ) +from opaque_keys.edx.locations import SlashSeparatedCourseKey +from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory class EmailTestException(Exception): @@ -40,7 +37,7 @@ class EmailTestException(Exception): pass -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@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 9e311882c8..558758f584 100644 --- a/lms/djangoapps/bulk_email/tests/test_forms.py +++ b/lms/djangoapps/bulk_email/tests/test_forms.py @@ -2,25 +2,23 @@ """ Unit tests for bulk-email-related forms. """ -from django.test.utils import override_settings from django.conf import settings - -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.factories import CourseFactory -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE -from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE - -from xmodule.modulestore.django import modulestore -from xmodule.modulestore import ModuleStoreEnum - +from django.test.utils import override_settings from mock import patch from bulk_email.models import CourseAuthorization, CourseEmailTemplate from bulk_email.forms import CourseAuthorizationAdminForm, CourseEmailTemplateForm +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE +) from opaque_keys.edx.locations import SlashSeparatedCourseKey +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.modulestore.django import modulestore +from xmodule.modulestore import ModuleStoreEnum -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class CourseAuthorizationFormTest(ModuleStoreTestCase): """Test the CourseAuthorizationAdminForm form for Mongo-backed courses.""" @@ -124,7 +122,7 @@ class CourseAuthorizationFormTest(ModuleStoreTestCase): form.save() -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MIXED_TOY_MODULESTORE) class CourseAuthorizationXMLFormTest(ModuleStoreTestCase): """Check that XML courses cannot be authorized for email.""" @@ -147,7 +145,7 @@ class CourseAuthorizationXMLFormTest(ModuleStoreTestCase): form.save() -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@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 e228159742..73a7601397 100644 --- a/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py +++ b/lms/djangoapps/class_dashboard/tests/test_dashboard_data.py @@ -3,17 +3,18 @@ Tests for class dashboard (Metrics tab in instructor dashboard) """ import json -from mock import patch from django.test.utils import override_settings from django.core.urlresolvers import reverse from django.test.client import RequestFactory -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE +from mock import patch + +from capa.tests.response_xml_factory import StringResponseXMLFactory +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from courseware.tests.factories import StudentModuleFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory -from capa.tests.response_xml_factory import StringResponseXMLFactory +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from class_dashboard.dashboard_data import (get_problem_grade_distribution, get_sequential_open_distrib, get_problem_set_grade_distrib, get_d3_problem_grade_distrib, @@ -26,7 +27,7 @@ from class_dashboard.views import has_instructor_access_for_class USER_COUNT = 11 -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@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 f2c49324dd..f4b5f31941 100644 --- a/lms/djangoapps/class_dashboard/tests/test_views.py +++ b/lms/djangoapps/class_dashboard/tests/test_views.py @@ -1,21 +1,20 @@ """ Tests for class dashboard (Metrics tab in instructor dashboard) """ -from mock import patch from django.test.utils import override_settings - -from django.test import TestCase from django.test.client import RequestFactory -from xmodule.modulestore.tests.factories import CourseFactory -from student.tests.factories import AdminFactory from django.utils import simplejson -from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE +from mock import patch + +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE +from student.tests.factories import AdminFactory +from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from class_dashboard import views -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@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 04cbe0e62c..39480c5618 100644 --- a/lms/djangoapps/course_wiki/tests/test_access.py +++ b/lms/djangoapps/course_wiki/tests/test_access.py @@ -9,7 +9,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from django.test.utils import override_settings from courseware.tests.factories import InstructorFactory, StaffFactory -from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from wiki.models import URLPath from course_wiki.views import get_or_create_root @@ -17,7 +17,7 @@ from course_wiki.utils import user_is_article_course_staff, course_wiki_slug from course_wiki import settings -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@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 28e548996e..519d3a8ccb 100644 --- a/lms/djangoapps/course_wiki/tests/test_middleware.py +++ b/lms/djangoapps/course_wiki/tests/test_middleware.py @@ -10,11 +10,11 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from courseware.tests.factories import InstructorFactory -from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE +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_MONGO_MODULESTORE) +@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 30e57774b1..a3428c77a9 100644 --- a/lms/djangoapps/course_wiki/tests/tests.py +++ b/lms/djangoapps/course_wiki/tests/tests.py @@ -2,13 +2,13 @@ from django.core.urlresolvers import reverse from django.test.utils import override_settings from courseware.tests.tests import LoginEnrollmentTestCase -from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE from xmodule.modulestore.tests.factories import CourseFactory from mock import patch -@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MOCK_MODULESTORE) class WikiRedirectTestCase(LoginEnrollmentTestCase): """ 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 433a494c84..55be6cc8cd 100644 --- a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py +++ b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py @@ -3,33 +3,37 @@ """Tests for Django management commands""" import json +from path import path import shutil from StringIO import StringIO import tarfile from tempfile import mkdtemp -from path import path - +from django.conf import settings from django.core.management import call_command from django.test.utils import override_settings from django.test.testcases import TestCase - -from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE -from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE -from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE +from opaque_keys.edx.locations import SlashSeparatedCourseKey from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.xml_importer import import_from_xml -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from django.conf import settings DATA_DIR = settings.COMMON_TEST_DATA_ROOT - TEST_COURSE_ID = 'edX/simple/2012_Fall' +XML_COURSE_DIRS = ['toy', 'simple', 'open_ended'] +MAPPINGS = { + 'edX/toy/2012_Fall': 'xml', + 'edX/simple/2012_Fall': 'xml', + 'edX/open_ended/2012_Fall': 'xml', +} +TEST_DATA_MIXED_XML_MODULESTORE = mixed_store_config( + DATA_DIR, MAPPINGS, include_xml=True, xml_course_dirs=XML_COURSE_DIRS +) class CommandsTestBase(TestCase): """ @@ -58,7 +62,7 @@ class CommandsTestBase(TestCase): courses = store.get_courses() # NOTE: if xml store owns these, it won't import them into mongo if SlashSeparatedCourseKey.from_deprecated_string(TEST_COURSE_ID) not in [c.id for c in courses]: - import_from_xml(store, ModuleStoreEnum.UserID.mgmt_command, DATA_DIR, ['toy', 'simple', 'open_ended']) + import_from_xml(store, ModuleStoreEnum.UserID.mgmt_command, DATA_DIR, XML_COURSE_DIRS) return [course.id for course in store.get_courses()] @@ -194,7 +198,7 @@ class CommandsTestBase(TestCase): assert_in('edX-simple-2012_Fall/sequential/Lecture_2.xml', names) -@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) +@override_settings(MODULESTORE=TEST_DATA_MIXED_XML_MODULESTORE) class CommandsXMLTestCase(CommandsTestBase, ModuleStoreTestCase): """ Test case for management commands using the xml modulestore. @@ -205,14 +209,6 @@ class CommandsXMLTestCase(CommandsTestBase, ModuleStoreTestCase): @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) class CommandsMongoTestCase(CommandsTestBase, ModuleStoreTestCase): """ - Test case for management commands using the mongo modulestore. - - """ - - -@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) -class CommandsMixedTestCase(CommandsTestBase, ModuleStoreTestCase): - """ - Test case for management commands. Using the mixed modulestore. + Test case for management commands using the mixed mongo modulestore. """ diff --git a/lms/djangoapps/courseware/tests/__init__.py b/lms/djangoapps/courseware/tests/__init__.py index 29f07391d5..c0cf78fdb3 100644 --- a/lms/djangoapps/courseware/tests/__init__.py +++ b/lms/djangoapps/courseware/tests/__init__.py @@ -13,7 +13,7 @@ from django.test.client import Client from edxmako.shortcuts import render_to_string from student.tests.factories import UserFactory, CourseEnrollmentFactory -from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE +from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE from xblock.field_data import DictFieldData from xmodule.tests import get_test_system, get_test_descriptor_system from opaque_keys.edx.locations import Location diff --git a/lms/djangoapps/courseware/tests/modulestore_config.py b/lms/djangoapps/courseware/tests/modulestore_config.py deleted file mode 100644 index 9b7908c575..0000000000 --- a/lms/djangoapps/courseware/tests/modulestore_config.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -Define test configuration for modulestores. -""" - -from xmodule.modulestore.tests.django_utils import xml_store_config, \ - mixed_store_config - -from django.conf import settings - -TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT -TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR) - -# Map all XML course fixtures so they are accessible through -# the MixedModuleStore -MAPPINGS = { - 'edX/simple/2012_Fall': 'xml', - 'edX/toy/2012_Fall': 'xml', - 'edX/toy/TT_2012_Fall': 'xml', - 'edX/test_end/2012_Fall': 'xml', - 'edX/test_about_blob_end_date/2012_Fall': 'xml', - 'edX/graded/2012_Fall': 'xml', - 'edX/open_ended/2012_Fall': 'xml', - 'edX/due_date/2013_fall': 'xml', - 'edX/open_ended_nopath/2012_Fall': 'xml', - 'edX/detached_pages/2014': 'xml', -} -TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, MAPPINGS) - -# All store requests now go through mixed -# Some tests require that no XML courses exist. So provide the following constant with no course Mappings. -TEST_DATA_MONGO_MODULESTORE = mixed_store_config(TEST_DATA_DIR, {}) diff --git a/lms/djangoapps/courseware/tests/test_about.py b/lms/djangoapps/courseware/tests/test_about.py index bd4cb51013..0231656313 100644 --- a/lms/djangoapps/courseware/tests/test_about.py +++ b/lms/djangoapps/courseware/tests/test_about.py @@ -1,33 +1,34 @@ """ Test the about xblock """ -import mock -from mock import patch -import pytz import datetime -from django.test.utils import override_settings -from django.core.urlresolvers import reverse +import pytz + from django.conf import settings +from django.core.urlresolvers import reverse +from django.test.utils import override_settings +from mock import patch +from opaque_keys.edx.locations import SlashSeparatedCourseKey + +from course_modes.models import CourseMode +from xmodule.modulestore.tests.django_utils import ( + TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_CLOSED_MODULESTORE +) +from student.models import CourseEnrollment +from student.tests.factories import UserFactory, CourseEnrollmentAllowedFactory +from shoppingcart.models import Order, PaidCourseRegistration +from xmodule.course_module import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from .helpers import LoginEnrollmentTestCase -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE, TEST_DATA_MIXED_MODULESTORE -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from opaque_keys.edx.locations import SlashSeparatedCourseKey -from student.tests.factories import UserFactory, CourseEnrollmentAllowedFactory -from course_modes.models import CourseMode -from student.models import CourseEnrollment - -from shoppingcart.models import Order, PaidCourseRegistration - -from xmodule.course_module import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE # HTML for registration button REG_STR = "