Merge pull request #1124 from edx/dhm/asset_policy
Just write the loc name as the key in the policy file
This commit is contained in:
@@ -999,13 +999,33 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
|
|||||||
|
|
||||||
# remove old course
|
# remove old course
|
||||||
delete_course(module_store, content_store, location, commit=True)
|
delete_course(module_store, content_store, location, commit=True)
|
||||||
|
# reimport over old course
|
||||||
# reimport
|
stub_location = Location(['i4x', 'edX', 'toy', None, None])
|
||||||
import_from_xml(
|
course_location = course.location
|
||||||
module_store, root_dir, ['test_export'], draft_store=draft_store, static_content_store=content_store
|
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)
|
self.assertGreater(len(items), 0)
|
||||||
for descriptor in items:
|
for descriptor in items:
|
||||||
# don't try to look at private verticals. Right now we're running
|
# 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)
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
|
||||||
# verify that we have the content in the draft store as well
|
# verify that we have the content in the draft store as well
|
||||||
vertical = draft_store.get_item(Location(['i4x', 'edX', 'toy',
|
vertical = draft_store.get_item(
|
||||||
'vertical', 'vertical_test', None]), depth=1)
|
stub_location.replace(category='vertical', name='vertical_test', revision=None),
|
||||||
|
depth=1
|
||||||
|
)
|
||||||
|
|
||||||
self.assertTrue(getattr(vertical, 'is_draft', False))
|
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)
|
self.assertNotIn('parent_sequential_url', vertical.xml_attributes)
|
||||||
|
|
||||||
for child in vertical.get_children():
|
for child in vertical.get_children():
|
||||||
@@ -1033,27 +1055,34 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
|
|||||||
self.assertNotIn('parent_sequential_url', child.data)
|
self.assertNotIn('parent_sequential_url', child.data)
|
||||||
|
|
||||||
# make sure that we don't have a sequential that is in draft mode
|
# make sure that we don't have a sequential that is in draft mode
|
||||||
sequential = draft_store.get_item(Location(['i4x', 'edX', 'toy',
|
sequential = draft_store.get_item(
|
||||||
'sequential', 'vertical_sequential', None]))
|
stub_location.replace(category='sequential', name='vertical_sequential', revision=None)
|
||||||
|
)
|
||||||
|
|
||||||
self.assertFalse(getattr(sequential, 'is_draft', False))
|
self.assertFalse(getattr(sequential, 'is_draft', False))
|
||||||
|
|
||||||
# verify that we have the private vertical
|
# verify that we have the private vertical
|
||||||
test_private_vertical = draft_store.get_item(Location(['i4x', 'edX', 'toy',
|
test_private_vertical = draft_store.get_item(
|
||||||
'vertical', 'a_private_vertical', None]))
|
stub_location.replace(category='vertical', name='a_private_vertical', revision=None)
|
||||||
|
)
|
||||||
|
|
||||||
self.assertTrue(getattr(test_private_vertical, 'is_draft', False))
|
self.assertTrue(getattr(test_private_vertical, 'is_draft', False))
|
||||||
|
|
||||||
# make sure the textbook survived the export/import
|
# 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)
|
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)
|
new_attrs = content_store.get_attrs(locked_asset)
|
||||||
for key, value in locked_asset_attrs.iteritems():
|
for key, value in locked_asset_attrs.iteritems():
|
||||||
self.assertEqual(value, new_attrs[key])
|
if key == '_id':
|
||||||
|
self.assertEqual(value['name'], new_attrs[key]['name'])
|
||||||
shutil.rmtree(root_dir)
|
elif key == 'filename':
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.assertEqual(value, new_attrs[key])
|
||||||
|
|
||||||
def test_export_course_with_metadata_only_video(self):
|
def test_export_course_with_metadata_only_video(self):
|
||||||
module_store = modulestore('direct')
|
module_store = modulestore('direct')
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ class MongoContentStore(ContentStore):
|
|||||||
self.export(asset_location, output_directory)
|
self.export(asset_location, output_directory)
|
||||||
for attr, value in asset.iteritems():
|
for attr, value in asset.iteritems():
|
||||||
if attr not in ['_id', 'md5', 'uploadDate', 'length', 'chunkSize']:
|
if attr not in ['_id', 'md5', 'uploadDate', 'length', 'chunkSize']:
|
||||||
policy.setdefault(asset_location.url(), {})[attr] = value
|
policy.setdefault(asset_location.name, {})[attr] = value
|
||||||
|
|
||||||
with open(assets_policy_file, 'w') as f:
|
with open(assets_policy_file, 'w') as f:
|
||||||
json.dump(policy, f)
|
json.dump(policy, f)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ def import_static_content(modules, course_loc, course_data_path, static_content_
|
|||||||
content_loc = StaticContent.compute_location(target_location_namespace.org, target_location_namespace.course, fullname_with_subpath)
|
content_loc = StaticContent.compute_location(target_location_namespace.org, target_location_namespace.course, fullname_with_subpath)
|
||||||
|
|
||||||
|
|
||||||
policy_ele = policy.get(content_loc.url(), {})
|
policy_ele = policy.get(content_loc.name, {})
|
||||||
displayname = policy_ele.get('displayname', filename)
|
displayname = policy_ele.get('displayname', filename)
|
||||||
locked = policy_ele.get('locked', False)
|
locked = policy_ele.get('locked', False)
|
||||||
mime_type = policy_ele.get('contentType', mimetypes.guess_type(filename)[0])
|
mime_type = policy_ele.get('contentType', mimetypes.guess_type(filename)[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user