diff --git a/django/test/client.py b/django/test/client.py index a755aae05c..85d91b0c44 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -947,9 +947,7 @@ class ClientMixin: 'Content-Type header is "%s", not "application/json"' % response.get("Content-Type") ) - response._json = json.loads( - response.content.decode(response.charset), **extra - ) + response._json = json.loads(response.text, **extra) return response._json def _follow_redirect( diff --git a/tests/admin_views/test_autocomplete_view.py b/tests/admin_views/test_autocomplete_view.py index dc3789fc5b..d9595cdb28 100644 --- a/tests/admin_views/test_autocomplete_view.py +++ b/tests/admin_views/test_autocomplete_view.py @@ -102,7 +102,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): request.user = self.superuser response = AutocompleteJsonView.as_view(**self.as_view_args)(request) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual( data, { @@ -120,7 +120,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): request.user = self.superuser response = AutocompleteJsonView.as_view(**self.as_view_args)(request) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual( data, { @@ -150,7 +150,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): request.user = self.superuser response = AutocompleteJsonView.as_view(**self.as_view_args)(request) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual( data, { @@ -184,7 +184,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): request.user = self.superuser response = AutocompleteJsonView.as_view(**self.as_view_args)(request) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual( data, { @@ -205,7 +205,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): request.user = self.superuser response = AutocompleteJsonView.as_view(**self.as_view_args)(request) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual( data, { @@ -250,7 +250,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): request.user = self.superuser response = AutocompleteJsonView.as_view(**self.as_view_args)(request) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual( data, { @@ -306,7 +306,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): with model_admin(Question, DistinctQuestionAdmin): response = AutocompleteJsonView.as_view(**self.as_view_args)(request) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual(len(data["results"]), 3) def test_missing_search_fields(self): @@ -335,7 +335,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): with model_admin(Question, PKOrderingQuestionAdmin): response = AutocompleteJsonView.as_view(**self.as_view_args)(request) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual( data, { @@ -352,7 +352,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): with model_admin(Question, PKOrderingQuestionAdmin): response = AutocompleteJsonView.as_view(**self.as_view_args)(request) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual( data, { @@ -380,7 +380,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase): request ) self.assertEqual(response.status_code, 200) - data = json.loads(response.content.decode("utf-8")) + data = json.loads(response.text) self.assertEqual( data, { diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index f63a9ca56f..17174ff5e0 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -296,9 +296,7 @@ class AdminViewBasicTestCase(TestCase): self.assertLess( response.content.index(text1.encode()), response.content.index(text2.encode()), - (failing_msg or "") - + "\nResponse:\n" - + response.content.decode(response.charset), + (failing_msg or "") + "\nResponse:\n" + response.text, ) @@ -3603,7 +3601,7 @@ class AdminViewDeletedObjectsTest(TestCase): response = self.client.get( reverse("admin:admin_views_villain_delete", args=(self.v1.pk,)) ) - self.assertRegex(response.content.decode(), pattern) + self.assertRegex(response.text, pattern) def test_cyclic(self): """ @@ -8266,7 +8264,7 @@ class AdminKeepChangeListFiltersTests(TestCase): # Check the `change_view` link has the correct querystring. detail_link = re.search( '{}'.format(self.joepublicuser.username), - response.content.decode(), + response.text, ) self.assertURLEqual(detail_link[1], self.get_change_url()) @@ -8278,7 +8276,7 @@ class AdminKeepChangeListFiltersTests(TestCase): # Check the form action. form_action = re.search( '