summaryrefslogtreecommitdiff
path: root/tests/responses/tests.py
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-03 20:24:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch)
treef0506b668a013d0063e5fba3dbf4863b466713ba /tests/responses/tests.py
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/responses/tests.py')
-rw-r--r--tests/responses/tests.py78
1 files changed, 46 insertions, 32 deletions
diff --git a/tests/responses/tests.py b/tests/responses/tests.py
index 059cdf86ed..035dd39174 100644
--- a/tests/responses/tests.py
+++ b/tests/responses/tests.py
@@ -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")