summaryrefslogtreecommitdiff
path: root/tests/asgi
diff options
context:
space:
mode:
authorJonas Lundberg <jonas@5monkeys.se>2022-06-02 23:19:16 +0200
committerCarlton Gibson <carlton@noumenal.es>2022-06-09 11:11:45 +0200
commite96320c91724830034033a9cb8afd9cf8c11e2fd (patch)
tree12d82a70c1820bccc2f606b886bed4fdd3f6ea54 /tests/asgi
parentc32858a8ce961d276215a040ae0ab1e4409b70f8 (diff)
Fixed #33755 -- Moved ASGI body-file cleanup into request class.
Diffstat (limited to 'tests/asgi')
-rw-r--r--tests/asgi/tests.py18
-rw-r--r--tests/asgi/urls.py5
2 files changed, 21 insertions, 2 deletions
diff --git a/tests/asgi/tests.py b/tests/asgi/tests.py
index cfee11802c..57300d18fc 100644
--- a/tests/asgi/tests.py
+++ b/tests/asgi/tests.py
@@ -165,7 +165,11 @@ class ASGITest(SimpleTestCase):
async def test_post_body(self):
application = get_asgi_application()
- scope = self.async_request_factory._base_scope(method="POST", path="/post/")
+ scope = self.async_request_factory._base_scope(
+ method="POST",
+ path="/post/",
+ query_string="echo=1",
+ )
communicator = ApplicationCommunicator(application, scope)
await communicator.send_input({"type": "http.request", "body": b"Echo!"})
response_start = await communicator.receive_output()
@@ -175,6 +179,18 @@ class ASGITest(SimpleTestCase):
self.assertEqual(response_body["type"], "http.response.body")
self.assertEqual(response_body["body"], b"Echo!")
+ async def test_untouched_request_body_gets_closed(self):
+ application = get_asgi_application()
+ scope = self.async_request_factory._base_scope(method="POST", path="/post/")
+ communicator = ApplicationCommunicator(application, scope)
+ await communicator.send_input({"type": "http.request"})
+ response_start = await communicator.receive_output()
+ self.assertEqual(response_start["type"], "http.response.start")
+ self.assertEqual(response_start["status"], 204)
+ response_body = await communicator.receive_output()
+ self.assertEqual(response_body["type"], "http.response.body")
+ self.assertEqual(response_body["body"], b"")
+
async def test_get_query_string(self):
application = get_asgi_application()
for query_string in (b"name=Andrew", "name=Andrew"):
diff --git a/tests/asgi/urls.py b/tests/asgi/urls.py
index bd286c9b2f..34595c1b6c 100644
--- a/tests/asgi/urls.py
+++ b/tests/asgi/urls.py
@@ -26,7 +26,10 @@ def sync_waiter(request):
@csrf_exempt
def post_echo(request):
- return HttpResponse(request.body)
+ if request.GET.get("echo"):
+ return HttpResponse(request.body)
+ else:
+ return HttpResponse(status=204)
sync_waiter.active_threads = set()