From 3402c657e927b8174ed2204d0bc530cedb5ed273 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 22 Apr 2016 13:27:43 -0400 Subject: [PATCH] Use separate ContentStore databases for every test --- .../xmodule/modulestore/tests/django_utils.py | 26 +++++++++++++++++++ lms/envs/test.py | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index 87333bff23..147563a967 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -130,6 +130,27 @@ def split_mongo_store_config(data_dir): return store +def contentstore_config(): + """ + Return a new configuration for the contentstore that is isolated + from other such configurations. + """ + return { + 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', + 'DOC_STORE_CONFIG': { + 'host': MONGO_HOST, + 'db': 'test_xcontent_{}'.format(uuid4().hex), + 'port': MONGO_PORT_NUM, + }, + # allow for additional options that can be keyed on a name, e.g. 'trashcan' + 'ADDITIONAL_OPTIONS': { + 'trashcan': { + 'bucket': 'trash_fs' + } + } + } + + @patch('xmodule.modulestore.django.create_modulestore_instance', autospec=True) def drop_mongo_collections(mock_create): """ @@ -195,9 +216,11 @@ class ModuleStoreIsolationMixin(CacheIsolationMixin): """ MODULESTORE = functools.partial(mixed_store_config, mkdtemp_clean(), {}) + CONTENTSTORE = functools.partial(contentstore_config) ENABLED_CACHES = ['mongo_metadata_inheritance', 'loc_cache'] __settings_overrides = [] __old_modulestores = [] + __old_contentstores = [] @classmethod def start_modulestore_isolation(cls): @@ -209,9 +232,11 @@ class ModuleStoreIsolationMixin(CacheIsolationMixin): cls.start_cache_isolation() override = override_settings( MODULESTORE=cls.MODULESTORE(), + CONTENTSTORE=cls.CONTENTSTORE(), ) cls.__old_modulestores.append(copy.deepcopy(settings.MODULESTORE)) + cls.__old_contentstores.append(copy.deepcopy(settings.CONTENTSTORE)) override.__enter__() cls.__settings_overrides.append(override) XMODULE_FACTORY_LOCK.enable() @@ -230,6 +255,7 @@ class ModuleStoreIsolationMixin(CacheIsolationMixin): cls.__settings_overrides.pop().__exit__(None, None, None) assert settings.MODULESTORE == cls.__old_modulestores.pop() + assert settings.CONTENTSTORE == cls.__old_contentstores.pop() cls.end_cache_isolation() diff --git a/lms/envs/test.py b/lms/envs/test.py index 41aee320a6..344a9ddc47 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -173,7 +173,7 @@ CONTENTSTORE = { 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', 'DOC_STORE_CONFIG': { 'host': MONGO_HOST, - 'db': 'xcontent', + 'db': 'test_xcontent_{}'.format(THIS_UUID), 'port': MONGO_PORT_NUM, } }