diff options
author | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-08-06 19:10:27 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-08-08 07:27:32 +0200 |
commit | 88e67a54b7ed0210c11523a337b498aadb2f5187 (patch) | |
tree | 6ceacec098aebb44dbba3f72d70261c68d3f004b /tests/staticfiles_tests | |
parent | c0beff21239e70cbdcc9597e5be09e505bb8f76c (diff) | |
download | django-88e67a54b7ed0210c11523a337b498aadb2f5187.tar.gz |
Added test for non-HTTP request on ASGIStaticFilesHandler.
Diffstat (limited to 'tests/staticfiles_tests')
-rw-r--r-- | tests/staticfiles_tests/test_handlers.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/staticfiles_tests/test_handlers.py b/tests/staticfiles_tests/test_handlers.py index e0451c6e16..5145d187e1 100644 --- a/tests/staticfiles_tests/test_handlers.py +++ b/tests/staticfiles_tests/test_handlers.py @@ -5,6 +5,13 @@ from django.test import AsyncRequestFactory from .cases import StaticFilesTestCase +class MockApplication: + """ASGI application that returns a string indicating that it was called.""" + + async def __call__(self, scope, receive, send): + return "Application called" + + class TestASGIStaticFilesHandler(StaticFilesTestCase): async_request_factory = AsyncRequestFactory() @@ -20,3 +27,15 @@ class TestASGIStaticFilesHandler(StaticFilesTestCase): handler = ASGIStaticFilesHandler(ASGIHandler()) response = await handler.get_response_async(request) self.assertEqual(response.status_code, 404) + + async def test_non_http_requests_passed_to_the_wrapped_application(self): + tests = [ + "/static/path.txt", + "/non-static/path.txt", + ] + for path in tests: + with self.subTest(path=path): + scope = {"type": "websocket", "path": path} + handler = ASGIStaticFilesHandler(MockApplication()) + response = await handler(scope, None, None) + self.assertEqual(response, "Application called") |