Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoided firing the request_finished signal in tests.

* Avoided calling BaseHttpResponse.close(). The test client take care of
  that since acc5396.
* Disconnected the request_finished signal when this method must be
  called. The test client has a similar implementation since bacb097.
  • Loading branch information...
commit 92837ae56999a6f602d22130bfb3c49cd9b40242 1 parent 09ca010
@aaugustin aaugustin authored
View
11 tests/regressiontests/httpwrappers/tests.py
@@ -7,6 +7,8 @@
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 @@ def test_streaming_response(self):
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')
View
1  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))
View
6 tests/regressiontests/views/tests/static.py
@@ -27,7 +27,6 @@ def test_serve(self):
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 @@ def test_serve(self):
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 @@ def test_is_modified_since(self):
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 @@ def test_invalid_if_modified_since(self):
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 @@ def test_invalid_if_modified_since2(self):
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),
Please sign in to comment.
Something went wrong with that request. Please try again.