1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Refs #34342 -- Added tests for handling sync streaming responses by test client.

Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es>
This commit is contained in:
Alexandre Spaeth
2023-02-17 10:35:19 +01:00
committed by Mariusz Felisiak
parent 8eef22dfed
commit bfb8fda3e6
3 changed files with 22 additions and 4 deletions

View File

@@ -41,9 +41,10 @@ class StaticTests(SimpleTestCase):
def test_chunked(self):
"The static view should stream files in chunks to avoid large memory usage"
response = self.client.get("/%s/%s" % (self.prefix, "long-line.txt"))
first_chunk = next(response.streaming_content)
response_iterator = iter(response)
first_chunk = next(response_iterator)
self.assertEqual(len(first_chunk), FileResponse.block_size)
second_chunk = next(response.streaming_content)
second_chunk = next(response_iterator)
response.close()
# strip() to prevent OS line endings from causing differences
self.assertEqual(len(second_chunk.strip()), 1449)