#31550 closed Cleanup/optimization (fixed)
AssertionError raised by test_file_response method of ASGITest class.
Reported by: | Yash Saini | Owned by: | chrisxkeith |
---|---|---|---|
Component: | HTTP handling | Version: | 3.0 |
Severity: | Normal | Keywords: | ASGI tests |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
On running:
python runtests.py asgi
The following assertion is raised in tests\asgi\tests.py in ASGITest.test_file_response method:
AssertionError: Items in the first set but not the second: (b'Content-Type', b'text/x-python') Items in the second set but not the first: (b'Content-Type', b'text/plain')
Change History (11)
comment:1 by , 5 years ago
Component: | Uncategorized → HTTP handling |
---|---|
Resolution: | → needsinfo |
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
comment:4 by , 4 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
I think the test is incorrect in expecting text/plain
instead of text/x-python
as the content type for a Python file
test_file_response
in tests/asgi/tests.py
fails for me as well.
(.venv) PS D:\source\django\tests> py runtests.py asgi.tests ... ====================================================================== FAIL: test_file_response (asgi.tests.ASGITest) Makes sure that FileResponse works over ASGI. ---------------------------------------------------------------------- ... AssertionError: Items in the first set but not the second: (b'Content-Type', b'text/x-python') Items in the second set but not the first: (b'Content-Type', b'text/plain')
My environment (Windows 10 Pro Build 20211):
>>> sys.platform 'win32' >>> sys.getwindowsversion() sys.getwindowsversion(major=10, minor=0, build=20211, platform=2, service_pack='') >>> sys.version '3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)]'
The set_headers
method of django.http.FileResponse
queries the content type of the file on line 467:
content_type, encoding = mimetypes.guess_type(filename)
On my machine, the above line sets content_type
to text/x-python
, but line 79 in the test file expects text/plain
on Windows platforms:
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'), # line 79 (b'Content-Disposition', b'inline; filename="urls.py"'), }, )
The test method is incorrect, but why doesn't this fail on Jenkins? Is Jenkins running the tests on Windows 10 or an older version? The Python documentation for mimetypes.guess_type
doesn't shed much light, specifically on whether the function returns text/plain
for python files on Windows platforms (perhaps previous versions).
comment:5 by , 4 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Hi Addison. This works for me. #32041 came up recently, which is related.
If you can dig-in and come up with some more information we can look into it but short of a concrete analysis I'm not sure what we can do. What action are we to take? (The line in the tests is as it is because this was the behaviour we hit developing the feature…)
comment:6 by , 4 years ago
Has patch: | set |
---|---|
Resolution: | needsinfo |
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
This has come up again with a PR adjusting the test case to pass with either mimetype.
comment:7 by , 4 years ago
Owner: | changed from | to
---|---|
Patch needs improvement: | set |
Status: | new → assigned |
comment:8 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:9 by , 4 years ago
Patch needs improvement: | unset |
---|
Content-type depends on a platform. Jenkins doesn't report this issue on Windows and Linux. What platform and Python version are you using?