Permalink
Browse files

[1.5.x] Fixed #19519 again -- Regression in LiveServerTestCase after f…

…d1279a.

Backport of 328f5b5.
  • Loading branch information...
1 parent dfd8623 commit 56e54727661bc34bd2b6f9fa6a75f5370149256e @aaugustin aaugustin committed Jan 1, 2013
Showing with 11 additions and 15 deletions.
  1. +10 −5 django/test/client.py
  2. +0 −2 django/test/testcases.py
  3. +1 −7 django/test/utils.py
  4. +0 −1 tests/regressiontests/handlers/tests.py
View
@@ -16,7 +16,9 @@
from django.contrib.auth import authenticate, login
from django.core.handlers.base import BaseHandler
from django.core.handlers.wsgi import WSGIRequest
-from django.core.signals import got_request_exception
+from django.core.signals import (request_started, request_finished,
+ got_request_exception)
+from django.db import close_connection
from django.http import SimpleCookie, HttpRequest, QueryDict
from django.template import TemplateDoesNotExist
from django.test import signals
@@ -76,7 +78,9 @@ def closing_iterator_wrapper(iterable, close):
for item in iterable:
yield item
finally:
- close()
+ request_finished.disconnect(close_connection)
+ close() # will fire request_finished
+ request_finished.connect(close_connection)
class ClientHandler(BaseHandler):
@@ -91,14 +95,13 @@ def __init__(self, enforce_csrf_checks=True, *args, **kwargs):
def __call__(self, environ):
from django.conf import settings
- from django.core import signals
# Set up middleware if needed. We couldn't do this earlier, because
# settings weren't available.
if self._request_middleware is None:
self.load_middleware()
- signals.request_started.send(sender=self.__class__)
+ request_started.send(sender=self.__class__)
request = WSGIRequest(environ)
# sneaky little hack so that we can easily get round
# CsrfViewMiddleware. This makes life easier, and is probably
@@ -112,7 +115,9 @@ def __call__(self, environ):
response.streaming_content = closing_iterator_wrapper(
response.streaming_content, response.close)
else:
- response.close()
+ request_finished.disconnect(close_connection)
+ response.close() # will fire request_finished
+ request_finished.connect(close_connection)
return response
@@ -641,8 +641,6 @@ def assertContains(self, response, text, count=None, status_code=200,
else:
content = response.content
content = content.decode(response._charset)
- # Avoid ResourceWarning about unclosed files.
- response.close()
if html:
content = assert_and_parse_html(self, content, None,
"Response's content is not valid HTML:")
@@ -4,8 +4,6 @@
from django.conf import settings, UserSettingsHolder
from django.core import mail
-from django.core.signals import request_finished
-from django.db import close_connection
from django.test.signals import template_rendered, setting_changed
from django.template import Template, loader, TemplateDoesNotExist
from django.template.loaders import cached
@@ -70,10 +68,8 @@ def setup_test_environment():
"""Perform any global pre-test setup. This involves:
- Installing the instrumented test renderer
- - Setting the email backend to the locmem email backend.
+ - Set the email backend to the locmem email backend.
@bquinn
bquinn Jan 6, 2013

why this change? if you wanted to change the tense of this line it should be changed for all the other lines as well, eg "install the instrumented..." It's a very small issue, but you want a quality release, right?! :-)

@aaugustin
aaugustin Jan 7, 2013 Django member

In this commit, I reverted all the changes made to this file in fd1279a, including this minor docstring fix. Indeed, I could have kept it.

@bquinn
bquinn Jan 8, 2013

oh I see, fair enough! Thanks for replying, and thanks for all your work on Django, we really appreciate it!

- Setting the active locale to match the LANGUAGE_CODE setting.
- - Disconnecting the request_finished signal to avoid closing
- the database connection within tests.
"""
Template.original_render = Template._render
Template._render = instrumented_test_render
@@ -85,8 +81,6 @@ def setup_test_environment():
deactivate()
- request_finished.disconnect(close_connection)
-
def teardown_test_environment():
"""Perform any global post-test teardown. This involves:
@@ -56,6 +56,5 @@ def test_request_signals(self):
def test_request_signals_streaming_response(self):
response = self.client.get('/streaming/')
self.assertEqual(self.signals, ['started'])
- # Avoid self.assertContains, because it explicitly calls response.close()
self.assertEqual(b''.join(response.streaming_content), b"streaming content")
self.assertEqual(self.signals, ['started', 'finished'])

0 comments on commit 56e5472

Please sign in to comment.