diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py index 497bd7f792..74c7e7241a 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py @@ -345,6 +345,19 @@ class SplitMongoModuleStore(ModuleStoreBase): else: return [] + def get_instance(self, course_id, location, depth=0): + """ + Get an instance of this location. + + For now, just delegate to get_item and ignore course policy. + + depth (int): An argument that some module stores may use to prefetch + descendants of the queried modules for more efficient results later + in the request. The depth is counted in the number of + calls to get_children() to cache. None indicates to cache all descendants. + """ + return self.get_item(location, depth=depth) + def get_parent_locations(self, locator, usage_id=None): ''' Return the locations (Locators w/ usage_ids) for the parents of this location in this diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py index f86a8dcaef..086d85b72c 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py @@ -327,21 +327,29 @@ class SplitModuleItemTests(SplitModuleTest): locator = BlockUsageLocator(version_guid=self.GUID_D1, usage_id='head12345') block = modulestore().get_item(locator) self.assertIsInstance(block, CourseDescriptor) + # get_instance just redirects to get_item, ignores course_id + self.assertIsInstance(modulestore().get_instance("course_id", locator), CourseDescriptor) + + def verify_greek_hero(block): + self.assertEqual(block.location.course_id, "GreekHero") + + + # look at this one in detail + self.assertEqual(len(block.tabs), 6, "wrong number of tabs") + self.assertEqual(block.display_name, "The Ancient Greek Hero") + self.assertEqual(block.advertised_start, "Fall 2013") + self.assertEqual(len(block.children), 3) + self.assertEqual(block.definition_locator.definition_id, "head12345_12") + # check dates and graders--forces loading of descriptor + self.assertEqual(block.edited_by, "testassist@edx.org") + self.assertDictEqual( + block.grade_cutoffs, {"Pass": 0.45}, + ) locator = BlockUsageLocator(course_id='GreekHero', usage_id='head12345', branch='draft') - block = modulestore().get_item(locator) - self.assertEqual(block.location.course_id, "GreekHero") - # look at this one in detail - self.assertEqual(len(block.tabs), 6, "wrong number of tabs") - self.assertEqual(block.display_name, "The Ancient Greek Hero") - self.assertEqual(block.advertised_start, "Fall 2013") - self.assertEqual(len(block.children), 3) - self.assertEqual(block.definition_locator.definition_id, "head12345_12") - # check dates and graders--forces loading of descriptor - self.assertEqual(block.edited_by, "testassist@edx.org") - self.assertDictEqual( - block.grade_cutoffs, {"Pass": 0.45}, - ) + verify_greek_hero(modulestore().get_item(locator)) + # get_instance just redirects to get_item, ignores course_id + verify_greek_hero(modulestore().get_instance("course_id", locator)) # try to look up other branches self.assertRaises(ItemNotFoundError,