From b1bf8d64fbadcab860eb98662c49b8db33db0c3c Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 21 Jan 2015 20:59:40 +0100 Subject: [1.7.x] Fixed #24193 -- Prevented unclosed file warnings in static.serve() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This regression was caused by 818e59a3f0. The patch is a partial backport of the new FileResponse class available in later Django versions. Thanks Raphaƫl Hertzog for the report, and Tim Graham and Collin Anderson for the reviews. --- tests/view_tests/tests/test_static.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/view_tests/tests/test_static.py b/tests/view_tests/tests/test_static.py index c7a36ce743..1f1ca44c83 100644 --- a/tests/view_tests/tests/test_static.py +++ b/tests/view_tests/tests/test_static.py @@ -5,10 +5,10 @@ from os import path import unittest from django.conf.urls.static import static -from django.http import HttpResponseNotModified +from django.http import FileResponse, HttpResponseNotModified from django.test import SimpleTestCase, override_settings from django.utils.http import http_date -from django.views.static import was_modified_since, STREAM_CHUNK_SIZE +from django.views.static import was_modified_since from .. import urls from ..urls import media_dir @@ -37,10 +37,11 @@ class StaticTests(SimpleTestCase): "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) - self.assertEqual(len(first_chunk), STREAM_CHUNK_SIZE) + self.assertEqual(len(first_chunk), FileResponse.block_size) second_chunk = next(response.streaming_content) # strip() to prevent OS line endings from causing differences self.assertEqual(len(second_chunk.strip()), 1449) + response.close() def test_unknown_mime_type(self): response = self.client.get('/%s/file.unknown' % self.prefix) -- cgit v1.3