diff options
| author | Alexandre Spaeth <Alexerson@users.noreply.github.com> | 2023-02-17 10:35:19 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-02-17 10:48:00 +0100 |
| commit | bfb8fda3e69cc6f5c6695ba70117faff51cc25a9 (patch) | |
| tree | 58b2dc46a4adbc5952dad9f42f6a2b4757d8d16e /tests/handlers | |
| parent | 8eef22dfed2d53df0da10c0090d9cb04f66efb15 (diff) | |
Refs #34342 -- Added tests for handling sync streaming responses by test client.
Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es>
Diffstat (limited to 'tests/handlers')
| -rw-r--r-- | tests/handlers/tests.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py index 96826d3056..0df481c2fc 100644 --- a/tests/handlers/tests.py +++ b/tests/handlers/tests.py @@ -171,7 +171,7 @@ class SignalsTests(SimpleTestCase): def test_request_signals_streaming_response(self): response = self.client.get("/streaming/") self.assertEqual(self.signals, ["started"]) - self.assertEqual(b"".join(response.streaming_content), b"streaming content") + self.assertEqual(b"".join(list(response)), b"streaming content") self.assertEqual(self.signals, ["started", "finished"]) @@ -248,6 +248,11 @@ class HandlerRequestTests(SimpleTestCase): ): self.client.get(url) + def test_streaming(self): + response = self.client.get("/streaming/") + self.assertEqual(response.status_code, 200) + self.assertEqual(b"".join(list(response)), b"streaming content") + class ScriptNameTests(SimpleTestCase): def test_get_script_name(self): @@ -312,3 +317,15 @@ class AsyncHandlerRequestTests(SimpleTestCase): ) with self.assertRaisesMessage(ValueError, msg): await self.async_client.get("/unawaited/") + + async def test_sync_streaming(self): + response = await self.async_client.get("/streaming/") + self.assertEqual(response.status_code, 200) + msg = ( + "StreamingHttpResponse must consume synchronous iterators in order to " + "serve them asynchronously. Use an asynchronous iterator instead." + ) + with self.assertWarnsMessage(Warning, msg): + self.assertEqual( + b"".join([chunk async for chunk in response]), b"streaming content" + ) |
