本文整理汇总了Python中opaque_keys.edx.locations.AssetLocation._from_deprecated_son方法的典型用法代码示例。如果您正苦于以下问题:Python AssetLocation._from_deprecated_son方法的具体用法?Python AssetLocation._from_deprecated_son怎么用?Python AssetLocation._from_deprecated_son使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opaque_keys.edx.locations.AssetLocation
的用法示例。
在下文中一共展示了AssetLocation._from_deprecated_son方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_contentstore_attrs
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import _from_deprecated_son [as 别名]
def test_contentstore_attrs(self):
"""
Test getting, setting, and defaulting the locked attr and arbitrary attrs.
"""
location = Location('edX', 'toy', '2012_Fall', 'course', '2012_Fall')
course_content, __ = self.content_store.get_all_content_for_course(location.course_key)
assert_true(len(course_content) > 0)
# a bit overkill, could just do for content[0]
for content in course_content:
assert not content.get('locked', False)
asset_key = AssetLocation._from_deprecated_son(content.get('content_son', content['_id']), location.run)
assert not self.content_store.get_attr(asset_key, 'locked', False)
attrs = self.content_store.get_attrs(asset_key)
assert_in('uploadDate', attrs)
assert not attrs.get('locked', False)
self.content_store.set_attr(asset_key, 'locked', True)
assert self.content_store.get_attr(asset_key, 'locked', False)
attrs = self.content_store.get_attrs(asset_key)
assert_in('locked', attrs)
assert attrs['locked'] is True
self.content_store.set_attrs(asset_key, {'miscel': 99})
assert_equals(self.content_store.get_attr(asset_key, 'miscel'), 99)
asset_key = AssetLocation._from_deprecated_son(
course_content[0].get('content_son', course_content[0]['_id']),
location.run
)
assert_raises(
AttributeError, self.content_store.set_attr, asset_key,
'md5', 'ff1532598830e3feac91c2449eaa60d6'
)
assert_raises(
AttributeError, self.content_store.set_attrs, asset_key,
{'foo': 9, 'md5': 'ff1532598830e3feac91c2449eaa60d6'}
)
assert_raises(
NotFoundError, self.content_store.get_attr,
Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'),
'displayname'
)
assert_raises(
NotFoundError, self.content_store.set_attr,
Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'),
'displayname', 'hello'
)
assert_raises(
NotFoundError, self.content_store.get_attrs,
Location('bogus', 'bogus', 'bogus', 'asset', 'bogus')
)
assert_raises(
NotFoundError, self.content_store.set_attrs,
Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'),
{'displayname': 'hello'}
)
assert_raises(
NotFoundError, self.content_store.set_attrs,
Location('bogus', 'bogus', 'bogus', 'asset', None),
{'displayname': 'hello'}
)
示例2: export_all_for_course
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import _from_deprecated_son [as 别名]
def export_all_for_course(self, course_key, output_directory, assets_policy_file):
"""
Export all of this course's assets to the output_directory. Export all of the assets'
attributes to the policy file.
Args:
course_key (CourseKey): the :class:`CourseKey` identifying the course
output_directory: the directory under which to put all the asset files
assets_policy_file: the filename for the policy file which should be in the same
directory as the other policy files.
"""
policy = {}
assets, __ = self.get_all_content_for_course(course_key)
for asset in assets:
asset_location = AssetLocation._from_deprecated_son(asset['_id'], course_key.run) # pylint: disable=protected-access
# TODO: On 6/19/14, I had to put a try/except around this
# to export a course. The course failed on JSON files in
# the /static/ directory placed in it with an import.
#
# If this hasn't been looked at in a while, remove this comment.
#
# When debugging course exports, this might be a good place
# to look. -- pmitros
self.export(asset_location, output_directory)
for attr, value in asset.iteritems():
if attr not in ['_id', 'md5', 'uploadDate', 'length', 'chunkSize']:
policy.setdefault(asset_location.name, {})[attr] = value
with open(assets_policy_file, 'w') as f:
json.dump(policy, f)
示例3: _clear_assets
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import _from_deprecated_son [as 别名]
def _clear_assets(location):
"""
Clear all assets for location.
"""
store = contentstore()
assets, __ = store.get_all_content_for_course(location.course_key)
for asset in assets:
asset_location = AssetLocation._from_deprecated_son(asset["_id"], location.course_key.run)
del_cached_content(asset_location)
store.delete(asset_location)
示例4: export_all_for_course
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import _from_deprecated_son [as 别名]
def export_all_for_course(self, course_key, output_directory, assets_policy_file):
"""
Export all of this course's assets to the output_directory. Export all of the assets'
attributes to the policy file.
Args:
course_key (CourseKey): the :class:`CourseKey` identifying the course
output_directory: the directory under which to put all the asset files
assets_policy_file: the filename for the policy file which should be in the same
directory as the other policy files.
"""
policy = {}
assets, __ = self.get_all_content_for_course(course_key)
for asset in assets:
asset_location = AssetLocation._from_deprecated_son(asset['_id'], course_key.run) # pylint: disable=protected-access
self.export(asset_location, output_directory)
for attr, value in asset.iteritems():
if attr not in ['_id', 'md5', 'uploadDate', 'length', 'chunkSize']:
policy.setdefault(asset_location.name, {})[attr] = value
with open(assets_policy_file, 'w') as f:
json.dump(policy, f)
示例5: test_contentstore_attrs
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import _from_deprecated_son [as 别名]
def test_contentstore_attrs(self):
"""
Test getting, setting, and defaulting the locked attr and arbitrary attrs.
"""
location = Location("edX", "toy", "2012_Fall", "course", "2012_Fall")
course_content, __ = self.content_store.get_all_content_for_course(location.course_key)
assert_true(len(course_content) > 0)
filter_params = _build_requested_filter("Images")
filtered_course_content, __ = self.content_store.get_all_content_for_course(
location.course_key, filter_params=filter_params
)
assert_true(len(filtered_course_content) < len(course_content))
# a bit overkill, could just do for content[0]
for content in course_content:
assert not content.get("locked", False)
asset_key = AssetLocation._from_deprecated_son(content.get("content_son", content["_id"]), location.run)
assert not self.content_store.get_attr(asset_key, "locked", False)
attrs = self.content_store.get_attrs(asset_key)
assert_in("uploadDate", attrs)
assert not attrs.get("locked", False)
self.content_store.set_attr(asset_key, "locked", True)
assert self.content_store.get_attr(asset_key, "locked", False)
attrs = self.content_store.get_attrs(asset_key)
assert_in("locked", attrs)
assert attrs["locked"] is True
self.content_store.set_attrs(asset_key, {"miscel": 99})
assert_equals(self.content_store.get_attr(asset_key, "miscel"), 99)
asset_key = AssetLocation._from_deprecated_son(
course_content[0].get("content_son", course_content[0]["_id"]), location.run
)
assert_raises(AttributeError, self.content_store.set_attr, asset_key, "md5", "ff1532598830e3feac91c2449eaa60d6")
assert_raises(
AttributeError,
self.content_store.set_attrs,
asset_key,
{"foo": 9, "md5": "ff1532598830e3feac91c2449eaa60d6"},
)
assert_raises(
NotFoundError,
self.content_store.get_attr,
Location("bogus", "bogus", "bogus", "asset", "bogus"),
"displayname",
)
assert_raises(
NotFoundError,
self.content_store.set_attr,
Location("bogus", "bogus", "bogus", "asset", "bogus"),
"displayname",
"hello",
)
assert_raises(
NotFoundError, self.content_store.get_attrs, Location("bogus", "bogus", "bogus", "asset", "bogus")
)
assert_raises(
NotFoundError,
self.content_store.set_attrs,
Location("bogus", "bogus", "bogus", "asset", "bogus"),
{"displayname": "hello"},
)
assert_raises(
NotFoundError,
self.content_store.set_attrs,
Location("bogus", "bogus", "bogus", "asset", None),
{"displayname": "hello"},
)