diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-02-11 00:23:31 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-02-11 00:23:31 +0000 |
| commit | f9cdde0cb41851e9d1eb70bd108debb75f267585 (patch) | |
| tree | b8f45306df30bccc5e10d1e8fd6f052764b201b7 /django | |
| parent | 23272de5dbc9429180e309883ffd021026bd4921 (diff) | |
Fixed #3162 -- Added coded to catch and rethrow exceptions that are thrown by the views visited by the test client. Thanks, Ben <afternoon@uk2.net>.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4482 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/auth/forms.py | 1 | ||||
| -rw-r--r-- | django/test/client.py | 18 |
2 files changed, 19 insertions, 0 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 7700ec7d7a..023f9b43be 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -4,6 +4,7 @@ from django.contrib.sites.models import Site from django.template import Context, loader from django.core import validators from django import oldforms +from django.utils.translation import gettext as _ class UserCreationForm(oldforms.Manipulator): "A form that creates a user, with no privileges, from the given username and password." diff --git a/django/test/client.py b/django/test/client.py index f66b180867..ca1a04e659 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -1,7 +1,9 @@ +import sys from cStringIO import StringIO from django.conf import settings from django.core.handlers.base import BaseHandler from django.core.handlers.wsgi import WSGIRequest +from django.core.signals import got_request_exception from django.dispatch import dispatcher from django.http import urlencode, SimpleCookie from django.test import signals @@ -100,6 +102,14 @@ class Client: self.defaults = defaults self.cookies = SimpleCookie() self.session = {} + self.exc_info = None + + def store_exc_info(self, *args, **kwargs): + """ + Utility method that can be used to store exceptions when they are + generated by a view. + """ + self.exc_info = sys.exc_info() def request(self, **request): """ @@ -128,6 +138,9 @@ class Client: on_template_render = curry(store_rendered_templates, data) dispatcher.connect(on_template_render, signal=signals.template_rendered) + # Capture exceptions created by the handler + dispatcher.connect(self.store_exc_info, signal=got_request_exception) + response = self.handler(environ) # Add any rendered template detail to the response @@ -142,6 +155,11 @@ class Client: else: setattr(response, detail, None) + # Look for a signalled exception and reraise it + if self.exc_info: + raise self.exc_info[1], None, self.exc_info[2] + + # Update persistent cookie and session data if response.cookies: self.cookies.update(response.cookies) |
