Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit e054295fed6a19a4e68fb50e71e0e57305a6770d 1 parent 462ee40
Russell Keith-Magee authored August 22, 2008
5  django/core/handlers/base.py
@@ -112,7 +112,10 @@ def get_response(self, request):
112 112
                     callback, param_dict = resolver.resolve404()
113 113
                     return callback(request, **param_dict)
114 114
                 except:
115  
-                    return self.handle_uncaught_exception(request, resolver, sys.exc_info())
  115
+                    try:
  116
+                        return self.handle_uncaught_exception(request, resolver, sys.exc_info())
  117
+                    finally:
  118
+                        receivers = signals.got_request_exception.send(sender=self.__class__, request=request)
116 119
         except exceptions.PermissionDenied:
117 120
             return http.HttpResponseForbidden('<h1>Permission denied</h1>')
118 121
         except SystemExit:
3  tests/regressiontests/test_client_regress/bad_templates/404.html
... ...
@@ -0,0 +1,3 @@
  1
+{% block foo %}
  2
+
  3
+This template is deliberately bad - we want it to raise an exception when it is used.
28  tests/regressiontests/test_client_regress/models.py
... ...
@@ -1,10 +1,13 @@
1 1
 """
2 2
 Regression tests for the Test Client, especially the customized assertions.
3 3
 """
  4
+import os
  5
+from django.conf import settings
4 6
 
5 7
 from django.test import Client, TestCase
6 8
 from django.core.urlresolvers import reverse
7 9
 from django.core.exceptions import SuspiciousOperation
  10
+from django.template import TemplateDoesNotExist, TemplateSyntaxError
8 11
 
9 12
 class AssertContainsTests(TestCase):
10 13
     def test_contains(self):
@@ -306,7 +309,32 @@ def test_exception_cleared(self):
306 309
             self.client.get("/test_client_regress/staff_only/")
307 310
         except SuspiciousOperation:
308 311
             self.fail("Staff should be able to visit this page")
  312
+    
  313
+class TemplateExceptionTests(TestCase):
  314
+    def setUp(self):
  315
+        self.old_templates = settings.TEMPLATE_DIRS
  316
+        settings.TEMPLATE_DIRS = ()
  317
+        
  318
+    def tearDown(self):
  319
+        settings.TEMPLATE_DIRS = self.old_templates
  320
+        
  321
+    def test_no_404_template(self):
  322
+        "Missing templates are correctly reported by test client"    
  323
+        try:
  324
+            response = self.client.get("/no_such_view/")
  325
+            self.fail("Should get error about missing template")
  326
+        except TemplateDoesNotExist:
  327
+            pass
309 328
 
  329
+    def test_bad_404_template(self):
  330
+        "Errors found when rendering 404 error templates are re-raised"
  331
+        settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'bad_templates'),)
  332
+        try:
  333
+            response = self.client.get("/no_such_view/")
  334
+            self.fail("Should get error about syntax error in template")
  335
+        except TemplateSyntaxError:
  336
+            pass
  337
+        
310 338
 # We need two different tests to check URLconf substitution -  one to check
311 339
 # it was changed, and another one (without self.urls) to check it was reverted on
312 340
 # teardown. This pair of tests relies upon the alphabetical ordering of test execution.

0 notes on commit e054295

Please sign in to comment.
Something went wrong with that request. Please try again.