diff options
author | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-12-13 16:15:25 +0100 |
---|---|---|
committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-12-22 10:41:12 +0100 |
commit | 0bd2c0c9015b53c41394a1c0989afbfd94dc2830 (patch) | |
tree | 6b24758335cf10eeedfdf7dec50cda3500796305 /tests/asgi | |
parent | ae0899be0d787fbfc5f5ab2b18c5a8219d822d2b (diff) | |
download | django-0bd2c0c9015b53c41394a1c0989afbfd94dc2830.tar.gz |
Fixed #33735 -- Added async support to StreamingHttpResponse.
Thanks to Florian Vazelle for initial exploratory work, and to Nick
Pope and Mariusz Felisiak for review.
Diffstat (limited to 'tests/asgi')
-rw-r--r-- | tests/asgi/tests.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/asgi/tests.py b/tests/asgi/tests.py index 4e51c2d9fe..61d040b45b 100644 --- a/tests/asgi/tests.py +++ b/tests/asgi/tests.py @@ -12,6 +12,7 @@ from django.db import close_old_connections from django.test import ( AsyncRequestFactory, SimpleTestCase, + ignore_warnings, modify_settings, override_settings, ) @@ -58,6 +59,13 @@ class ASGITest(SimpleTestCase): # Allow response.close() to finish. await communicator.wait() + # Python's file API is not async compatible. A third-party library such + # as https://github.com/Tinche/aiofiles allows passing the file to + # FileResponse as an async interator. With a sync iterator + # StreamingHTTPResponse triggers a warning when iterating the file. + # assertWarnsMessage is not async compatible, so ignore_warnings for the + # test. + @ignore_warnings(module="django.http.response") async def test_file_response(self): """ Makes sure that FileResponse works over ASGI. @@ -91,6 +99,8 @@ class ASGITest(SimpleTestCase): self.assertEqual(value, b"text/plain") else: raise + + # Warning ignored here. response_body = await communicator.receive_output() self.assertEqual(response_body["type"], "http.response.body") self.assertEqual(response_body["body"], test_file_contents) @@ -106,6 +116,7 @@ class ASGITest(SimpleTestCase): "django.contrib.staticfiles.finders.FileSystemFinder", ], ) + @ignore_warnings(module="django.http.response") async def test_static_file_response(self): application = ASGIStaticFilesHandler(get_asgi_application()) # Construct HTTP request. |