From 3427c1abf36f274f24efeee33d6ad5b034d62c3f Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Wed, 18 Sep 2019 16:26:55 -0400 Subject: [PATCH] BOM-618 Pass unicode to json.loads --- lms/djangoapps/courseware/tests/test_video_handlers.py | 2 +- lms/djangoapps/courseware/tests/test_word_cloud.py | 2 +- lms/djangoapps/verify_student/tests/test_views.py | 4 ++-- lms/djangoapps/verify_student/views.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index 6853d078b8..249ecfb54c 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -973,7 +973,7 @@ class TestStudioTranscriptTranslationPostDispatch(TestVideo): request = Request.blank('/translation', POST=post_data) response = self.item_descriptor.studio_transcript(request=request, dispatch='translation') self.assertEqual(response.status, '201 Created') - response = json.loads(response.body) + response = json.loads(response.text) self.assertTrue(response["language_code"], "uk") self.assertDictEqual(self.item_descriptor.transcripts, {}) self.assertTrue(edxval_api.get_video_transcript_data(video_id=response["edx_video_id"], language_code="uk")) diff --git a/lms/djangoapps/courseware/tests/test_word_cloud.py b/lms/djangoapps/courseware/tests/test_word_cloud.py index 5e91234cdf..709895568a 100644 --- a/lms/djangoapps/courseware/tests/test_word_cloud.py +++ b/lms/djangoapps/courseware/tests/test_word_cloud.py @@ -243,7 +243,7 @@ class TestWordCloud(BaseTestXmodule): for user in self.users: self.assertDictEqual( - json.loads(responses[user.username].content), + json.loads(responses[user.username].content.decode('utf-8')), { 'status': 'fail', 'error': 'Unknown Command!' diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index ca70b38786..4e51ad86af 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -1298,7 +1298,7 @@ class TestCheckoutWithEcommerceService(ModuleStoreTestCase): self.assertTrue(mock_audit_log.called) # Check the api call - self.assertEqual(json.loads(httpretty.last_request().body), { + self.assertEqual(json.loads(httpretty.last_request().body.decode('utf-8')), { 'products': [{'sku': 'test-sku'}], 'checkout': True, 'payment_processor_name': 'test-processor', @@ -1845,7 +1845,7 @@ class TestPhotoVerificationResultsCallback(ModuleStoreTestCase): self.assertEqual(attempt.status, u'denied') self.assertEqual(attempt.error_code, u'Your photo doesn\'t meet standards.') self.assertEqual(attempt.error_msg, u'[{"photoIdReasons": ["Not provided"]}]') - self.assertEquals(response.content, 'OK!') + self.assertEquals(response.content.decode('utf-8'), 'OK!') self.assertEqual(len(mail.outbox), 1) @patch( diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 9dec48b2f8..28cdf2e8ab 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -1113,7 +1113,7 @@ def results_callback(request): body = request.body try: - body_dict = json.loads(body) + body_dict = json.loads(body.decode('utf-8')) except ValueError: log.exception(u"Invalid JSON received from Software Secure:\n\n{}\n".format(body)) return HttpResponseBadRequest(u"Invalid JSON. Received:\n\n{}".format(body))