1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Refs #35727 -- Updated response.content.decode calls to use the HttpResponse.text property.

Signed-off-by: SaJH <wogur981208@gmail.com>
This commit is contained in:
SaJH 2024-10-16 01:11:46 +09:00 committed by Sarah Boyce
parent 4a685bc0dc
commit 0c81775515
12 changed files with 63 additions and 65 deletions

View File

@ -947,9 +947,7 @@ class ClientMixin:
'Content-Type header is "%s", not "application/json"' 'Content-Type header is "%s", not "application/json"'
% response.get("Content-Type") % response.get("Content-Type")
) )
response._json = json.loads( response._json = json.loads(response.text, **extra)
response.content.decode(response.charset), **extra
)
return response._json return response._json
def _follow_redirect( def _follow_redirect(

View File

@ -102,7 +102,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
request.user = self.superuser request.user = self.superuser
response = AutocompleteJsonView.as_view(**self.as_view_args)(request) response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode("utf-8")) data = json.loads(response.text)
self.assertEqual( self.assertEqual(
data, data,
{ {
@ -120,7 +120,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
request.user = self.superuser request.user = self.superuser
response = AutocompleteJsonView.as_view(**self.as_view_args)(request) response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode("utf-8")) data = json.loads(response.text)
self.assertEqual( self.assertEqual(
data, data,
{ {
@ -150,7 +150,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
request.user = self.superuser request.user = self.superuser
response = AutocompleteJsonView.as_view(**self.as_view_args)(request) response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode("utf-8")) data = json.loads(response.text)
self.assertEqual( self.assertEqual(
data, data,
{ {
@ -184,7 +184,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
request.user = self.superuser request.user = self.superuser
response = AutocompleteJsonView.as_view(**self.as_view_args)(request) response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode("utf-8")) data = json.loads(response.text)
self.assertEqual( self.assertEqual(
data, data,
{ {
@ -205,7 +205,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
request.user = self.superuser request.user = self.superuser
response = AutocompleteJsonView.as_view(**self.as_view_args)(request) response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode("utf-8")) data = json.loads(response.text)
self.assertEqual( self.assertEqual(
data, data,
{ {
@ -250,7 +250,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
request.user = self.superuser request.user = self.superuser
response = AutocompleteJsonView.as_view(**self.as_view_args)(request) response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode("utf-8")) data = json.loads(response.text)
self.assertEqual( self.assertEqual(
data, data,
{ {
@ -306,7 +306,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
with model_admin(Question, DistinctQuestionAdmin): with model_admin(Question, DistinctQuestionAdmin):
response = AutocompleteJsonView.as_view(**self.as_view_args)(request) response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
self.assertEqual(response.status_code, 200) 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) self.assertEqual(len(data["results"]), 3)
def test_missing_search_fields(self): def test_missing_search_fields(self):
@ -335,7 +335,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
with model_admin(Question, PKOrderingQuestionAdmin): with model_admin(Question, PKOrderingQuestionAdmin):
response = AutocompleteJsonView.as_view(**self.as_view_args)(request) response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode("utf-8")) data = json.loads(response.text)
self.assertEqual( self.assertEqual(
data, data,
{ {
@ -352,7 +352,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
with model_admin(Question, PKOrderingQuestionAdmin): with model_admin(Question, PKOrderingQuestionAdmin):
response = AutocompleteJsonView.as_view(**self.as_view_args)(request) response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode("utf-8")) data = json.loads(response.text)
self.assertEqual( self.assertEqual(
data, data,
{ {
@ -380,7 +380,7 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
request request
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode("utf-8")) data = json.loads(response.text)
self.assertEqual( self.assertEqual(
data, data,
{ {

View File

@ -296,9 +296,7 @@ class AdminViewBasicTestCase(TestCase):
self.assertLess( self.assertLess(
response.content.index(text1.encode()), response.content.index(text1.encode()),
response.content.index(text2.encode()), response.content.index(text2.encode()),
(failing_msg or "") (failing_msg or "") + "\nResponse:\n" + response.text,
+ "\nResponse:\n"
+ response.content.decode(response.charset),
) )
@ -3603,7 +3601,7 @@ class AdminViewDeletedObjectsTest(TestCase):
response = self.client.get( response = self.client.get(
reverse("admin:admin_views_villain_delete", args=(self.v1.pk,)) 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): def test_cyclic(self):
""" """
@ -8266,7 +8264,7 @@ class AdminKeepChangeListFiltersTests(TestCase):
# Check the `change_view` link has the correct querystring. # Check the `change_view` link has the correct querystring.
detail_link = re.search( detail_link = re.search(
'<a href="(.*?)">{}</a>'.format(self.joepublicuser.username), '<a href="(.*?)">{}</a>'.format(self.joepublicuser.username),
response.content.decode(), response.text,
) )
self.assertURLEqual(detail_link[1], self.get_change_url()) self.assertURLEqual(detail_link[1], self.get_change_url())
@ -8278,7 +8276,7 @@ class AdminKeepChangeListFiltersTests(TestCase):
# Check the form action. # Check the form action.
form_action = re.search( form_action = re.search(
'<form action="(.*?)" method="post" id="user_form" novalidate>', '<form action="(.*?)" method="post" id="user_form" novalidate>',
response.content.decode(), response.text,
) )
self.assertURLEqual( self.assertURLEqual(
form_action[1], "?%s" % self.get_preserved_filters_querystring() form_action[1], "?%s" % self.get_preserved_filters_querystring()
@ -8286,13 +8284,13 @@ class AdminKeepChangeListFiltersTests(TestCase):
# Check the history link. # Check the history link.
history_link = re.search( history_link = re.search(
'<a href="(.*?)" class="historylink">History</a>', response.content.decode() '<a href="(.*?)" class="historylink">History</a>', response.text
) )
self.assertURLEqual(history_link[1], self.get_history_url()) self.assertURLEqual(history_link[1], self.get_history_url())
# Check the delete link. # Check the delete link.
delete_link = re.search( delete_link = re.search(
'<a href="(.*?)" class="deletelink">Delete</a>', response.content.decode() '<a href="(.*?)" class="deletelink">Delete</a>', response.text
) )
self.assertURLEqual(delete_link[1], self.get_delete_url()) self.assertURLEqual(delete_link[1], self.get_delete_url())
@ -8332,7 +8330,7 @@ class AdminKeepChangeListFiltersTests(TestCase):
self.client.force_login(viewuser) self.client.force_login(viewuser)
response = self.client.get(self.get_change_url()) response = self.client.get(self.get_change_url())
close_link = re.search( close_link = re.search(
'<a href="(.*?)" class="closelink">Close</a>', response.content.decode() '<a href="(.*?)" class="closelink">Close</a>', response.text
) )
close_link = close_link[1].replace("&amp;", "&") close_link = close_link[1].replace("&amp;", "&")
self.assertURLEqual(close_link, self.get_changelist_url()) self.assertURLEqual(close_link, self.get_changelist_url())
@ -8350,7 +8348,7 @@ class AdminKeepChangeListFiltersTests(TestCase):
# Check the form action. # Check the form action.
form_action = re.search( form_action = re.search(
'<form action="(.*?)" method="post" id="user_form" novalidate>', '<form action="(.*?)" method="post" id="user_form" novalidate>',
response.content.decode(), response.text,
) )
self.assertURLEqual( self.assertURLEqual(
form_action[1], "?%s" % self.get_preserved_filters_querystring() form_action[1], "?%s" % self.get_preserved_filters_querystring()

View File

@ -1521,7 +1521,7 @@ class ChangelistTests(MessagesTestMixin, AuthViewsTestCase):
# Test the link inside password field help_text. # Test the link inside password field help_text.
rel_link = re.search( rel_link = re.search(
r'<a class="button" href="([^"]*)">Reset password</a>', r'<a class="button" href="([^"]*)">Reset password</a>',
response.content.decode(), response.text,
)[1] )[1]
self.assertEqual(urljoin(user_change_url, rel_link), password_change_url) self.assertEqual(urljoin(user_change_url, rel_link), password_change_url)
@ -1617,7 +1617,7 @@ class ChangelistTests(MessagesTestMixin, AuthViewsTestCase):
# Test the link inside password field help_text. # Test the link inside password field help_text.
rel_link = re.search( rel_link = re.search(
r'<a class="button" href="([^"]*)">Set password</a>', r'<a class="button" href="([^"]*)">Set password</a>',
response.content.decode(), response.text,
)[1] )[1]
self.assertEqual(urljoin(user_change_url, rel_link), password_change_url) self.assertEqual(urljoin(user_change_url, rel_link), password_change_url)

View File

@ -1481,9 +1481,11 @@ class CsrfInErrorHandlingViewsTests(CsrfFunctionTestMixin, SimpleTestCase):
response = self.client.get("/does not exist/") response = self.client.get("/does not exist/")
# The error handler returns status code 599. # The error handler returns status code 599.
self.assertEqual(response.status_code, 599) self.assertEqual(response.status_code, 599)
token1 = response.content.decode("ascii") response.charset = "ascii"
token1 = response.text
response = self.client.get("/does not exist/") response = self.client.get("/does not exist/")
self.assertEqual(response.status_code, 599) self.assertEqual(response.status_code, 599)
token2 = response.content.decode("ascii") response.charset = "ascii"
token2 = response.text
secret2 = _unmask_cipher_token(token2) secret2 = _unmask_cipher_token(token2)
self.assertMaskedSecretCorrect(token1, secret2) self.assertMaskedSecretCorrect(token1, secret2)

View File

@ -630,7 +630,7 @@ class JsonResponseTests(SimpleTestCase):
def test_json_response_non_ascii(self): def test_json_response_non_ascii(self):
data = {"key": "łóżko"} data = {"key": "łóżko"}
response = JsonResponse(data) response = JsonResponse(data)
self.assertEqual(json.loads(response.content.decode()), data) self.assertEqual(json.loads(response.text), data)
def test_json_response_raises_type_error_with_default_setting(self): def test_json_response_raises_type_error_with_default_setting(self):
with self.assertRaisesMessage( with self.assertRaisesMessage(
@ -642,16 +642,16 @@ class JsonResponseTests(SimpleTestCase):
def test_json_response_text(self): def test_json_response_text(self):
response = JsonResponse("foobar", safe=False) response = JsonResponse("foobar", safe=False)
self.assertEqual(json.loads(response.content.decode()), "foobar") self.assertEqual(json.loads(response.text), "foobar")
def test_json_response_list(self): def test_json_response_list(self):
response = JsonResponse(["foo", "bar"], safe=False) response = JsonResponse(["foo", "bar"], safe=False)
self.assertEqual(json.loads(response.content.decode()), ["foo", "bar"]) self.assertEqual(json.loads(response.text), ["foo", "bar"])
def test_json_response_uuid(self): def test_json_response_uuid(self):
u = uuid.uuid4() u = uuid.uuid4()
response = JsonResponse(u, safe=False) response = JsonResponse(u, safe=False)
self.assertEqual(json.loads(response.content.decode()), str(u)) self.assertEqual(json.loads(response.text), str(u))
def test_json_response_custom_encoder(self): def test_json_response_custom_encoder(self):
class CustomDjangoJSONEncoder(DjangoJSONEncoder): class CustomDjangoJSONEncoder(DjangoJSONEncoder):
@ -659,11 +659,11 @@ class JsonResponseTests(SimpleTestCase):
return json.dumps({"foo": "bar"}) return json.dumps({"foo": "bar"})
response = JsonResponse({}, encoder=CustomDjangoJSONEncoder) response = JsonResponse({}, encoder=CustomDjangoJSONEncoder)
self.assertEqual(json.loads(response.content.decode()), {"foo": "bar"}) self.assertEqual(json.loads(response.text), {"foo": "bar"})
def test_json_response_passing_arguments_to_json_dumps(self): def test_json_response_passing_arguments_to_json_dumps(self):
response = JsonResponse({"foo": "bar"}, json_dumps_params={"indent": 2}) response = JsonResponse({"foo": "bar"}, json_dumps_params={"indent": 2})
self.assertEqual(response.content.decode(), '{\n "foo": "bar"\n}') self.assertEqual(response.text, '{\n "foo": "bar"\n}')
class StreamingHttpResponseTests(SimpleTestCase): class StreamingHttpResponseTests(SimpleTestCase):

View File

@ -155,7 +155,7 @@ class SerializersTestBase:
if isinstance(stream, StringIO): if isinstance(stream, StringIO):
self.assertEqual(string_data, stream.getvalue()) self.assertEqual(string_data, stream.getvalue())
else: else:
self.assertEqual(string_data, stream.content.decode()) self.assertEqual(string_data, stream.text)
def test_serialize_specific_fields(self): def test_serialize_specific_fields(self):
obj = ComplexModel(field1="first", field2="second", field3="third") obj = ComplexModel(field1="first", field2="second", field3="third")

View File

@ -45,7 +45,7 @@ class GenericViewsSitemapTests(SitemapTestsBase):
"%s\n" "%s\n"
"</urlset>" "</urlset>"
) % expected ) % expected
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_generic_sitemap_lastmod(self): def test_generic_sitemap_lastmod(self):
test_model = TestModel.objects.first() test_model = TestModel.objects.first()
@ -61,7 +61,7 @@ class GenericViewsSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
test_model.pk, test_model.pk,
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
self.assertEqual( self.assertEqual(
response.headers["Last-Modified"], "Wed, 13 Mar 2013 10:00:00 GMT" response.headers["Last-Modified"], "Wed, 13 Mar 2013 10:00:00 GMT"
) )
@ -89,4 +89,4 @@ class GenericViewsSitemapTests(SitemapTestsBase):
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>http://example.com/simple/sitemap-generic.xml</loc><lastmod>2013-03-13T10:00:00</lastmod></sitemap> <sitemap><loc>http://example.com/simple/sitemap-generic.xml</loc><lastmod>2013-03-13T10:00:00</lastmod></sitemap>
</sitemapindex>""" </sitemapindex>"""
self.assertXMLEqual(response.content.decode("utf-8"), expected_content) self.assertXMLEqual(response.text, expected_content)

View File

@ -29,7 +29,7 @@ class HTTPSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_sitemap_not_callable(self): def test_sitemap_not_callable(self):
"""A sitemap may not be callable.""" """A sitemap may not be callable."""
@ -42,7 +42,7 @@ class HTTPSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_paged_sitemap(self): def test_paged_sitemap(self):
"""A sitemap may have multiple pages.""" """A sitemap may have multiple pages."""
@ -54,7 +54,7 @@ class HTTPSitemapTests(SitemapTestsBase):
""".format( """.format(
self.base_url, date.today() self.base_url, date.today()
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
@override_settings( @override_settings(
TEMPLATES=[ TEMPLATES=[
@ -76,7 +76,7 @@ class HTTPSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_simple_sitemap_section(self): def test_simple_sitemap_section(self):
"A simple sitemap section can be rendered" "A simple sitemap section can be rendered"
@ -92,7 +92,7 @@ class HTTPSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_no_section(self): def test_no_section(self):
response = self.client.get("/simple/sitemap-simple2.xml") response = self.client.get("/simple/sitemap-simple2.xml")
@ -126,7 +126,7 @@ class HTTPSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
@override_settings( @override_settings(
TEMPLATES=[ TEMPLATES=[
@ -148,7 +148,7 @@ class HTTPSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_sitemap_last_modified(self): def test_sitemap_last_modified(self):
"Last-Modified header is set correctly" "Last-Modified header is set correctly"
@ -268,7 +268,7 @@ class HTTPSitemapTests(SitemapTestsBase):
"<changefreq>never</changefreq><priority>0.5</priority></url>\n" "<changefreq>never</changefreq><priority>0.5</priority></url>\n"
"</urlset>" "</urlset>"
) % date.today() ) % date.today()
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_sitemap_get_urls_no_site_1(self): def test_sitemap_get_urls_no_site_1(self):
""" """
@ -316,7 +316,7 @@ class HTTPSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_x_robots_sitemap(self): def test_x_robots_sitemap(self):
response = self.client.get("/simple/index.xml") response = self.client.get("/simple/index.xml")
@ -346,7 +346,7 @@ class HTTPSitemapTests(SitemapTestsBase):
"<changefreq>never</changefreq><priority>0.5</priority></url>\n" "<changefreq>never</changefreq><priority>0.5</priority></url>\n"
"</urlset>" "</urlset>"
).format(self.base_url, self.i18n_model.pk) ).format(self.base_url, self.i18n_model.pk)
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
@override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese"))) @override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese")))
def test_alternate_i18n_sitemap_index(self): def test_alternate_i18n_sitemap_index(self):
@ -374,7 +374,7 @@ class HTTPSitemapTests(SitemapTestsBase):
f"{expected_urls}\n" f"{expected_urls}\n"
f"</urlset>" f"</urlset>"
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
@override_settings( @override_settings(
LANGUAGES=(("en", "English"), ("pt", "Portuguese"), ("es", "Spanish")) LANGUAGES=(("en", "English"), ("pt", "Portuguese"), ("es", "Spanish"))
@ -404,7 +404,7 @@ class HTTPSitemapTests(SitemapTestsBase):
f"{expected_urls}\n" f"{expected_urls}\n"
f"</urlset>" f"</urlset>"
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
@override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese"))) @override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese")))
def test_alternate_i18n_sitemap_xdefault(self): def test_alternate_i18n_sitemap_xdefault(self):
@ -434,7 +434,7 @@ class HTTPSitemapTests(SitemapTestsBase):
f"{expected_urls}\n" f"{expected_urls}\n"
f"</urlset>" f"</urlset>"
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
@override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese"))) @override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese")))
def test_language_for_item_i18n_sitemap(self): def test_language_for_item_i18n_sitemap(self):
@ -460,7 +460,7 @@ class HTTPSitemapTests(SitemapTestsBase):
f"{expected_urls}\n" f"{expected_urls}\n"
f"</urlset>" f"</urlset>"
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
@override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese"))) @override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese")))
def test_alternate_language_for_item_i18n_sitemap(self): def test_alternate_language_for_item_i18n_sitemap(self):
@ -500,7 +500,7 @@ class HTTPSitemapTests(SitemapTestsBase):
f"{expected_urls}\n" f"{expected_urls}\n"
f"</urlset>" f"</urlset>"
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_sitemap_without_entries(self): def test_sitemap_without_entries(self):
response = self.client.get("/sitemap-without-entries/sitemap.xml") response = self.client.get("/sitemap-without-entries/sitemap.xml")
@ -510,7 +510,7 @@ class HTTPSitemapTests(SitemapTestsBase):
'xmlns:xhtml="http://www.w3.org/1999/xhtml">\n\n' 'xmlns:xhtml="http://www.w3.org/1999/xhtml">\n\n'
"</urlset>" "</urlset>"
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_callable_sitemod_partial(self): def test_callable_sitemod_partial(self):
""" """
@ -535,8 +535,8 @@ class HTTPSitemapTests(SitemapTestsBase):
"<loc>http://example.com/location/</loc></url>\n" "<loc>http://example.com/location/</loc></url>\n"
"</urlset>" "</urlset>"
) )
self.assertXMLEqual(index_response.content.decode(), expected_content_index) self.assertXMLEqual(index_response.text, expected_content_index)
self.assertXMLEqual(sitemap_response.content.decode(), expected_content_sitemap) self.assertXMLEqual(sitemap_response.text, expected_content_sitemap)
def test_callable_sitemod_full(self): def test_callable_sitemod_full(self):
""" """
@ -566,8 +566,8 @@ class HTTPSitemapTests(SitemapTestsBase):
"<lastmod>2014-03-13</lastmod></url>\n" "<lastmod>2014-03-13</lastmod></url>\n"
"</urlset>" "</urlset>"
) )
self.assertXMLEqual(index_response.content.decode(), expected_content_index) self.assertXMLEqual(index_response.text, expected_content_index)
self.assertXMLEqual(sitemap_response.content.decode(), expected_content_sitemap) self.assertXMLEqual(sitemap_response.text, expected_content_sitemap)
def test_callable_sitemod_no_items(self): def test_callable_sitemod_no_items(self):
index_response = self.client.get("/callable-lastmod-no-items/index.xml") index_response = self.client.get("/callable-lastmod-no-items/index.xml")
@ -577,4 +577,4 @@ class HTTPSitemapTests(SitemapTestsBase):
<sitemap><loc>http://example.com/simple/sitemap-callable-lastmod.xml</loc></sitemap> <sitemap><loc>http://example.com/simple/sitemap-callable-lastmod.xml</loc></sitemap>
</sitemapindex> </sitemapindex>
""" """
self.assertXMLEqual(index_response.content.decode(), expected_content_index) self.assertXMLEqual(index_response.text, expected_content_index)

View File

@ -20,7 +20,7 @@ class HTTPSSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_secure_sitemap_section(self): def test_secure_sitemap_section(self):
"A secure sitemap section can be rendered" "A secure sitemap section can be rendered"
@ -36,7 +36,7 @@ class HTTPSSitemapTests(SitemapTestsBase):
self.base_url, self.base_url,
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
@override_settings(SECURE_PROXY_SSL_HEADER=False) @override_settings(SECURE_PROXY_SSL_HEADER=False)
@ -54,7 +54,7 @@ class HTTPSDetectionSitemapTests(SitemapTestsBase):
self.base_url.replace("http://", "https://"), self.base_url.replace("http://", "https://"),
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)
def test_sitemap_section_with_https_request(self): def test_sitemap_section_with_https_request(self):
"A sitemap section requested in HTTPS is rendered with HTTPS links" "A sitemap section requested in HTTPS is rendered with HTTPS links"
@ -70,4 +70,4 @@ class HTTPSDetectionSitemapTests(SitemapTestsBase):
self.base_url.replace("http://", "https://"), self.base_url.replace("http://", "https://"),
date.today(), date.today(),
) )
self.assertXMLEqual(response.content.decode(), expected_content) self.assertXMLEqual(response.text, expected_content)

View File

@ -295,7 +295,7 @@ class I18NViewTests(SimpleTestCase):
""" """
with override("de"): with override("de"):
response = self.client.get("/jsoni18n/") response = self.client.get("/jsoni18n/")
data = json.loads(response.content.decode()) data = json.loads(response.text)
self.assertIn("catalog", data) self.assertIn("catalog", data)
self.assertIn("formats", data) self.assertIn("formats", data)
self.assertEqual( self.assertEqual(
@ -329,7 +329,7 @@ class I18NViewTests(SimpleTestCase):
""" """
with self.settings(LANGUAGE_CODE="es"), override("en-us"): with self.settings(LANGUAGE_CODE="es"), override("en-us"):
response = self.client.get("/jsoni18n/") response = self.client.get("/jsoni18n/")
data = json.loads(response.content.decode()) data = json.loads(response.text)
self.assertIn("catalog", data) self.assertIn("catalog", data)
self.assertIn("formats", data) self.assertIn("formats", data)
self.assertIn("plural", data) self.assertIn("plural", data)

View File

@ -10,7 +10,7 @@ class JsonResponseTests(SimpleTestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["content-type"], "application/json") self.assertEqual(response.headers["content-type"], "application/json")
self.assertEqual( self.assertEqual(
json.loads(response.content.decode()), json.loads(response.text),
{ {
"a": [1, 2, 3], "a": [1, 2, 3],
"foo": {"bar": "baz"}, "foo": {"bar": "baz"},