BOM-618 Decode to utf-8 before loading as json in tests.

This commit is contained in:
Feanil Patel
2019-09-19 11:15:06 -04:00
parent 3a83760909
commit cbf35593ac
4 changed files with 16 additions and 10 deletions

View File

@@ -76,7 +76,7 @@ class ResetPasswordTests(EventTestMixin, CacheIsolationTestCase):
bad_pwd_resp = password_reset(bad_pwd_req)
# If they've got an unusable password, we return a successful response code
self.assertEquals(bad_pwd_resp.status_code, 200)
obj = json.loads(bad_pwd_resp.content)
obj = json.loads(bad_pwd_resp.content.decode('utf-8'))
self.assertEquals(obj, {
'success': True,
'value': "('registration/password_reset_done.html', [])",
@@ -95,7 +95,7 @@ class ResetPasswordTests(EventTestMixin, CacheIsolationTestCase):
# This prevents someone potentially trying to "brute-force" find out which
# emails are and aren't registered with edX
self.assertEquals(bad_email_resp.status_code, 200)
obj = json.loads(bad_email_resp.content)
obj = json.loads(bad_email_resp.content.decode('utf-8'))
self.assertEquals(obj, {
'success': True,
'value': "('registration/password_reset_done.html', [])",
@@ -145,7 +145,7 @@ class ResetPasswordTests(EventTestMixin, CacheIsolationTestCase):
self.assertFalse(dop_models.RefreshToken.objects.filter(user=self.user).exists())
self.assertFalse(dot_models.AccessToken.objects.filter(user=self.user).exists())
self.assertFalse(dot_models.RefreshToken.objects.filter(user=self.user).exists())
obj = json.loads(good_resp.content)
obj = json.loads(good_resp.content.decode('utf-8'))
self.assertTrue(obj['success'])
self.assertIn('e-mailed you instructions for setting your password', obj['value'])

View File

@@ -46,7 +46,7 @@ class ApiAccessRequestViewTests(TestCase):
"""
Assert API response on `API Access Request` endpoint.
"""
json_content = json.loads(api_response.content)
json_content = json.loads(api_response.content.decode('utf-8'))
self.assertEqual(api_response.status_code, 200)
self.assertEqual(json_content['count'], expected_results_count)

View File

@@ -547,8 +547,12 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
def test_enrollment_already_enrolled(self):
response = self.assert_enrollment_status()
response_json = json.loads(response.content.decode('utf-8'))
repeat_response = self.assert_enrollment_status(expected_status=status.HTTP_200_OK)
self.assertEqual(json.loads(response.content.decode('utf-8')), json.loads(repeat_response.content))
repeat_json = json.loads(repeat_response.content.decode('utf-8'))
self.assertEqual(response_json, repeat_json)
def test_get_enrollment_with_invalid_key(self):
resp = self.client.post(
@@ -562,7 +566,7 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
format='json'
)
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn("No course ", resp.content)
self.assertIn("No course ", resp.content.decode('utf-8'))
def test_enrollment_throttle_for_user(self):
"""Make sure a user requests do not exceed the maximum number of requests"""
@@ -655,7 +659,7 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
),
{'include_expired': True},
)
v_data = json.loads(v_response.content)
v_data = json.loads(v_response.content.decode('utf-8'))
# Ensure that both course modes are returned
self.assertEqual(len(v_data['course_modes']), 2)
@@ -664,7 +668,7 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
h_response = self.client.get(
reverse('courseenrollmentdetails', kwargs={"course_id": six.text_type(self.course.id)}),
)
h_data = json.loads(h_response.content)
h_data = json.loads(h_response.content.decode('utf-8'))
# Ensure that only one course mode is returned and that it is honor
self.assertEqual(len(h_data['course_modes']), 1)

View File

@@ -109,7 +109,8 @@ class AwardProgramCertificateTestCase(TestCase):
}
]
}
self.assertEqual(json.loads(httpretty.last_request().body), expected_body)
last_request_body = httpretty.last_request().body.decode('utf-8')
self.assertEqual(json.loads(last_request_body), expected_body)
@skip_unless_lms
@@ -471,7 +472,8 @@ class PostCourseCertificateTestCase(TestCase):
'value': visible_date.strftime('%Y-%m-%dT%H:%M:%SZ') # text representation of date
}]
}
self.assertEqual(json.loads(httpretty.last_request().body), expected_body)
last_request_body = httpretty.last_request().body.decode('utf-8')
self.assertEqual(json.loads(last_request_body), expected_body)
@skip_unless_lms