Commit fc1ca7b3 by Don Mitchell

No longer create loc maps on create_(item|course)

parent dcc6f544
...@@ -441,8 +441,6 @@ class BlockUsageLocator(CourseLocator): ...@@ -441,8 +441,6 @@ class BlockUsageLocator(CourseLocator):
Returns a copy of itself without any version info. Returns a copy of itself without any version info.
:raises: ValueError if the block locator has no package_id :raises: ValueError if the block locator has no package_id
:param block_locator:
""" """
return BlockUsageLocator(package_id=self.package_id, return BlockUsageLocator(package_id=self.package_id,
branch=self.branch, branch=self.branch,
...@@ -454,8 +452,6 @@ class BlockUsageLocator(CourseLocator): ...@@ -454,8 +452,6 @@ class BlockUsageLocator(CourseLocator):
Returns a copy of itself without any course info. Returns a copy of itself without any course info.
:raises: ValueError if the block locator has no version_guid :raises: ValueError if the block locator has no version_guid
:param block_locator:
""" """
return BlockUsageLocator(version_guid=self.version_guid, return BlockUsageLocator(version_guid=self.version_guid,
block_id=self.block_id) block_id=self.block_id)
......
...@@ -625,12 +625,19 @@ class MongoModuleStore(ModuleStoreWriteBase): ...@@ -625,12 +625,19 @@ class MongoModuleStore(ModuleStoreWriteBase):
modules = self._load_items(list(items), depth) modules = self._load_items(list(items), depth)
return modules return modules
def create_course(self, location, definition_data=None, metadata=None, runtime=None): def create_course(self, course_id, definition_data=None, metadata=None, runtime=None):
""" """
Create a course with the given location. The location category must be 'course'. Create a course with the given course_id.
""" """
if location.category != 'course': if isinstance(course_id, Location):
raise ValueError(u"Course roots must be of category 'course': {}".format(unicode(location))) location = course_id
if location.category != 'course':
raise ValueError(u"Course roots must be of category 'course': {}".format(unicode(location)))
else:
course_dict = Location.parse_course_id(course_id)
course_dict['category'] = 'course'
course_dict['tag'] = 'i4x'
location = Location(course_dict)
return self.create_and_save_xmodule(location, definition_data, metadata, runtime) return self.create_and_save_xmodule(location, definition_data, metadata, runtime)
def create_xmodule(self, location, definition_data=None, metadata=None, system=None, fields={}): def create_xmodule(self, location, definition_data=None, metadata=None, system=None, fields={}):
......
...@@ -110,25 +110,23 @@ class TestMixedModuleStore(LocMapperSetupSansDjango): ...@@ -110,25 +110,23 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self.addCleanup(patcher.stop) self.addCleanup(patcher.stop)
self.addTypeEqualityFunc(BlockUsageLocator, '_compareIgnoreVersion') self.addTypeEqualityFunc(BlockUsageLocator, '_compareIgnoreVersion')
def _create_course(self, default, course_location, item_location): def _create_course(self, default, course_id):
""" """
Create a course w/ one item in the persistence store using the given course & item location. Create a course w/ one item in the persistence store using the given course & item location.
NOTE: course_location and item_location must be Location regardless of the app reference type in order
to cause the right mapping to be created.
""" """
course = self.store.create_course( course = self.store.create_course(course_id, store_name=default)
course_location, store_name=default, metadata={'display_name': course_location.name} category = self.import_chapter_location.category
) block_id = self.import_chapter_location.name
chapter = self.store.create_item( chapter = self.store.create_item(
# don't use course_location as it may not be the repr # don't use course_location as it may not be the repr
course.location, item_location.category, location=item_location, block_id=item_location.name course.location, category, location=self.import_chapter_location, block_id=block_id
) )
if isinstance(course.location, CourseLocator): if isinstance(course.location, CourseLocator):
self.course_locations[self.MONGO_COURSEID] = course.location.version_agnostic() self.course_locations[self.MONGO_COURSEID] = course.location.version_agnostic()
self.import_chapter_location = chapter.location.version_agnostic() self.import_chapter_location = chapter.location.version_agnostic()
else: else:
self.assertEqual(course.location, course_location) self.assertEqual(course.location.course_id, course_id)
self.assertEqual(chapter.location, item_location) self.assertEqual(chapter.location, self.import_chapter_location)
def initdb(self, default): def initdb(self, default):
""" """
...@@ -159,13 +157,11 @@ class TestMixedModuleStore(LocMapperSetupSansDjango): ...@@ -159,13 +157,11 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self.xml_chapter_location = self.course_locations[self.XML_COURSEID1].replace( self.xml_chapter_location = self.course_locations[self.XML_COURSEID1].replace(
category='chapter', name='Overview' category='chapter', name='Overview'
) )
# grab old style location b4 possibly converted
import_location = self.course_locations[self.MONGO_COURSEID]
# get Locators and set up the loc mapper if app is Locator based # get Locators and set up the loc mapper if app is Locator based
if default == 'split': if default == 'split':
self.fake_location = loc_mapper().translate_location('foo/bar/2012_Fall', self.fake_location) self.fake_location = loc_mapper().translate_location('foo/bar/2012_Fall', self.fake_location)
self._create_course(default, import_location, self.import_chapter_location) self._create_course(default, self.MONGO_COURSEID)
@ddt.data('direct', 'split') @ddt.data('direct', 'split')
def test_get_modulestore_type(self, default_ms): def test_get_modulestore_type(self, default_ms):
...@@ -273,12 +269,12 @@ class TestMixedModuleStore(LocMapperSetupSansDjango): ...@@ -273,12 +269,12 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self.initdb(default_ms) self.initdb(default_ms)
# we should have 3 total courses across all stores # we should have 3 total courses across all stores
courses = self.store.get_courses() courses = self.store.get_courses()
self.assertEqual(len(courses), 3)
course_ids = [ course_ids = [
course.location.version_agnostic() course.location.version_agnostic()
if hasattr(course.location, 'version_agnostic') else course.location if hasattr(course.location, 'version_agnostic') else course.location
for course in courses for course in courses
] ]
self.assertEqual(len(courses), 3, "Not 3 courses: {}".format(course_ids))
self.assertIn(self.course_locations[self.MONGO_COURSEID], course_ids) self.assertIn(self.course_locations[self.MONGO_COURSEID], course_ids)
self.assertIn(self.course_locations[self.XML_COURSEID1], course_ids) self.assertIn(self.course_locations[self.XML_COURSEID1], course_ids)
self.assertIn(self.course_locations[self.XML_COURSEID2], course_ids) self.assertIn(self.course_locations[self.XML_COURSEID2], course_ids)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment