summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2011-02-01 14:18:07 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2011-02-01 14:18:07 +0000
commit9a82eb6ff109e95dbb6cf26ee3d2ce1c548714bb (patch)
tree1938ab46e59133b4d172e21cc4f1e3a7e8e90d88 /tests/regressiontests
parent00fda7f45db2425c1dcb5d927093ede45734d841 (diff)
Fixed #14972 -- Ensure that the HTML email logger always produces useful output, regardless of whether it has been given an exception or a request. Thanks to jamstooks for the report, and bpeschier for the initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15383 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/views/tests/debug.py89
1 files changed, 88 insertions, 1 deletions
diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py
index c71e8c502d..0b07b406d0 100644
--- a/tests/regressiontests/views/tests/debug.py
+++ b/tests/regressiontests/views/tests/debug.py
@@ -1,13 +1,16 @@
import inspect
+import sys
from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile
-from django.test import TestCase
+from django.test import TestCase, RequestFactory
from django.core.urlresolvers import reverse
from django.template import TemplateSyntaxError
+from django.views.debug import ExceptionReporter
from regressiontests.views import BrokenException, except_args
+
class DebugViewTests(TestCase):
def setUp(self):
self.old_debug = settings.DEBUG
@@ -52,3 +55,87 @@ class DebugViewTests(TestCase):
def test_template_loader_postmortem(self):
response = self.client.get(reverse('raises_template_does_not_exist'))
self.assertContains(response, 'templates/i_dont_exist.html</code> (File does not exist)</li>', status_code=500)
+
+
+class ExceptionReporterTests(TestCase):
+ rf = RequestFactory()
+
+ def test_request_and_exception(self):
+ "A simple exception report can be generated"
+ try:
+ request = self.rf.get('/test_view/')
+ raise KeyError("Can't find my keys")
+ except KeyError:
+ exc_type, exc_value, tb = sys.exc_info()
+ reporter = ExceptionReporter(request, exc_type, exc_value, tb)
+ html = reporter.get_traceback_html()
+ self.assertIn('<h1>KeyError at /test_view/</h1>', html)
+ self.assertIn('<pre class="exception_value">Can&#39;t find my keys</pre>', html)
+ self.assertIn('<th>Request Method:</th>', html)
+ self.assertIn('<th>Request URL:</th>', html)
+ self.assertIn('<th>Exception Type:</th>', html)
+ self.assertIn('<th>Exception Value:</th>', html)
+ self.assertIn('<h2>Traceback ', html)
+ self.assertIn('<h2>Request information</h2>', html)
+ self.assertNotIn('<p>Request data not supplied</p>', html)
+
+ def test_no_request(self):
+ "An exception report can be generated without request"
+ try:
+ raise KeyError("Can't find my keys")
+ except KeyError:
+ exc_type, exc_value, tb = sys.exc_info()
+ reporter = ExceptionReporter(None, exc_type, exc_value, tb)
+ html = reporter.get_traceback_html()
+ self.assertIn('<h1>KeyError</h1>', html)
+ self.assertIn('<pre class="exception_value">Can&#39;t find my keys</pre>', html)
+ self.assertNotIn('<th>Request Method:</th>', html)
+ self.assertNotIn('<th>Request URL:</th>', html)
+ self.assertIn('<th>Exception Type:</th>', html)
+ self.assertIn('<th>Exception Value:</th>', html)
+ self.assertIn('<h2>Traceback ', html)
+ self.assertIn('<h2>Request information</h2>', html)
+ self.assertIn('<p>Request data not supplied</p>', html)
+
+ def test_no_exception(self):
+ "An exception report can be generated for just a request"
+ request = self.rf.get('/test_view/')
+ reporter = ExceptionReporter(request, None, None, None)
+ html = reporter.get_traceback_html()
+ self.assertIn('<h1>Report at /test_view/</h1>', html)
+ self.assertIn('<pre class="exception_value">No exception supplied</pre>', html)
+ self.assertIn('<th>Request Method:</th>', html)
+ self.assertIn('<th>Request URL:</th>', html)
+ self.assertNotIn('<th>Exception Type:</th>', html)
+ self.assertNotIn('<th>Exception Value:</th>', html)
+ self.assertNotIn('<h2>Traceback ', html)
+ self.assertIn('<h2>Request information</h2>', html)
+ self.assertNotIn('<p>Request data not supplied</p>', html)
+
+ def test_request_and_message(self):
+ "A message can be provided in addition to a request"
+ request = self.rf.get('/test_view/')
+ reporter = ExceptionReporter(request, None, "I'm a little teapot", None)
+ html = reporter.get_traceback_html()
+ self.assertIn('<h1>Report at /test_view/</h1>', html)
+ self.assertIn('<pre class="exception_value">I&#39;m a little teapot</pre>', html)
+ self.assertIn('<th>Request Method:</th>', html)
+ self.assertIn('<th>Request URL:</th>', html)
+ self.assertNotIn('<th>Exception Type:</th>', html)
+ self.assertNotIn('<th>Exception Value:</th>', html)
+ self.assertNotIn('<h2>Traceback ', html)
+ self.assertIn('<h2>Request information</h2>', html)
+ self.assertNotIn('<p>Request data not supplied</p>', html)
+
+ def test_message_only(self):
+ reporter = ExceptionReporter(None, None, "I'm a little teapot", None)
+ html = reporter.get_traceback_html()
+ self.assertIn('<h1>Report</h1>', html)
+ self.assertIn('<pre class="exception_value">I&#39;m a little teapot</pre>', html)
+ self.assertNotIn('<th>Request Method:</th>', html)
+ self.assertNotIn('<th>Request URL:</th>', html)
+ self.assertNotIn('<th>Exception Type:</th>', html)
+ self.assertNotIn('<th>Exception Value:</th>', html)
+ self.assertNotIn('<h2>Traceback ', html)
+ self.assertIn('<h2>Request information</h2>', html)
+ self.assertIn('<p>Request data not supplied</p>', html)