mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #25725 -- Made HttpReponse immediately close objects.
This commit is contained in:
parent
a6c803a2e3
commit
5233b70070
5 changed files with 29 additions and 18 deletions
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|||
import io
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.http import HttpResponse
|
||||
from django.http.response import HttpResponseBase
|
||||
from django.test import SimpleTestCase
|
||||
|
@ -121,3 +122,13 @@ class HttpResponseTests(SimpleTestCase):
|
|||
with io.TextIOWrapper(r, UTF8) as buf:
|
||||
buf.write(content)
|
||||
self.assertEqual(r.content, content.encode(UTF8))
|
||||
|
||||
def test_generator_cache(self):
|
||||
generator = ("{}".format(i) for i in range(10))
|
||||
response = HttpResponse(content=generator)
|
||||
self.assertEqual(response.content, b'0123456789')
|
||||
self.assertRaises(StopIteration, next, generator)
|
||||
|
||||
cache.set('my-response-key', response)
|
||||
response = cache.get('my-response-key')
|
||||
self.assertEqual(response.content, b'0123456789')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue