BOM-617 Fix test_static_replace test failures.
Update the tests around static_file code to use byte streams instead of string streams for generating static content. This is a fix to get these tests passing on python 3.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import re
|
||||
from six import StringIO
|
||||
from six import BytesIO
|
||||
from six.moves.urllib.parse import parse_qsl, urlparse, urlunparse
|
||||
|
||||
import ddt
|
||||
@@ -331,7 +331,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase):
|
||||
StaticContent: the StaticContent object for the created image
|
||||
"""
|
||||
new_image = Image.new('RGB', dimensions, color)
|
||||
new_buf = StringIO()
|
||||
new_buf = BytesIO()
|
||||
new_image.save(new_buf, format='png')
|
||||
new_buf.seek(0)
|
||||
new_name = name.format(prefix)
|
||||
@@ -355,7 +355,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase):
|
||||
StaticContent: the StaticContent object for the created content
|
||||
|
||||
"""
|
||||
new_buf = StringIO('testingggggggggggg')
|
||||
new_buf = BytesIO(b'testingggggggggggg')
|
||||
new_name = name.format(prefix)
|
||||
new_key = StaticContent.compute_location(cls.courses[prefix].id, new_name)
|
||||
new_content = StaticContent(new_key, new_name, 'application/octet-stream', new_buf.getvalue(), locked=locked)
|
||||
|
||||
@@ -270,7 +270,7 @@ class StaticContent(object):
|
||||
if query_val.startswith("/static/"):
|
||||
new_val = StaticContent.get_canonicalized_asset_path(
|
||||
course_key, query_val, base_url, excluded_exts, encode=False)
|
||||
updated_query_params.append((query_name, new_val))
|
||||
updated_query_params.append((query_name, new_val.encode('utf-8')))
|
||||
else:
|
||||
# Make sure we're encoding Unicode strings down to their byte string
|
||||
# representation so that `urlencode` can handle it.
|
||||
@@ -286,11 +286,11 @@ class StaticContent(object):
|
||||
|
||||
# Only encode this if told to. Important so that we don't double encode
|
||||
# when working with paths that are in query parameters.
|
||||
asset_path = asset_path.encode('utf-8')
|
||||
if encode:
|
||||
asset_path = asset_path.encode('utf-8')
|
||||
asset_path = quote_plus(asset_path, '/:+@')
|
||||
|
||||
return urlunparse(('', base_url.encode('utf-8'), asset_path, params, urlencode(updated_query_params), ''))
|
||||
return urlunparse(('', base_url, asset_path, params, urlencode(updated_query_params), ''))
|
||||
|
||||
def stream_data(self):
|
||||
yield self._data
|
||||
|
||||
@@ -99,7 +99,9 @@ class MongoContentStore(ContentStore):
|
||||
import_path=content.import_path,
|
||||
# getattr b/c caching may mean some pickled instances don't have attr
|
||||
locked=getattr(content, 'locked', False)) as fp:
|
||||
if hasattr(content.data, '__iter__'):
|
||||
# It seems that this code thought that only some specific object would have the `__iter__` attribute
|
||||
# but the bytes object in python 3 has one and should not use the chunking logic.
|
||||
if hasattr(content.data, '__iter__') and not isinstance(content.data, six.binary_type):
|
||||
for chunk in content.data:
|
||||
fp.write(chunk)
|
||||
else:
|
||||
|
||||
@@ -1298,7 +1298,8 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite):
|
||||
result = defaultdict(dict)
|
||||
if fields is None:
|
||||
return result
|
||||
cls = self.mixologist.mix(XBlock.load_class(category, select=prefer_xmodules))
|
||||
classes = XBlock.load_class(category, select=prefer_xmodules)
|
||||
cls = self.mixologist.mix(classes)
|
||||
for field_name, value in six.iteritems(fields):
|
||||
field = getattr(cls, field_name)
|
||||
result[field.scope][field_name] = value
|
||||
|
||||
Reference in New Issue
Block a user