Ticket #19519: 19519-fix-live-server-test-case.patch

File 19519-fix-live-server-test-case.patch, 3.5 KB (added by Aymeric Augustin, 12 years ago)
  • django/test/client.py

    diff --git a/django/test/client.py b/django/test/client.py
    index 77d4de0..6bdc1cf 100644
    a b from django.conf import settings  
    1616from django.contrib.auth import authenticate, login
    1717from django.core.handlers.base import BaseHandler
    1818from django.core.handlers.wsgi import WSGIRequest
    19 from django.core.signals import got_request_exception
     19from django.core.signals import (request_started, request_finished,
     20    got_request_exception)
     21from django.db import close_connection
    2022from django.http import SimpleCookie, HttpRequest, QueryDict
    2123from django.template import TemplateDoesNotExist
    2224from django.test import signals
    def closing_iterator_wrapper(iterable, close):  
    7678        for item in iterable:
    7779            yield item
    7880    finally:
    79         close()
     81        request_finished.disconnect(close_connection)
     82        close()                                 # will fire request_finished
     83        request_finished.connect(close_connection)
    8084
    8185
    8286class ClientHandler(BaseHandler):
    class ClientHandler(BaseHandler):  
    9195
    9296    def __call__(self, environ):
    9397        from django.conf import settings
    94         from django.core import signals
    9598
    9699        # Set up middleware if needed. We couldn't do this earlier, because
    97100        # settings weren't available.
    98101        if self._request_middleware is None:
    99102            self.load_middleware()
    100103
    101         signals.request_started.send(sender=self.__class__)
     104        request_started.send(sender=self.__class__)
    102105        request = WSGIRequest(environ)
    103106        # sneaky little hack so that we can easily get round
    104107        # CsrfViewMiddleware.  This makes life easier, and is probably
    class ClientHandler(BaseHandler):  
    112115            response.streaming_content = closing_iterator_wrapper(
    113116                response.streaming_content, response.close)
    114117        else:
    115             response.close()
     118            request_finished.disconnect(close_connection)
     119            response.close()                    # will fire request_finished
     120            request_finished.connect(close_connection)
    116121
    117122        return response
    118123
  • django/test/utils.py

    diff --git a/django/test/utils.py b/django/test/utils.py
    index a1ff826..8114ae0 100644
    a b from xml.dom.minidom import parseString, Node  
    44
    55from django.conf import settings, UserSettingsHolder
    66from django.core import mail
    7 from django.core.signals import request_finished
    8 from django.db import close_connection
    97from django.test.signals import template_rendered, setting_changed
    108from django.template import Template, loader, TemplateDoesNotExist
    119from django.template.loaders import cached
    def setup_test_environment():  
    7068    """Perform any global pre-test setup. This involves:
    7169
    7270        - Installing the instrumented test renderer
    73         - Setting the email backend to the locmem email backend.
     71        - Set the email backend to the locmem email backend.
    7472        - Setting the active locale to match the LANGUAGE_CODE setting.
    75         - Disconnecting the request_finished signal to avoid closing
    76           the database connection within tests.
    7773    """
    7874    Template.original_render = Template._render
    7975    Template._render = instrumented_test_render
    def setup_test_environment():  
    8581
    8682    deactivate()
    8783
    88     request_finished.disconnect(close_connection)
    89 
    9084
    9185def teardown_test_environment():
    9286    """Perform any global post-test teardown. This involves:
Back to Top