Fixed #8136: Added a signal emission when an error is raised handling an error. This was required for the test client to handle missing 404.html templates and errors in the 404.html template. Thanks to danfairs for the report and fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8464 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2008-08-22 13:59:41 +00:00
parent 462ee405fb
commit e054295fed
3 changed files with 35 additions and 1 deletions

View File

@ -112,7 +112,10 @@ class BaseHandler(object):
callback, param_dict = resolver.resolve404() callback, param_dict = resolver.resolve404()
return callback(request, **param_dict) return callback(request, **param_dict)
except: except:
return self.handle_uncaught_exception(request, resolver, sys.exc_info()) try:
return self.handle_uncaught_exception(request, resolver, sys.exc_info())
finally:
receivers = signals.got_request_exception.send(sender=self.__class__, request=request)
except exceptions.PermissionDenied: except exceptions.PermissionDenied:
return http.HttpResponseForbidden('<h1>Permission denied</h1>') return http.HttpResponseForbidden('<h1>Permission denied</h1>')
except SystemExit: except SystemExit:

View File

@ -0,0 +1,3 @@
{% block foo %}
This template is deliberately bad - we want it to raise an exception when it is used.

View File

@ -1,10 +1,13 @@
""" """
Regression tests for the Test Client, especially the customized assertions. Regression tests for the Test Client, especially the customized assertions.
""" """
import os
from django.conf import settings
from django.test import Client, TestCase from django.test import Client, TestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.exceptions import SuspiciousOperation from django.core.exceptions import SuspiciousOperation
from django.template import TemplateDoesNotExist, TemplateSyntaxError
class AssertContainsTests(TestCase): class AssertContainsTests(TestCase):
def test_contains(self): def test_contains(self):
@ -307,6 +310,31 @@ class ExceptionTests(TestCase):
except SuspiciousOperation: except SuspiciousOperation:
self.fail("Staff should be able to visit this page") self.fail("Staff should be able to visit this page")
class TemplateExceptionTests(TestCase):
def setUp(self):
self.old_templates = settings.TEMPLATE_DIRS
settings.TEMPLATE_DIRS = ()
def tearDown(self):
settings.TEMPLATE_DIRS = self.old_templates
def test_no_404_template(self):
"Missing templates are correctly reported by test client"
try:
response = self.client.get("/no_such_view/")
self.fail("Should get error about missing template")
except TemplateDoesNotExist:
pass
def test_bad_404_template(self):
"Errors found when rendering 404 error templates are re-raised"
settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'bad_templates'),)
try:
response = self.client.get("/no_such_view/")
self.fail("Should get error about syntax error in template")
except TemplateSyntaxError:
pass
# We need two different tests to check URLconf substitution - one to check # We need two different tests to check URLconf substitution - one to check
# it was changed, and another one (without self.urls) to check it was reverted on # it was changed, and another one (without self.urls) to check it was reverted on
# teardown. This pair of tests relies upon the alphabetical ordering of test execution. # teardown. This pair of tests relies upon the alphabetical ordering of test execution.