Commit 59b31474 by Don Mitchell

Separate db config from modulestore config parms

use to instantiate loc_mapper
test loc_mapper injection into split modulestore
parent d328c53d
...@@ -2,7 +2,7 @@ import unittest ...@@ -2,7 +2,7 @@ import unittest
from xmodule import templates from xmodule import templates
from xmodule.modulestore.tests import persistent_factories from xmodule.modulestore.tests import persistent_factories
from xmodule.course_module import CourseDescriptor 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.seq_module import SequenceDescriptor
from xmodule.capa_module import CapaDescriptor from xmodule.capa_module import CapaDescriptor
from xmodule.modulestore.locator import CourseLocator, BlockUsageLocator from xmodule.modulestore.locator import CourseLocator, BlockUsageLocator
...@@ -191,6 +191,26 @@ class TemplateTests(unittest.TestCase): ...@@ -191,6 +191,26 @@ class TemplateTests(unittest.TestCase):
version_history = modulestore('split').get_block_generations(second_problem.location) version_history = modulestore('split').get_block_generations(second_problem.location)
self.assertNotEqual(version_history.locator.version_guid, first_problem.location.version_guid) 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 =========================== # ================================= JSON PARSING ===========================
# These are example methods for creating xmodules in memory w/o persisting them. # 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 # 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 ...@@ -24,14 +24,17 @@ from random import choice, randint
def seed(): def seed():
return os.getppid() return os.getppid()
MODULESTORE_OPTIONS = { DOC_STORE_CONFIG = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'acceptance_xmodule', 'db': 'acceptance_xmodule',
'collection': 'acceptance_modulestore_%s' % seed(), 'collection': 'acceptance_modulestore_%s' % seed(),
}
MODULESTORE_OPTIONS = dict({
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': TEST_ROOT / "data", 'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
...@@ -90,6 +93,6 @@ LETTUCE_BROWSER = os.environ.get('LETTUCE_BROWSER', 'chrome') ...@@ -90,6 +93,6 @@ LETTUCE_BROWSER = os.environ.get('LETTUCE_BROWSER', 'chrome')
##################################################################### #####################################################################
# Lastly, see if the developer has any local overrides. # Lastly, see if the developer has any local overrides.
try: try:
from .private import * # pylint: disable=F0401 from .private import * # pylint: disable=F0401
except ImportError: except ImportError:
pass pass
...@@ -16,14 +16,17 @@ LOGGING = get_logger_config(ENV_ROOT / "log", ...@@ -16,14 +16,17 @@ LOGGING = get_logger_config(ENV_ROOT / "log",
dev_env=True, dev_env=True,
debug=True) debug=True)
modulestore_options = { DOC_STORE_CONFIG = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'xmodule', 'db': 'xmodule',
'collection': 'modulestore', 'collection': 'modulestore',
}
modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': GITHUB_REPO_ROOT, 'fs_root': GITHUB_REPO_ROOT,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
...@@ -185,6 +188,6 @@ if SEGMENT_IO_KEY: ...@@ -185,6 +188,6 @@ if SEGMENT_IO_KEY:
##################################################################### #####################################################################
# Lastly, see if the developer has any local overrides. # Lastly, see if the developer has any local overrides.
try: try:
from .private import * # pylint: disable=F0401 from .private import * # pylint: disable=F0401
except ImportError: except ImportError:
pass pass
...@@ -42,14 +42,17 @@ STATICFILES_DIRS += [ ...@@ -42,14 +42,17 @@ STATICFILES_DIRS += [
if os.path.isdir(COMMON_TEST_DATA_ROOT / course_dir) if os.path.isdir(COMMON_TEST_DATA_ROOT / course_dir)
] ]
MODULESTORE_OPTIONS = { DOC_STORE_CONFIG = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'test_modulestore', 'collection': 'test_modulestore',
}
MODULESTORE_OPTIONS = dict({
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': TEST_ROOT / "data", 'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
......
...@@ -93,7 +93,7 @@ def loc_mapper(): ...@@ -93,7 +93,7 @@ def loc_mapper():
# pylint: disable=W0212 # pylint: disable=W0212
if _loc_singleton is None: if _loc_singleton is None:
# instantiate # instantiate
_loc_singleton = LocMapperStore(settings.modulestore_options) _loc_singleton = LocMapperStore(**settings.DOC_STORE_CONFIG)
# inject into split mongo modulestore # inject into split mongo modulestore
if 'split' in _MODULESTORES: if 'split' in _MODULESTORES:
_MODULESTORES['split'].loc_mapper = _loc_singleton _MODULESTORES['split'].loc_mapper = _loc_singleton
......
...@@ -33,11 +33,6 @@ class LocMapperStore(object): ...@@ -33,11 +33,6 @@ class LocMapperStore(object):
''' '''
Constructor 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( self.db = pymongo.database.Database(
pymongo.MongoClient( pymongo.MongoClient(
host=host, host=host,
......
...@@ -25,19 +25,22 @@ from xmodule.modulestore.mongo import draft ...@@ -25,19 +25,22 @@ from xmodule.modulestore.mongo import draft
class TestMigration(unittest.TestCase): class TestMigration(unittest.TestCase):
# Snippet of what would be in the django settings envs file # Snippet of what would be in the django settings envs file
modulestore_options = { db_config = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'test_xmodule', 'db': 'test_xmodule',
'collection': 'modulestore{0}'.format(uuid.uuid4().hex), 'collection': 'modulestore{0}'.format(uuid.uuid4().hex),
}
modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': '', 'fs_root': '',
'render_template': mock.Mock(return_value=""), 'render_template': mock.Mock(return_value=""),
'xblock_mixins': (InheritanceMixin,) 'xblock_mixins': (InheritanceMixin,)
} }, **db_config)
def setUp(self): def setUp(self):
super(TestMigration, self).setUp() 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.old_mongo = MongoModuleStore(**self.modulestore_options)
self.draft_mongo = DraftModuleStore(**self.modulestore_options) self.draft_mongo = DraftModuleStore(**self.modulestore_options)
self.split_mongo = SplitMongoModuleStore( self.split_mongo = SplitMongoModuleStore(
......
...@@ -26,14 +26,17 @@ def seed(): ...@@ -26,14 +26,17 @@ def seed():
return os.getppid() return os.getppid()
# Use the mongo store for acceptance tests # Use the mongo store for acceptance tests
modulestore_options = { DOC_STORE_CONFIG = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'acceptance_xmodule', 'db': 'acceptance_xmodule',
'collection': 'acceptance_modulestore_%s' % seed(), 'collection': 'acceptance_modulestore_%s' % seed(),
}
modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': TEST_ROOT / "data", 'fs_root': TEST_ROOT / "data",
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
...@@ -129,6 +132,6 @@ LETTUCE_BROWSER = os.environ.get('LETTUCE_BROWSER', 'chrome') ...@@ -129,6 +132,6 @@ LETTUCE_BROWSER = os.environ.get('LETTUCE_BROWSER', 'chrome')
##################################################################### #####################################################################
# Lastly, see if the developer has any local overrides. # Lastly, see if the developer has any local overrides.
try: try:
from .private import * # pylint: disable=F0401 from .private import * # pylint: disable=F0401
except ImportError: except ImportError:
pass pass
...@@ -22,14 +22,17 @@ MITX_FEATURES['ENABLE_LMS_MIGRATION'] = False ...@@ -22,14 +22,17 @@ MITX_FEATURES['ENABLE_LMS_MIGRATION'] = False
META_UNIVERSITIES = {} META_UNIVERSITIES = {}
modulestore_options = { DOC_STORE_CONFIG = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost', 'host': 'localhost',
'db': 'xmodule', 'db': 'xmodule',
'collection': 'modulestore', 'collection': 'modulestore',
}
modulestore_options = dict({
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': DATA_DIR, 'fs_root': DATA_DIR,
'render_template': 'mitxmako.shortcuts.render_to_string', 'render_template': 'mitxmako.shortcuts.render_to_string',
} }, **DOC_STORE_CONFIG)
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment