diff --git a/cms/djangoapps/contentstore/tests/test_crud.py b/cms/djangoapps/contentstore/tests/test_crud.py index a16251fa0f..b95d58d913 100644 --- a/cms/djangoapps/contentstore/tests/test_crud.py +++ b/cms/djangoapps/contentstore/tests/test_crud.py @@ -2,7 +2,7 @@ import unittest from xmodule import templates from xmodule.modulestore.tests import persistent_factories from xmodule.course_module import CourseDescriptor -from xmodule.modulestore.django import modulestore +from xmodule.modulestore.django import modulestore, loc_mapper from xmodule.seq_module import SequenceDescriptor from xmodule.capa_module import CapaDescriptor from xmodule.modulestore.locator import CourseLocator, BlockUsageLocator @@ -191,6 +191,26 @@ class TemplateTests(unittest.TestCase): version_history = modulestore('split').get_block_generations(second_problem.location) self.assertNotEqual(version_history.locator.version_guid, first_problem.location.version_guid) + def test_split_inject_loc_mapper(self): + """ + Test that creating a loc_mapper causes it to automatically attach to the split mongo store + """ + # instantiate location mapper before split + mapper = loc_mapper() + # split must inject the location mapper itself since the mapper existed before it did + self.assertEqual(modulestore('split').loc_mapper, mapper) + + def test_loc_inject_into_split(self): + """ + Test that creating a loc_mapper causes it to automatically attach to the split mongo store + """ + # force instantiation of split modulestore before there's a location mapper and verify + # it has no pointer to loc mapper + self.assertIsNone(modulestore('split').loc_mapper) + # force instantiation of location mapper which must inject itself into the split + mapper = loc_mapper() + self.assertEqual(modulestore('split').loc_mapper, mapper) + # ================================= JSON PARSING =========================== # These are example methods for creating xmodules in memory w/o persisting them. # They were in x_module but since xblock is not planning to support them but will diff --git a/cms/envs/acceptance.py b/cms/envs/acceptance.py index bbb767118c..73dc91dbd7 100644 --- a/cms/envs/acceptance.py +++ b/cms/envs/acceptance.py @@ -24,14 +24,17 @@ from random import choice, randint def seed(): return os.getppid() -MODULESTORE_OPTIONS = { - 'default_class': 'xmodule.raw_module.RawDescriptor', +DOC_STORE_CONFIG = { 'host': 'localhost', 'db': 'acceptance_xmodule', 'collection': 'acceptance_modulestore_%s' % seed(), +} + +MODULESTORE_OPTIONS = dict({ + 'default_class': 'xmodule.raw_module.RawDescriptor', 'fs_root': TEST_ROOT / "data", 'render_template': 'mitxmako.shortcuts.render_to_string', -} +}, **DOC_STORE_CONFIG) MODULESTORE = { 'default': { @@ -90,6 +93,6 @@ LETTUCE_BROWSER = os.environ.get('LETTUCE_BROWSER', 'chrome') ##################################################################### # Lastly, see if the developer has any local overrides. try: - from .private import * # pylint: disable=F0401 + from .private import * # pylint: disable=F0401 except ImportError: pass diff --git a/cms/envs/dev.py b/cms/envs/dev.py index 42a6f706b6..6e4ce460c3 100644 --- a/cms/envs/dev.py +++ b/cms/envs/dev.py @@ -16,14 +16,17 @@ LOGGING = get_logger_config(ENV_ROOT / "log", dev_env=True, debug=True) -modulestore_options = { - 'default_class': 'xmodule.raw_module.RawDescriptor', +DOC_STORE_CONFIG = { 'host': 'localhost', 'db': 'xmodule', 'collection': 'modulestore', +} + +modulestore_options = dict({ + 'default_class': 'xmodule.raw_module.RawDescriptor', 'fs_root': GITHUB_REPO_ROOT, 'render_template': 'mitxmako.shortcuts.render_to_string', -} +}, **DOC_STORE_CONFIG) MODULESTORE = { 'default': { @@ -185,6 +188,6 @@ if SEGMENT_IO_KEY: ##################################################################### # Lastly, see if the developer has any local overrides. try: - from .private import * # pylint: disable=F0401 + from .private import * # pylint: disable=F0401 except ImportError: pass diff --git a/cms/envs/test.py b/cms/envs/test.py index ffbf9f5376..364bee2441 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -42,14 +42,17 @@ STATICFILES_DIRS += [ if os.path.isdir(COMMON_TEST_DATA_ROOT / course_dir) ] -MODULESTORE_OPTIONS = { - 'default_class': 'xmodule.raw_module.RawDescriptor', +DOC_STORE_CONFIG = { 'host': 'localhost', 'db': 'test_xmodule', 'collection': 'test_modulestore', +} + +MODULESTORE_OPTIONS = dict({ + 'default_class': 'xmodule.raw_module.RawDescriptor', 'fs_root': TEST_ROOT / "data", 'render_template': 'mitxmako.shortcuts.render_to_string', -} +}, **DOC_STORE_CONFIG) MODULESTORE = { 'default': { diff --git a/common/lib/xmodule/xmodule/modulestore/django.py b/common/lib/xmodule/xmodule/modulestore/django.py index d9176f6abf..284f5e4eb7 100644 --- a/common/lib/xmodule/xmodule/modulestore/django.py +++ b/common/lib/xmodule/xmodule/modulestore/django.py @@ -93,7 +93,7 @@ def loc_mapper(): # pylint: disable=W0212 if _loc_singleton is None: # instantiate - _loc_singleton = LocMapperStore(settings.modulestore_options) + _loc_singleton = LocMapperStore(**settings.DOC_STORE_CONFIG) # inject into split mongo modulestore if 'split' in _MODULESTORES: _MODULESTORES['split'].loc_mapper = _loc_singleton diff --git a/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py b/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py index 4ab3a8106d..1b4cee7c95 100644 --- a/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py +++ b/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py @@ -33,11 +33,6 @@ class LocMapperStore(object): ''' Constructor ''' - # get rid of unwanted args - kwargs.pop('default_class', None) - kwargs.pop('fs_root', None) - kwargs.pop('xblock_mixins', None) - kwargs.pop('render_template', None) self.db = pymongo.database.Database( pymongo.MongoClient( host=host, 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 86c99f7015..40e1b466c4 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_migrator.py @@ -25,19 +25,22 @@ from xmodule.modulestore.mongo import draft class TestMigration(unittest.TestCase): # Snippet of what would be in the django settings envs file - modulestore_options = { - 'default_class': 'xmodule.raw_module.RawDescriptor', + db_config = { 'host': 'localhost', 'db': 'test_xmodule', 'collection': 'modulestore{0}'.format(uuid.uuid4().hex), + } + + modulestore_options = dict({ + 'default_class': 'xmodule.raw_module.RawDescriptor', 'fs_root': '', 'render_template': mock.Mock(return_value=""), 'xblock_mixins': (InheritanceMixin,) - } + }, **db_config) def setUp(self): super(TestMigration, self).setUp() - self.loc_mapper = LocMapperStore(**self.modulestore_options) + self.loc_mapper = LocMapperStore(**self.db_config) self.old_mongo = MongoModuleStore(**self.modulestore_options) self.draft_mongo = DraftModuleStore(**self.modulestore_options) self.split_mongo = SplitMongoModuleStore( diff --git a/lms/envs/acceptance.py b/lms/envs/acceptance.py index 2182bbcad6..b261e2be54 100644 --- a/lms/envs/acceptance.py +++ b/lms/envs/acceptance.py @@ -26,14 +26,17 @@ def seed(): return os.getppid() # Use the mongo store for acceptance tests -modulestore_options = { - 'default_class': 'xmodule.raw_module.RawDescriptor', +DOC_STORE_CONFIG = { 'host': 'localhost', 'db': 'acceptance_xmodule', 'collection': 'acceptance_modulestore_%s' % seed(), +} + +modulestore_options = dict({ + 'default_class': 'xmodule.raw_module.RawDescriptor', 'fs_root': TEST_ROOT / "data", 'render_template': 'mitxmako.shortcuts.render_to_string', -} +}, **DOC_STORE_CONFIG) MODULESTORE = { 'default': { @@ -129,6 +132,6 @@ LETTUCE_BROWSER = os.environ.get('LETTUCE_BROWSER', 'chrome') ##################################################################### # Lastly, see if the developer has any local overrides. try: - from .private import * # pylint: disable=F0401 + from .private import * # pylint: disable=F0401 except ImportError: pass diff --git a/lms/envs/cms/dev.py b/lms/envs/cms/dev.py index 0d11c373c9..7026d45366 100644 --- a/lms/envs/cms/dev.py +++ b/lms/envs/cms/dev.py @@ -22,14 +22,17 @@ MITX_FEATURES['ENABLE_LMS_MIGRATION'] = False META_UNIVERSITIES = {} -modulestore_options = { - 'default_class': 'xmodule.raw_module.RawDescriptor', +DOC_STORE_CONFIG = { 'host': 'localhost', 'db': 'xmodule', 'collection': 'modulestore', +} + +modulestore_options = dict({ + 'default_class': 'xmodule.raw_module.RawDescriptor', 'fs_root': DATA_DIR, 'render_template': 'mitxmako.shortcuts.render_to_string', -} +}, **DOC_STORE_CONFIG) MODULESTORE = { 'default': {