Merge pull request #6078 from edx/zoldak/modulestore-test-refactor

Clean up all modulestore testcases
This commit is contained in:
Jesse Zoldak
2014-12-02 08:53:41 -05:00
89 changed files with 909 additions and 823 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -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"""

View File

@@ -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

View File

@@ -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 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.django_utils import TEST_DATA_MOCK_MODULESTORE
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

View File

@@ -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.

View File

@@ -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 """

View File

@@ -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):
"""

View File

@@ -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

View File

@@ -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

View File

@@ -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,13 @@ 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 directories (relative to data_dir)
containing the courses you want to load
* mappings should be configured, pointing the xml courses to the xml modulestore
"""
stores = [
@@ -47,7 +55,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 +88,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 +115,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 +127,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 +145,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):
"""

View File

@@ -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):
"""

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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.