Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cms/djangoapps/contentstore/tests/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def test_toy_assets(self):
self.assertContains(resp, "new AssetCollection([{")
self.assertContains(resp, "/c4x/edX/toy/asset/handouts_sample_handout.txt")

# 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):
"""
Expand Down
10 changes: 6 additions & 4 deletions common/lib/xmodule/xmodule/modulestore/xml_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions common/test/data/toy/policies/assets.json
Original file line number Diff line number Diff line change
@@ -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
}
}
Binary file added common/test/data/toy/static/textbook.pdf
Binary file not shown.