[Django] #31550: AssertionError raised by test_file_response method of ASGITest class.

36 views
Skip to first unread message

Django

unread,
May 8, 2020, 9:19:14 AM5/8/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-----------------------------------------+----------------------------
Reporter: Yash Saini | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.0
Severity: Normal | 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 |
-----------------------------------------+----------------------------
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')
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31550>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 8, 2020, 10:52:28 AM5/8/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------

Reporter: Yash Saini | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution: needsinfo

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 felixxm):

* status: new => closed
* resolution: => needsinfo
* component: Uncategorized => HTTP handling
* type: Uncategorized => Cleanup/optimization


Comment:

Content-type depends on a platform. Jenkins doesn't report this issue on
Windows and Linux. What platform and Python version are you using?

--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:1>

Django

unread,
May 8, 2020, 3:07:36 PM5/8/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------

Reporter: Yash Saini | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution: needsinfo
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
-------------------------------------+-------------------------------------

Comment (by Yash Saini):

I am using Windows 10 and python 3.7.7.

--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:2>

Django

unread,
May 9, 2020, 2:14:49 PM5/9/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------

Reporter: Yash Saini | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution: needsinfo
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
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

The failure doesn't reproduce for me on Windows with Python 3.7 or 3.8.

--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:3>

Django

unread,
Sep 25, 2020, 6:34:48 PM9/25/20
to django-...@googlegroups.com
#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

unread,
Sep 29, 2020, 2:50:26 AM9/29/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------

Reporter: Yash Saini | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution: needsinfo

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 Carlton Gibson):

* status: new => closed
* resolution: => needsinfo


Comment:

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…)

--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:5>

Django

unread,
Nov 3, 2020, 4:09:24 AM11/3/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
--------------------------------------+------------------------------------

Reporter: Yash Saini | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution:
Keywords: ASGI tests | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Carlton Gibson):

* status: closed => new
* has_patch: 0 => 1
* resolution: needsinfo =>
* stage: Unreviewed => Accepted


Comment:

This has come up again with a [https://github.com/django/django/pull/13633
PR adjusting the test case to pass with either mimetype].

--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:6>

Django

unread,
Nov 3, 2020, 6:48:39 AM11/3/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------
Reporter: Yash Saini | Owner:
Type: | chrisxkeith
Cleanup/optimization | Status: assigned

Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution:
Keywords: ASGI tests | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* owner: nobody => chrisxkeith
* needs_better_patch: 0 => 1
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:7>

Django

unread,
Nov 4, 2020, 2:03:23 PM11/4/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------
Reporter: Yash Saini | Owner:
Type: | chrisxkeith
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution:
Keywords: ASGI tests | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:8>

Django

unread,
Nov 4, 2020, 2:23:38 PM11/4/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------
Reporter: Yash Saini | Owner:
Type: | chrisxkeith
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution:
Keywords: ASGI tests | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:9>

Django

unread,
Nov 5, 2020, 2:19:57 AM11/5/20
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------
Reporter: Yash Saini | Owner:
Type: | chrisxkeith
Cleanup/optimization | Status: closed

Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution: fixed

Keywords: ASGI tests | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"76181308fb02e67794d0cc1471766a5d7e4c877e" 7618130]:
{{{
#!CommitTicketReference repository=""
revision="76181308fb02e67794d0cc1471766a5d7e4c877e"
Fixed #31550 -- Adjusted ASGI test_file_response for various Windows
content types.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:10>

Django

unread,
Feb 4, 2021, 3:59:55 PM2/4/21
to django-...@googlegroups.com
#31550: AssertionError raised by test_file_response method of ASGITest class.
-------------------------------------+-------------------------------------
Reporter: Yash Saini | Owner:
Type: | chrisxkeith
Cleanup/optimization | Status: closed
Component: HTTP handling | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: ASGI tests | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"5dec57a6fc5a41bdfe1e881bfd364d7ae1c67b5e" 5dec57a6]:
{{{
#!CommitTicketReference repository=""
revision="5dec57a6fc5a41bdfe1e881bfd364d7ae1c67b5e"
[3.1.x] Fixed #31550 -- Adjusted ASGI test_file_response for various
Windows content types.

Backport of 76181308fb02e67794d0cc1471766a5d7e4c877e from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31550#comment:11>

Reply all
Reply to author
Forward
0 new messages