summaryrefslogtreecommitdiff
path: root/tests/responses
diff options
context:
space:
mode:
authorTom Carrick <tom@carrick.eu>2020-07-14 13:32:24 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-09-14 08:41:59 +0200
commitbcc2befd0e9c1885e45b46d0b0bcdc11def8b249 (patch)
tree59fab69a3182286da87fcd6fe05a8ce0f4277a5a /tests/responses
parent71ae1ab0123582cc5bfe0f7d5f4cc19a9412f396 (diff)
Fixed #31789 -- Added a new headers interface to HttpResponse.
Diffstat (limited to 'tests/responses')
-rw-r--r--tests/responses/test_fileresponse.py37
-rw-r--r--tests/responses/tests.py10
2 files changed, 28 insertions, 19 deletions
diff --git a/tests/responses/test_fileresponse.py b/tests/responses/test_fileresponse.py
index e77df4513a..46d407bdf5 100644
--- a/tests/responses/test_fileresponse.py
+++ b/tests/responses/test_fileresponse.py
@@ -12,23 +12,26 @@ from django.test import SimpleTestCase
class FileResponseTests(SimpleTestCase):
def test_file_from_disk_response(self):
response = FileResponse(open(__file__, 'rb'))
- self.assertEqual(response['Content-Length'], str(os.path.getsize(__file__)))
- self.assertIn(response['Content-Type'], ['text/x-python', 'text/plain'])
- self.assertEqual(response['Content-Disposition'], 'inline; filename="test_fileresponse.py"')
+ self.assertEqual(response.headers['Content-Length'], str(os.path.getsize(__file__)))
+ self.assertIn(response.headers['Content-Type'], ['text/x-python', 'text/plain'])
+ self.assertEqual(
+ response.headers['Content-Disposition'],
+ 'inline; filename="test_fileresponse.py"',
+ )
response.close()
def test_file_from_buffer_response(self):
response = FileResponse(io.BytesIO(b'binary content'))
- self.assertEqual(response['Content-Length'], '14')
- self.assertEqual(response['Content-Type'], 'application/octet-stream')
+ self.assertEqual(response.headers['Content-Length'], '14')
+ self.assertEqual(response.headers['Content-Type'], 'application/octet-stream')
self.assertFalse(response.has_header('Content-Disposition'))
self.assertEqual(list(response), [b'binary content'])
def test_file_from_buffer_unnamed_attachment(self):
response = FileResponse(io.BytesIO(b'binary content'), as_attachment=True)
- self.assertEqual(response['Content-Length'], '14')
- self.assertEqual(response['Content-Type'], 'application/octet-stream')
- self.assertEqual(response['Content-Disposition'], 'attachment')
+ self.assertEqual(response.headers['Content-Length'], '14')
+ self.assertEqual(response.headers['Content-Type'], 'application/octet-stream')
+ self.assertEqual(response.headers['Content-Disposition'], 'attachment')
self.assertEqual(list(response), [b'binary content'])
@skipIf(sys.platform == 'win32', "Named pipes are Unix-only.")
@@ -47,9 +50,12 @@ class FileResponseTests(SimpleTestCase):
def test_file_from_disk_as_attachment(self):
response = FileResponse(open(__file__, 'rb'), as_attachment=True)
- self.assertEqual(response['Content-Length'], str(os.path.getsize(__file__)))
- self.assertIn(response['Content-Type'], ['text/x-python', 'text/plain'])
- self.assertEqual(response['Content-Disposition'], 'attachment; filename="test_fileresponse.py"')
+ self.assertEqual(response.headers['Content-Length'], str(os.path.getsize(__file__)))
+ self.assertIn(response.headers['Content-Type'], ['text/x-python', 'text/plain'])
+ self.assertEqual(
+ response.headers['Content-Disposition'],
+ 'attachment; filename="test_fileresponse.py"',
+ )
response.close()
def test_compressed_response(self):
@@ -67,7 +73,7 @@ class FileResponseTests(SimpleTestCase):
with self.subTest(ext=extension):
with tempfile.NamedTemporaryFile(suffix=extension) as tmp:
response = FileResponse(tmp)
- self.assertEqual(response['Content-Type'], mimetype)
+ self.assertEqual(response.headers['Content-Type'], mimetype)
self.assertFalse(response.has_header('Content-Encoding'))
def test_unicode_attachment(self):
@@ -75,8 +81,11 @@ class FileResponseTests(SimpleTestCase):
ContentFile(b'binary content', name="祝您平安.odt"), as_attachment=True,
content_type='application/vnd.oasis.opendocument.text',
)
- self.assertEqual(response['Content-Type'], 'application/vnd.oasis.opendocument.text')
self.assertEqual(
- response['Content-Disposition'],
+ response.headers['Content-Type'],
+ 'application/vnd.oasis.opendocument.text',
+ )
+ self.assertEqual(
+ response.headers['Content-Disposition'],
"attachment; filename*=utf-8''%E7%A5%9D%E6%82%A8%E5%B9%B3%E5%AE%89.odt"
)
diff --git a/tests/responses/tests.py b/tests/responses/tests.py
index 2c161ee352..059cdf86ed 100644
--- a/tests/responses/tests.py
+++ b/tests/responses/tests.py
@@ -39,12 +39,12 @@ class HttpResponseBaseTests(SimpleTestCase):
"""
r = HttpResponseBase()
- r['Header'] = 'Value'
+ r.headers['Header'] = 'Value'
r.setdefault('header', 'changed')
- self.assertEqual(r['header'], 'Value')
+ self.assertEqual(r.headers['header'], 'Value')
r.setdefault('x-header', 'DefaultValue')
- self.assertEqual(r['X-Header'], 'DefaultValue')
+ self.assertEqual(r.headers['X-Header'], 'DefaultValue')
class HttpResponseTests(SimpleTestCase):
@@ -92,7 +92,7 @@ class HttpResponseTests(SimpleTestCase):
response = HttpResponse(charset=ISO88591)
self.assertEqual(response.charset, ISO88591)
- self.assertEqual(response['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)
self.assertEqual(response.charset, ISO88591)
@@ -134,7 +134,7 @@ class HttpResponseTests(SimpleTestCase):
def test_repr_no_content_type(self):
response = HttpResponse(status=204)
- del response['Content-Type']
+ del response.headers['Content-Type']
self.assertEqual(repr(response), '<HttpResponse status_code=204>')
def test_wrap_textiowrapper(self):