Merge pull request #16159 from edx/ri/EDUCATOR-139-add-charset-webOb-response
EDUCATOR-139 Add charset to the WebOb response
This commit is contained in:
@@ -363,6 +363,7 @@ class TestStudioView(XBlockWrapperTestMixin, TestCase):
|
||||
self.assertEqual(html, rendered_content)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestXModuleHandler(TestCase):
|
||||
"""
|
||||
Tests that the xmodule_handler function correctly wraps handle_ajax
|
||||
@@ -387,6 +388,21 @@ class TestXModuleHandler(TestCase):
|
||||
self.assertIsInstance(response, webob.Response)
|
||||
self.assertEqual(response.body, '{}')
|
||||
|
||||
@ddt.data(
|
||||
u'{"test_key": "test_value"}',
|
||||
'{"test_key": "test_value"}',
|
||||
)
|
||||
def test_xmodule_handler_with_data(self, response_data):
|
||||
"""
|
||||
Tests that xmodule_handler function correctly wraps handle_ajax when handle_ajax response is either
|
||||
str or unicode.
|
||||
"""
|
||||
|
||||
self.module.handle_ajax = Mock(return_value=response_data)
|
||||
response = self.module.xmodule_handler(self.request)
|
||||
self.assertIsInstance(response, webob.Response)
|
||||
self.assertEqual(response.body, '{"test_key": "test_value"}')
|
||||
|
||||
|
||||
class TestXmlExport(XBlockWrapperTestMixin, TestCase):
|
||||
"""
|
||||
|
||||
@@ -881,21 +881,7 @@ class XModule(HTMLSnippet, XModuleMixin):
|
||||
request_post[key] = map(FileObjForWebobFiles, request.POST.getall(key))
|
||||
|
||||
response_data = self.handle_ajax(suffix, request_post)
|
||||
|
||||
try:
|
||||
return Response(response_data, content_type='application/json')
|
||||
except TypeError:
|
||||
request_environ = getattr(request, 'environ')
|
||||
log.exception(
|
||||
'Response creation failed for problem url: %s, response_data type: %s, LANG: %s, '
|
||||
'LC_ALL: %s and HTTP_ACCEPT_ENCODING: %s',
|
||||
request_environ.get('HTTP_REFERER'),
|
||||
type(response_data),
|
||||
request_environ.get('LANG'),
|
||||
request_environ.get('LC_ALL'),
|
||||
request_environ.get('HTTP_ACCEPT_ENCODING')
|
||||
)
|
||||
raise
|
||||
return Response(response_data, content_type='application/json', charset='UTF-8')
|
||||
|
||||
def get_child(self, usage_id):
|
||||
if usage_id in self._child_cache:
|
||||
|
||||
Reference in New Issue
Block a user