本文整理汇总了Python中opaque_keys.edx.locations.AssetLocation.from_deprecated_string方法的典型用法代码示例。如果您正苦于以下问题:Python AssetLocation.from_deprecated_string方法的具体用法?Python AssetLocation.from_deprecated_string怎么用?Python AssetLocation.from_deprecated_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opaque_keys.edx.locations.AssetLocation
的用法示例。
在下文中一共展示了AssetLocation.from_deprecated_string方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_can_delete_certificate_with_signatories
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_deprecated_string [as 别名]
def test_can_delete_certificate_with_signatories(self):
"""
Delete certificate
"""
self._add_course_certificates(count=2, signatory_count=1)
certificates = self.course.certificates["certificates"]
org_logo_url = certificates[1]["org_logo_path"]
image_asset_location = AssetLocation.from_deprecated_string(org_logo_url)
content = contentstore().find(image_asset_location)
self.assertIsNotNone(content)
response = self.client.delete(
self._url(cid=1),
content_type="application/json",
HTTP_ACCEPT="application/json",
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
)
self.assertEqual(response.status_code, 204)
self.assert_event_emitted(
"edx.certificate.configuration.deleted", course_id=unicode(self.course.id), configuration_id="1"
)
self.reload_course()
# Verify that certificates are properly updated in the course.
certificates = self.course.certificates["certificates"]
self.assertEqual(len(certificates), 1)
# make sure certificate org logo is deleted too
self.assertRaises(NotFoundError, contentstore().find, image_asset_location)
self.assertEqual(certificates[0].get("name"), "Name 0")
self.assertEqual(certificates[0].get("description"), "Description 0")
示例2: test_can_delete_signatory
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_deprecated_string [as 别名]
def test_can_delete_signatory(self):
"""
Delete an existing certificate signatory
"""
self._add_course_certificates(count=2, signatory_count=3)
certificates = self.course.certificates["certificates"]
signatory = certificates[1].get("signatories")[1]
image_asset_location = AssetLocation.from_deprecated_string(signatory["signature_image_path"])
content = contentstore().find(image_asset_location)
self.assertIsNotNone(content)
test_url = "{}/signatories/1".format(self._url(cid=1))
response = self.client.delete(
test_url,
content_type="application/json",
HTTP_ACCEPT="application/json",
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
)
self.assertEqual(response.status_code, 204)
self.reload_course()
# Verify that certificates are properly updated in the course.
certificates = self.course.certificates["certificates"]
self.assertEqual(len(certificates[1].get("signatories")), 2)
# make sure signatory signature image is deleted too
self.assertRaises(NotFoundError, contentstore().find, image_asset_location)
示例3: test_delete_image_type_asset
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_deprecated_string [as 别名]
def test_delete_image_type_asset(self):
""" Tests deletion of image type asset """
image_asset = self.get_sample_asset(self.asset_name, asset_type="image")
thumbnail_image_asset = self.get_sample_asset('delete_test_thumbnail', asset_type="image")
# upload image
response = self.client.post(self.url, {"name": "delete_image_test", "file": image_asset})
self.assertEquals(response.status_code, 200)
uploaded_image_url = json.loads(response.content)['asset']['url']
# upload image thumbnail
response = self.client.post(self.url, {"name": "delete_image_thumb_test", "file": thumbnail_image_asset})
self.assertEquals(response.status_code, 200)
thumbnail_url = json.loads(response.content)['asset']['url']
thumbnail_location = StaticContent.get_location_from_path(thumbnail_url)
image_asset_location = AssetLocation.from_deprecated_string(uploaded_image_url)
content = contentstore().find(image_asset_location)
content.thumbnail_location = thumbnail_location
contentstore().save(content)
with mock.patch('opaque_keys.edx.locator.CourseLocator.make_asset_key') as mock_asset_key:
mock_asset_key.return_value = thumbnail_location
test_url = reverse_course_url(
'assets_handler', self.course.id, kwargs={'asset_key_string': unicode(uploaded_image_url)})
resp = self.client.delete(test_url, HTTP_ACCEPT="application/json")
self.assertEquals(resp.status_code, 204)
示例4: test_static_import
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_deprecated_string [as 别名]
def test_static_import(self):
'''
Stuff in static_import should always be imported into contentstore
'''
_, content_store, course = self.load_test_import_course()
# make sure we have ONE asset in our contentstore ("should_be_imported.html")
all_assets, count = content_store.get_all_content_for_course(course.id)
print "len(all_assets)=%d" % len(all_assets)
self.assertEqual(len(all_assets), 1)
self.assertEqual(count, 1)
content = None
try:
location = AssetLocation.from_deprecated_string(
'/c4x/edX/test_import_course/asset/should_be_imported.html'
)
content = content_store.find(location)
except NotFoundError:
pass
self.assertIsNotNone(content)
# make sure course.static_asset_path is correct
print "static_asset_path = {0}".format(course.static_asset_path)
self.assertEqual(course.static_asset_path, 'test_import_course')
示例5: get_location_from_path
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_deprecated_string [as 别名]
def get_location_from_path(path):
"""
Generate an AssetKey for the given path (old c4x/org/course/asset/name syntax)
"""
# TODO OpaqueKeys after opaque keys deprecation is working
# return AssetLocation.from_string(path)
return AssetLocation.from_deprecated_string(path)
示例6: setUp
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_deprecated_string [as 别名]
def setUp(self):
""" Scaffolding """
super(DeleteAssetTestCase, self).setUp()
self.url = reverse_course_url('assets_handler', self.course.id)
# First, upload something.
self.asset_name = 'delete_test'
self.asset = self.get_sample_asset(self.asset_name)
response = self.client.post(self.url, {"name": self.asset_name, "file": self.asset})
self.assertEquals(response.status_code, 200)
self.uploaded_url = json.loads(response.content)['asset']['url']
self.asset_location = AssetLocation.from_deprecated_string(self.uploaded_url)
self.content = contentstore().find(self.asset_location)
示例7: test_pdf_asset
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_deprecated_string [as 别名]
def test_pdf_asset(self):
module_store = modulestore()
course_items = import_course_from_xml(
module_store, self.user.id, TEST_DATA_DIR, ["toy"], static_content_store=contentstore(), verbose=True
)
course = course_items[0]
url = reverse_course_url("assets_handler", course.id)
# Test valid contentType for pdf asset (textbook.pdf)
resp = self.client.get(url, HTTP_ACCEPT="application/json")
self.assertContains(resp, "/c4x/edX/toy/asset/textbook.pdf")
asset_location = AssetLocation.from_deprecated_string("/c4x/edX/toy/asset/textbook.pdf")
content = contentstore().find(asset_location)
# Check after import textbook.pdf has valid contentType ('application/pdf')
# Note: Actual contentType for textbook.pdf in asset.json is 'text/pdf'
self.assertEqual(content.content_type, "application/pdf")
示例8: test_get_all_content
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_deprecated_string [as 别名]
def test_get_all_content(self, deprecated):
"""
Test get_all_content_for_course
"""
self.set_up_assets(deprecated)
course1_assets, count = self.contentstore.get_all_content_for_course(self.course1_key)
self.assertEqual(count, len(self.course1_files), course1_assets)
for asset in course1_assets:
parsed = AssetLocation.from_deprecated_string(asset['filename'])
self.assertIn(parsed.name, self.course1_files)
course1_assets, __ = self.contentstore.get_all_content_for_course(self.course1_key, 1, 1)
self.assertEqual(len(course1_assets), 1, course1_assets)
fake_course = SlashSeparatedCourseKey('test', 'fake', 'non')
course_assets, count = self.contentstore.get_all_content_for_course(fake_course)
self.assertEqual(count, 0)
self.assertEqual(course_assets, [])
示例9: test_pdf_asset
# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_deprecated_string [as 别名]
def test_pdf_asset(self):
module_store = modulestore('direct')
_, course_items = import_from_xml(
module_store,
'common/test/data/',
['toy'],
static_content_store=contentstore(),
verbose=True
)
course = course_items[0]
url = reverse_course_url('assets_handler', course.id)
# Test valid contentType for pdf asset (textbook.pdf)
resp = self.client.get(url, HTTP_ACCEPT='application/json')
self.assertContains(resp, "/c4x/edX/toy/asset/textbook.pdf")
asset_location = AssetLocation.from_deprecated_string('/c4x/edX/toy/asset/textbook.pdf')
content = contentstore().find(asset_location)
# Check after import textbook.pdf has valid contentType ('application/pdf')
# Note: Actual contentType for textbook.pdf in asset.json is 'text/pdf'
self.assertEqual(content.content_type, 'application/pdf')