Merge pull request #2075 from zubair-arbi/zub/bugfix/std878-wrongcontenttype
Assign valid content_type to static resource (import_static_content)
This commit is contained in:
@@ -68,6 +68,14 @@ class AssetsToyCourseTestCase(CourseTestCase):
|
||||
self.assertEquals(len(assets), expected_length)
|
||||
self.assertEquals(json_response['totalCount'], expected_total)
|
||||
|
||||
# Test valid contentType for pdf asset (textbook.pdf)
|
||||
self.assertContains(resp, "/c4x/edX/toy/asset/textbook.pdf")
|
||||
asset_location = StaticContent.get_location_from_path('/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')
|
||||
|
||||
|
||||
class UploadTestCase(CourseTestCase):
|
||||
"""
|
||||
|
||||
@@ -33,6 +33,7 @@ def import_static_content(
|
||||
policy = {}
|
||||
|
||||
verbose = True
|
||||
mimetypes_list = mimetypes.types_map.values()
|
||||
|
||||
for dirname, _, filenames in os.walk(static_dir):
|
||||
for filename in filenames:
|
||||
@@ -64,10 +65,11 @@ def import_static_content(
|
||||
policy_ele = policy.get(content_loc.name, {})
|
||||
displayname = policy_ele.get('displayname', filename)
|
||||
locked = policy_ele.get('locked', False)
|
||||
mime_type = policy_ele.get(
|
||||
'contentType',
|
||||
mimetypes.guess_type(filename)[0]
|
||||
)
|
||||
mime_type = policy_ele.get('contentType')
|
||||
|
||||
# Check extracted contentType in list of all valid mimetypes
|
||||
if not mime_type or mime_type not in mimetypes_list:
|
||||
mime_type = mimetypes.guess_type(filename)[0] # Assign guessed mimetype
|
||||
content = StaticContent(
|
||||
content_loc, displayname, mime_type, data,
|
||||
import_path=fullname_with_subpath, locked=locked
|
||||
|
||||
10
common/test/data/toy/policies/assets.json
Normal file
10
common/test/data/toy/policies/assets.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"textbook.pdf":{
|
||||
"contentType":"text/pdf",
|
||||
"displayname":"textbook.pdf",
|
||||
"locked":false,
|
||||
"filename":"/c4x/edx/toy/asset/textbook.pdf",
|
||||
"import_path":null,
|
||||
"thumbnail_location":null
|
||||
}
|
||||
}
|
||||
BIN
common/test/data/toy/static/textbook.pdf
Normal file
BIN
common/test/data/toy/static/textbook.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user