diff options
| author | Scott Halgrim <shalgrim@gmail.com> | 2022-11-08 12:19:59 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton@noumenal.es> | 2022-11-08 13:53:34 +0100 |
| commit | c4eaa67e2b880db778c9fe6d9854fbdfcc16ecd2 (patch) | |
| tree | a3d2aa24cd99ec75b204f8112caf04675c5a0f8f /tests/test_client | |
| parent | 8e6ea1d153a852b83eaa4807301b143df1647a44 (diff) | |
Fixed #34063 -- Fixed reading request body with async request factory and client.
Co-authored-by: Kevan Swanberg <kevswanberg@gmail.com>
Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es>
Diffstat (limited to 'tests/test_client')
| -rw-r--r-- | tests/test_client/tests.py | 18 | ||||
| -rw-r--r-- | tests/test_client/views.py | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py index 57dc22ea0c..5612ae4462 100644 --- a/tests/test_client/tests.py +++ b/tests/test_client/tests.py @@ -1103,6 +1103,14 @@ class AsyncClientTest(TestCase): response = await self.async_client.get("/get_view/", {"var": "val"}) self.assertContains(response, "This is a test. val is the value.") + async def test_post_data(self): + response = await self.async_client.post("/post_view/", {"value": 37}) + self.assertContains(response, "Data received: 37 is the value.") + + async def test_body_read_on_get_data(self): + response = await self.async_client.get("/post_view/") + self.assertContains(response, "Viewing GET page.") + @override_settings(ROOT_URLCONF="test_client.urls") class AsyncRequestFactoryTest(SimpleTestCase): @@ -1147,6 +1155,16 @@ class AsyncRequestFactoryTest(SimpleTestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response.content, b'{"example": "data"}') + async def test_request_limited_read(self): + tests = ["GET", "POST"] + for method in tests: + with self.subTest(method=method): + request = self.request_factory.generic( + method, + "/somewhere", + ) + self.assertEqual(request.read(200), b"") + def test_request_factory_sets_headers(self): request = self.request_factory.get( "/somewhere/", diff --git a/tests/test_client/views.py b/tests/test_client/views.py index 773e9e4e98..01850257b5 100644 --- a/tests/test_client/views.py +++ b/tests/test_client/views.py @@ -90,6 +90,8 @@ def post_view(request): c = Context() else: t = Template("Viewing GET page.", name="Empty GET Template") + # Used by test_body_read_on_get_data. + request.read(200) c = Context() return HttpResponse(t.render(c)) |
