diff options
| author | Christopher Keith <chris.keith@gmail.com> | 2020-11-04 23:18:45 -0800 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-02-04 21:58:38 +0100 |
| commit | 5dec57a6fc5a41bdfe1e881bfd364d7ae1c67b5e (patch) | |
| tree | a29df7346e280e41566218b4a52b249fcb709e45 | |
| parent | 30b771766b99d899ed5fa60ac902250d40a4b50d (diff) | |
[3.1.x] Fixed #31550 -- Adjusted ASGI test_file_response for various Windows content types.
Backport of 76181308fb02e67794d0cc1471766a5d7e4c877e from master
| -rw-r--r-- | tests/asgi/tests.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/tests/asgi/tests.py b/tests/asgi/tests.py index 2ec493085e..68e242faa7 100644 --- a/tests/asgi/tests.py +++ b/tests/asgi/tests.py @@ -72,14 +72,23 @@ class ASGITest(SimpleTestCase): response_start = await communicator.receive_output() self.assertEqual(response_start['type'], 'http.response.start') self.assertEqual(response_start['status'], 200) - self.assertEqual( - set(response_start['headers']), - { - (b'Content-Length', str(len(test_file_contents)).encode('ascii')), - (b'Content-Type', b'text/plain' if sys.platform == 'win32' else b'text/x-python'), - (b'Content-Disposition', b'inline; filename="urls.py"'), - }, - ) + headers = response_start['headers'] + self.assertEqual(len(headers), 3) + expected_headers = { + b'Content-Length': str(len(test_file_contents)).encode('ascii'), + b'Content-Type': b'text/x-python', + b'Content-Disposition': b'inline; filename="urls.py"', + } + for key, value in headers: + try: + self.assertEqual(value, expected_headers[key]) + except AssertionError: + # Windows registry may not be configured with correct + # mimetypes. + if sys.platform == 'win32' and key == b'Content-Type': + self.assertEqual(value, b'text/plain') + else: + raise response_body = await communicator.receive_output() self.assertEqual(response_body['type'], 'http.response.body') self.assertEqual(response_body['body'], test_file_contents) |
