From 71ac8441205555b6f5e178a71d4b679ec07dbc61 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Tue, 4 Mar 2014 11:50:59 -0500 Subject: [PATCH] Add tests for get_orphans --- common/lib/xmodule/xmodule/modulestore/mixed.py | 4 ++++ .../modulestore/tests/test_mixed_modulestore.py | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mixed.py b/common/lib/xmodule/xmodule/modulestore/mixed.py index 1adab076f3..4b675fc146 100644 --- a/common/lib/xmodule/xmodule/modulestore/mixed.py +++ b/common/lib/xmodule/xmodule/modulestore/mixed.py @@ -334,6 +334,10 @@ class MixedModuleStore(ModuleStoreWriteBase): # convert parent loc if it's legit if isinstance(course_or_parent_loc, basestring): parent_loc = None + if location is None: + loc_dict = Location.parse_course_id(course_id) + loc_dict['name'] = block_id + location = Location(category=category, **loc_dict) else: parent_loc = course_or_parent_loc # must have a legitimate location, compute if appropriate 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 a168705993..dac4870f51 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -317,7 +317,6 @@ class TestMixedModuleStore(LocMapperSetupSansDjango): self.assertIsNotNone(course) self.assertEqual(course.location, course_locn) - # pylint: disable=E1101 @ddt.data('direct', 'split') def test_get_parent_locations(self, default_ms): self.initdb(default_ms) @@ -335,6 +334,22 @@ class TestMixedModuleStore(LocMapperSetupSansDjango): self.assertEqual(len(parents), 1) self.assertEqual(parents[0], self.course_locations[self.XML_COURSEID1]) + @ddt.data('direct', 'split') + def test_get_orphans(self, default_ms): + self.initdb(default_ms) + # create an orphan + if default_ms == 'split': + course_id = self.course_locations[self.MONGO_COURSEID].as_course_locator() + branch = course_id.branch + else: + course_id = self.MONGO_COURSEID + branch = None + orphan = self.store.create_item(course_id, 'problem', block_id='orphan') + found_orphans = self.store.get_orphans(self.course_locations[self.MONGO_COURSEID], branch) + if default_ms == 'split': + self.assertEqual(found_orphans, [orphan.location.version_agnostic()]) + else: + self.assertEqual(found_orphans, [unicode(orphan.location)]) #============================================================================================================= # General utils for not using django settings