From 30155d33bd2789eedaf21cad48d9898f9b0601cf Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Tue, 30 Sep 2014 15:01:20 -0400 Subject: [PATCH] Test caching of courses in mixed maps --- .../modulestore/tests/test_mixed_modulestore.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py index 8b6f6e32c1..da07fae420 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -30,7 +30,7 @@ from xmodule.modulestore.draft_and_published import UnsupportedRevisionError from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError, ReferentialIntegrityError, NoPathToItem from xmodule.modulestore.mixed import MixedModuleStore from xmodule.modulestore.search import path_to_location -from xmodule.modulestore.tests.factories import check_mongo_calls +from xmodule.modulestore.tests.factories import check_mongo_calls, check_exact_number_of_calls from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST from xmodule.tests import DATA_DIR @@ -272,6 +272,20 @@ class TestMixedModuleStore(unittest.TestCase): SlashSeparatedCourseKey('foo', 'bar', '2012_Fall')), mongo_ms_type ) + @ddt.data('draft', 'split') + def test_get_modulestore_cache(self, default_ms): + """ + Make sure we cache discovered course mappings + """ + self.initdb(default_ms) + # unset mappings + self.store.mappings = {} + course_key = self.course_locations[self.MONGO_COURSEID].course_key + with check_exact_number_of_calls(self.store.default_modulestore, 'has_course', 1): + self.assertEqual(self.store.default_modulestore, self.store._get_modulestore_for_courseid(course_key)) + self.assertIn(course_key, self.store.mappings) + self.assertEqual(self.store.default_modulestore, self.store._get_modulestore_for_courseid(course_key)) + @ddt.data(*itertools.product( (ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split), (True, False)