Separate db config from modulestore config parms
use to instantiate loc_mapper test loc_mapper injection into split modulestore
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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': {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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': {
|
||||
|
||||
Reference in New Issue
Block a user