1
0
mirror of https://github.com/django/django.git synced 2025-10-29 08:36:09 +00:00

Refs #33476 -- Reformatted code with Black.

This commit is contained in:
django-bot
2022-02-03 20:24:19 +01:00
committed by Mariusz Felisiak
parent f68fa8b45d
commit 9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions

View File

@@ -6,8 +6,8 @@ from django.http import HttpResponse
from django.http.response import HttpResponseBase
from django.test import SimpleTestCase
UTF8 = 'utf-8'
ISO88591 = 'iso-8859-1'
UTF8 = "utf-8"
ISO88591 = "iso-8859-1"
class HttpResponseBaseTests(SimpleTestCase):
@@ -22,14 +22,20 @@ class HttpResponseBaseTests(SimpleTestCase):
r = HttpResponseBase()
self.assertIs(r.writable(), False)
with self.assertRaisesMessage(OSError, 'This HttpResponseBase instance is not writable'):
r.write('asdf')
with self.assertRaisesMessage(OSError, 'This HttpResponseBase instance is not writable'):
r.writelines(['asdf\n', 'qwer\n'])
with self.assertRaisesMessage(
OSError, "This HttpResponseBase instance is not writable"
):
r.write("asdf")
with self.assertRaisesMessage(
OSError, "This HttpResponseBase instance is not writable"
):
r.writelines(["asdf\n", "qwer\n"])
def test_tell(self):
r = HttpResponseBase()
with self.assertRaisesMessage(OSError, 'This HttpResponseBase instance cannot tell its position'):
with self.assertRaisesMessage(
OSError, "This HttpResponseBase instance cannot tell its position"
):
r.tell()
def test_setdefault(self):
@@ -39,12 +45,12 @@ class HttpResponseBaseTests(SimpleTestCase):
"""
r = HttpResponseBase()
r.headers['Header'] = 'Value'
r.setdefault('header', 'changed')
self.assertEqual(r.headers['header'], 'Value')
r.headers["Header"] = "Value"
r.setdefault("header", "changed")
self.assertEqual(r.headers["header"], "Value")
r.setdefault('x-header', 'DefaultValue')
self.assertEqual(r.headers['X-Header'], 'DefaultValue')
r.setdefault("x-header", "DefaultValue")
self.assertEqual(r.headers["X-Header"], "DefaultValue")
class HttpResponseTests(SimpleTestCase):
@@ -60,16 +66,18 @@ class HttpResponseTests(SimpleTestCase):
self.assertEqual(resp.reason_phrase, "Service Unavailable")
def test_valid_status_code_string(self):
resp = HttpResponse(status='100')
resp = HttpResponse(status="100")
self.assertEqual(resp.status_code, 100)
resp = HttpResponse(status='404')
resp = HttpResponse(status="404")
self.assertEqual(resp.status_code, 404)
resp = HttpResponse(status='599')
resp = HttpResponse(status="599")
self.assertEqual(resp.status_code, 599)
def test_invalid_status_code(self):
must_be_integer = 'HTTP status code must be an integer.'
must_be_integer_in_range = 'HTTP status code must be an integer from 100 to 599.'
must_be_integer = "HTTP status code must be an integer."
must_be_integer_in_range = (
"HTTP status code must be an integer from 100 to 599."
)
with self.assertRaisesMessage(TypeError, must_be_integer):
HttpResponse(status=object())
with self.assertRaisesMessage(TypeError, must_be_integer):
@@ -86,27 +94,31 @@ class HttpResponseTests(SimpleTestCase):
self.assertEqual(resp.reason_phrase, reason)
def test_charset_detection(self):
""" HttpResponse should parse charset from content_type."""
response = HttpResponse('ok')
"""HttpResponse should parse charset from content_type."""
response = HttpResponse("ok")
self.assertEqual(response.charset, settings.DEFAULT_CHARSET)
response = HttpResponse(charset=ISO88591)
self.assertEqual(response.charset, ISO88591)
self.assertEqual(response.headers['Content-Type'], 'text/html; charset=%s' % ISO88591)
self.assertEqual(
response.headers["Content-Type"], "text/html; charset=%s" % ISO88591
)
response = HttpResponse(content_type='text/plain; charset=%s' % UTF8, charset=ISO88591)
response = HttpResponse(
content_type="text/plain; charset=%s" % UTF8, charset=ISO88591
)
self.assertEqual(response.charset, ISO88591)
response = HttpResponse(content_type='text/plain; charset=%s' % ISO88591)
response = HttpResponse(content_type="text/plain; charset=%s" % ISO88591)
self.assertEqual(response.charset, ISO88591)
response = HttpResponse(content_type='text/plain; charset="%s"' % ISO88591)
self.assertEqual(response.charset, ISO88591)
response = HttpResponse(content_type='text/plain; charset=')
response = HttpResponse(content_type="text/plain; charset=")
self.assertEqual(response.charset, settings.DEFAULT_CHARSET)
response = HttpResponse(content_type='text/plain')
response = HttpResponse(content_type="text/plain")
self.assertEqual(response.charset, settings.DEFAULT_CHARSET)
def test_response_content_charset(self):
@@ -118,13 +130,15 @@ class HttpResponseTests(SimpleTestCase):
response = HttpResponse(utf8_content)
self.assertContains(response, utf8_content)
response = HttpResponse(iso_content, content_type='text/plain; charset=%s' % ISO88591)
response = HttpResponse(
iso_content, content_type="text/plain; charset=%s" % ISO88591
)
self.assertContains(response, iso_content)
response = HttpResponse(iso_content)
self.assertContains(response, iso_content)
response = HttpResponse(iso_content, content_type='text/plain')
response = HttpResponse(iso_content, content_type="text/plain")
self.assertContains(response, iso_content)
def test_repr(self):
@@ -134,8 +148,8 @@ class HttpResponseTests(SimpleTestCase):
def test_repr_no_content_type(self):
response = HttpResponse(status=204)
del response.headers['Content-Type']
self.assertEqual(repr(response), '<HttpResponse status_code=204>')
del response.headers["Content-Type"]
self.assertEqual(repr(response), "<HttpResponse status_code=204>")
def test_wrap_textiowrapper(self):
content = "Café :)"
@@ -147,10 +161,10 @@ class HttpResponseTests(SimpleTestCase):
def test_generator_cache(self):
generator = (str(i) for i in range(10))
response = HttpResponse(content=generator)
self.assertEqual(response.content, b'0123456789')
self.assertEqual(response.content, b"0123456789")
with self.assertRaises(StopIteration):
next(generator)
cache.set('my-response-key', response)
response = cache.get('my-response-key')
self.assertEqual(response.content, b'0123456789')
cache.set("my-response-key", response)
response = cache.get("my-response-key")
self.assertEqual(response.content, b"0123456789")