diff options
| author | Tom Carrick <tom@carrick.eu> | 2020-07-14 13:32:24 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-09-14 08:41:59 +0200 |
| commit | bcc2befd0e9c1885e45b46d0b0bcdc11def8b249 (patch) | |
| tree | 59fab69a3182286da87fcd6fe05a8ce0f4277a5a /tests/responses/test_fileresponse.py | |
| parent | 71ae1ab0123582cc5bfe0f7d5f4cc19a9412f396 (diff) | |
Fixed #31789 -- Added a new headers interface to HttpResponse.
Diffstat (limited to 'tests/responses/test_fileresponse.py')
| -rw-r--r-- | tests/responses/test_fileresponse.py | 37 |
1 files changed, 23 insertions, 14 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" ) |
