Skip to content

Commit 5dec57a

Browse files
chrisxkeithfelixxm
authored andcommitted
[3.1.x] Fixed #31550 -- Adjusted ASGI test_file_response for various Windows content types.
Backport of 7618130 from master
1 parent 30b7717 commit 5dec57a

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

tests/asgi/tests.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,23 @@ async def test_file_response(self):
7272
response_start = await communicator.receive_output()
7373
self.assertEqual(response_start['type'], 'http.response.start')
7474
self.assertEqual(response_start['status'], 200)
75-
self.assertEqual(
76-
set(response_start['headers']),
77-
{
78-
(b'Content-Length', str(len(test_file_contents)).encode('ascii')),
79-
(b'Content-Type', b'text/plain' if sys.platform == 'win32' else b'text/x-python'),
80-
(b'Content-Disposition', b'inline; filename="urls.py"'),
81-
},
82-
)
75+
headers = response_start['headers']
76+
self.assertEqual(len(headers), 3)
77+
expected_headers = {
78+
b'Content-Length': str(len(test_file_contents)).encode('ascii'),
79+
b'Content-Type': b'text/x-python',
80+
b'Content-Disposition': b'inline; filename="urls.py"',
81+
}
82+
for key, value in headers:
83+
try:
84+
self.assertEqual(value, expected_headers[key])
85+
except AssertionError:
86+
# Windows registry may not be configured with correct
87+
# mimetypes.
88+
if sys.platform == 'win32' and key == b'Content-Type':
89+
self.assertEqual(value, b'text/plain')
90+
else:
91+
raise
8392
response_body = await communicator.receive_output()
8493
self.assertEqual(response_body['type'], 'http.response.body')
8594
self.assertEqual(response_body['body'], test_file_contents)

0 commit comments

Comments
 (0)