#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------
Reporter: Yash Saini | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution:
Keywords: ASGI tests | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Addison Snelling):
* status: closed => new
* resolution: needsinfo =>
Comment:
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
[https://github.com/django/django/blob/master/django/http/response.py#L467
line 467]:
{{{
content_type, encoding = mimetypes.guess_type(filename)
}}}
On my machine, the above line sets `content_type` to `text/x-python`, but
[https://github.com/django/django/blob/master/tests/asgi/tests.py#L79 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
[https://docs.python.org/3/library/mimetypes.html#mimetypes.guess_type
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).
--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/071.7f573b225d0630b66a40ddb4c176e0f9%40djangoproject.com.