Permalink
Browse files

Fixed #19519 again -- Regression in LiveServerTestCase after fd1279a.

  • Loading branch information...
aaugustin committed Jan 1, 2013
1 parent 3570ff7 commit bacb097ac31af2479c43934747b34fad7c91f55c
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
View
@@ -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:")
View
@@ -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.
- 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 bacb097

Please sign in to comment.