diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 6f40ac0e53..288e6443f7 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -999,13 +999,33 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): # remove old course delete_course(module_store, content_store, location, commit=True) - - # reimport - import_from_xml( - module_store, root_dir, ['test_export'], draft_store=draft_store, static_content_store=content_store + # reimport over old course + stub_location = Location(['i4x', 'edX', 'toy', None, None]) + course_location = course.location + self.check_import( + module_store, root_dir, draft_store, content_store, stub_location, course_location, + locked_asset, locked_asset_attrs + ) + # import to different course id + stub_location = Location(['i4x', 'anotherX', 'anotherToy', None, None]) + course_location = stub_location.replace(category='course', name='Someday') + self.check_import( + module_store, root_dir, draft_store, content_store, stub_location, course_location, + locked_asset, locked_asset_attrs ) - items = module_store.get_items(Location(['i4x', 'edX', 'toy', 'vertical', None])) + shutil.rmtree(root_dir) + + def check_import(self, module_store, root_dir, draft_store, content_store, stub_location, course_location, + locked_asset, locked_asset_attrs): + # reimport + import_from_xml( + module_store, root_dir, ['test_export'], draft_store=draft_store, + static_content_store=content_store, + target_location_namespace=course_location + ) + + items = module_store.get_items(stub_location.replace(category='vertical', name=None)) self.assertGreater(len(items), 0) for descriptor in items: # don't try to look at private verticals. Right now we're running @@ -1016,11 +1036,13 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): self.assertEqual(resp.status_code, 200) # verify that we have the content in the draft store as well - vertical = draft_store.get_item(Location(['i4x', 'edX', 'toy', - 'vertical', 'vertical_test', None]), depth=1) + vertical = draft_store.get_item( + stub_location.replace(category='vertical', name='vertical_test', revision=None), + depth=1 + ) self.assertTrue(getattr(vertical, 'is_draft', False)) - self.assertNotIn('index_in_children_list', child.xml_attributes) + self.assertNotIn('index_in_children_list', vertical.xml_attributes) self.assertNotIn('parent_sequential_url', vertical.xml_attributes) for child in vertical.get_children(): @@ -1033,27 +1055,34 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): self.assertNotIn('parent_sequential_url', child.data) # make sure that we don't have a sequential that is in draft mode - sequential = draft_store.get_item(Location(['i4x', 'edX', 'toy', - 'sequential', 'vertical_sequential', None])) + sequential = draft_store.get_item( + stub_location.replace(category='sequential', name='vertical_sequential', revision=None) + ) self.assertFalse(getattr(sequential, 'is_draft', False)) # verify that we have the private vertical - test_private_vertical = draft_store.get_item(Location(['i4x', 'edX', 'toy', - 'vertical', 'a_private_vertical', None])) + test_private_vertical = draft_store.get_item( + stub_location.replace(category='vertical', name='a_private_vertical', revision=None) + ) self.assertTrue(getattr(test_private_vertical, 'is_draft', False)) # make sure the textbook survived the export/import - course = module_store.get_item(Location(['i4x', 'edX', 'toy', 'course', '2012_Fall', None])) + course = module_store.get_item(course_location) self.assertGreater(len(course.textbooks), 0) + locked_asset['course'] = stub_location.course + locked_asset['org'] = stub_location.org new_attrs = content_store.get_attrs(locked_asset) for key, value in locked_asset_attrs.iteritems(): - self.assertEqual(value, new_attrs[key]) - - shutil.rmtree(root_dir) + if key == '_id': + self.assertEqual(value['name'], new_attrs[key]['name']) + elif key == 'filename': + pass + else: + self.assertEqual(value, new_attrs[key]) def test_export_course_with_metadata_only_video(self): module_store = modulestore('direct')