Add get_instance method.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user