diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py index 2d3240915e2..2964a860346 100644 --- a/tests/regressiontests/httpwrappers/tests.py +++ b/tests/regressiontests/httpwrappers/tests.py @@ -7,6 +7,8 @@ import pickle import warnings from django.core.exceptions import SuspiciousOperation +from django.core.signals import request_finished +from django.db import close_connection from django.http import (QueryDict, HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect, HttpResponseNotAllowed, HttpResponseNotModified, StreamingHttpResponse, @@ -484,6 +486,15 @@ class StreamingHttpResponseTests(TestCase): r.tell() class FileCloseTests(TestCase): + + def setUp(self): + # Disable the request_finished signal during this test + # to avoid interfering with the database connection. + request_finished.disconnect(close_connection) + + def tearDown(self): + request_finished.connect(close_connection) + def test_response(self): filename = os.path.join(os.path.dirname(upath(__file__)), 'abc.txt') diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py index 2583a1ea04f..67aec08af2c 100644 --- a/tests/regressiontests/serializers_regress/tests.py +++ b/tests/regressiontests/serializers_regress/tests.py @@ -506,7 +506,6 @@ def streamTest(format, self): self.assertEqual(string_data, stream.getvalue()) else: self.assertEqual(string_data, stream.content.decode('utf-8')) - stream.close() for format in serializers.get_serializer_formats(): setattr(SerializerTests, 'test_' + format + '_serializer', curry(serializerTest, format)) diff --git a/tests/regressiontests/views/tests/static.py b/tests/regressiontests/views/tests/static.py index 8b8ef8ba9b7..bdd9fbfc0bc 100644 --- a/tests/regressiontests/views/tests/static.py +++ b/tests/regressiontests/views/tests/static.py @@ -27,7 +27,6 @@ class StaticTests(TestCase): for filename in media_files: response = self.client.get('/views/%s/%s' % (self.prefix, filename)) response_content = b''.join(response) - response.close() file_path = path.join(media_dir, filename) with open(file_path, 'rb') as fp: self.assertEqual(fp.read(), response_content) @@ -36,14 +35,12 @@ class StaticTests(TestCase): def test_unknown_mime_type(self): response = self.client.get('/views/%s/file.unknown' % self.prefix) - response.close() self.assertEqual('application/octet-stream', response['Content-Type']) def test_copes_with_empty_path_component(self): file_name = 'file.txt' response = self.client.get('/views/%s//%s' % (self.prefix, file_name)) response_content = b''.join(response) - response.close() with open(path.join(media_dir, file_name), 'rb') as fp: self.assertEqual(fp.read(), response_content) @@ -52,7 +49,6 @@ class StaticTests(TestCase): response = self.client.get('/views/%s/%s' % (self.prefix, file_name), HTTP_IF_MODIFIED_SINCE='Thu, 1 Jan 1970 00:00:00 GMT') response_content = b''.join(response) - response.close() with open(path.join(media_dir, file_name), 'rb') as fp: self.assertEqual(fp.read(), response_content) @@ -77,7 +73,6 @@ class StaticTests(TestCase): response = self.client.get('/views/%s/%s' % (self.prefix, file_name), HTTP_IF_MODIFIED_SINCE=invalid_date) response_content = b''.join(response) - response.close() with open(path.join(media_dir, file_name), 'rb') as fp: self.assertEqual(fp.read(), response_content) self.assertEqual(len(response_content), @@ -94,7 +89,6 @@ class StaticTests(TestCase): response = self.client.get('/views/%s/%s' % (self.prefix, file_name), HTTP_IF_MODIFIED_SINCE=invalid_date) response_content = b''.join(response) - response.close() with open(path.join(media_dir, file_name), 'rb') as fp: self.assertEqual(fp.read(), response_content) self.assertEqual(len(response_content),