Unverified Commit 08ca2110 by Awais Jibran Committed by GitHub

Merge pull request #16782 from edx/aj/fix-unicode-error

Handle Unicode chars with AlreadyRunningError exception
parents 571be1f5 4431cec4
...@@ -252,6 +252,14 @@ def view_alreadyrunningerror(request): # pylint: disable=unused-argument ...@@ -252,6 +252,14 @@ def view_alreadyrunningerror(request): # pylint: disable=unused-argument
@common_exceptions_400 @common_exceptions_400
def view_alreadyrunningerror_unicode(request): # pylint: disable=unused-argument
"""
A dummy view that raises an AlreadyRunningError exception with unicode message
"""
raise AlreadyRunningError(u'Text with unicode chárácters')
@common_exceptions_400
def view_queue_connection_error(request): # pylint: disable=unused-argument def view_queue_connection_error(request): # pylint: disable=unused-argument
""" """
A dummy view that raises a QueueConnectionError exception. A dummy view that raises a QueueConnectionError exception.
...@@ -287,17 +295,19 @@ class TestCommonExceptions400(TestCase): ...@@ -287,17 +295,19 @@ class TestCommonExceptions400(TestCase):
self.assertEqual(resp.status_code, 400) self.assertEqual(resp.status_code, 400)
self.assertIn("User does not exist", resp.content) self.assertIn("User does not exist", resp.content)
def test_alreadyrunningerror(self): @ddt.data(True, False)
self.request.is_ajax.return_value = False def test_alreadyrunningerror(self, is_ajax):
self.request.is_ajax.return_value = is_ajax
resp = view_alreadyrunningerror(self.request) # pylint: disable=assignment-from-no-return resp = view_alreadyrunningerror(self.request) # pylint: disable=assignment-from-no-return
self.assertEqual(resp.status_code, 400) self.assertEqual(resp.status_code, 400)
self.assertIn("Requested task is already running", resp.content) self.assertIn("Requested task is already running", resp.content)
def test_alreadyrunningerror_ajax(self): @ddt.data(True, False)
self.request.is_ajax.return_value = True def test_alreadyrunningerror_with_unicode(self, is_ajax):
resp = view_alreadyrunningerror(self.request) # pylint: disable=assignment-from-no-return self.request.is_ajax.return_value = is_ajax
resp = view_alreadyrunningerror_unicode(self.request) # pylint: disable=assignment-from-no-return
self.assertEqual(resp.status_code, 400) self.assertEqual(resp.status_code, 400)
self.assertIn("Requested task is already running", resp.content) self.assertIn('Text with unicode chárácters', resp.content)
@ddt.data(True, False) @ddt.data(True, False)
def test_queue_connection_error(self, is_ajax): def test_queue_connection_error(self, is_ajax):
......
...@@ -150,7 +150,7 @@ def common_exceptions_400(func): ...@@ -150,7 +150,7 @@ def common_exceptions_400(func):
except User.DoesNotExist: except User.DoesNotExist:
message = _('User does not exist.') message = _('User does not exist.')
except (AlreadyRunningError, QueueConnectionError) as err: except (AlreadyRunningError, QueueConnectionError) as err:
message = str(err) message = unicode(err)
if use_json: if use_json:
return JsonResponseBadRequest(message) return JsonResponseBadRequest(message)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment