Ticket #3162: test_client_exception_catch.patch
File test_client_exception_catch.patch, 1.9 KB (added by , 18 years ago) |
---|
-
django/test/client.py
1 1 from cStringIO import StringIO 2 import sys 2 3 from django.core.handlers.base import BaseHandler 3 4 from django.core.handlers.wsgi import WSGIRequest 5 from django.core.signals import got_request_exception 4 6 from django.dispatch import dispatcher 5 7 from django.http import urlencode, SimpleCookie 6 8 from django.test import signals … … 98 100 self.handler = ClientHandler() 99 101 self.defaults = defaults 100 102 self.cookie = SimpleCookie() 103 self.exc_info = None 101 104 102 105 def request(self, **request): 103 106 """ … … 106 109 Assumes defaults for the query environment, which can be overridden 107 110 using the arguments to the request. 108 111 """ 112 self.exc_info = None 109 113 110 114 environ = { 111 115 'HTTP_COOKIE': self.cookie, … … 126 130 on_template_render = curry(store_rendered_templates, data) 127 131 dispatcher.connect(on_template_render, signal=signals.template_rendered) 128 132 133 # Capture exceptions created by the handler 134 dispatcher.connect(self.store_exc_info, signal=got_request_exception) 135 129 136 response = self.handler(environ) 130 137 131 138 # Add any rendered template detail to the response … … 143 150 if response.cookies: 144 151 self.cookie.update(response.cookies) 145 152 153 # Look for a signalled exception and reraise it 154 if self.exc_info: 155 raise self.exc_info[1], None, self.exc_info[2] 156 146 157 return response 147 158 148 159 def get(self, path, data={}, **extra): … … 214 242 215 243 # Since we are logged in, request the actual page again 216 244 return self.get(path) 245 246 def store_exc_info(self, *args, **kwargs): 247 self.exc_info = sys.exc_info()