From 92837ae56999a6f602d22130bfb3c49cd9b40242 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Mon, 18 Feb 2013 14:26:33 +0100 Subject: [PATCH] Avoided firing the request_finished signal in tests. * Avoided calling BaseHttpResponse.close(). The test client take care of that since acc5396e. * Disconnected the request_finished signal when this method must be called. The test client has a similar implementation since bacb097a. --- tests/regressiontests/httpwrappers/tests.py | 11 +++++++++++ tests/regressiontests/serializers_regress/tests.py | 1 - tests/regressiontests/views/tests/static.py | 6 ------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py index 2d3240915e..2964a86034 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 2583a1ea04..67aec08af2 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 8b8ef8ba9b..bdd9fbfc0b 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),