summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLuca Ferroni <luca@befair.it>2015-04-19 15:30:01 +0200
committerTim Graham <timograham@gmail.com>2015-05-29 11:29:32 -0400
commit38eacbde62cd83ffaa64db7719c2c643f69551e0 (patch)
treeeca7f7f21591286280790b6c0da7a1d509066365 /tests
parent24718b7dccd64dfa118fe8136e7b175babec679b (diff)
Refs #23643 -- Fixed debug view regression on Python 2.
Thanks Tomáš Ehrlich for help with the patch.
Diffstat (limited to 'tests')
-rw-r--r--tests/view_tests/tests/test_debug.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index ac8cbcdb11..4f3a9d6161 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -14,13 +14,16 @@ from unittest import skipIf
from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse
+from django.db import DatabaseError, connection
from django.template import TemplateDoesNotExist
from django.test import RequestFactory, SimpleTestCase, override_settings
from django.test.utils import LoggingCaptureMixin
from django.utils import six
from django.utils.encoding import force_bytes, force_text
from django.utils.functional import SimpleLazyObject
-from django.views.debug import CallableSettingWrapper, ExceptionReporter
+from django.views.debug import (
+ CallableSettingWrapper, ExceptionReporter, technical_500_response,
+)
from .. import BrokenException, except_args
from ..views import (
@@ -194,6 +197,26 @@ class DebugViewTests(LoggingCaptureMixin, SimpleTestCase):
)
+class DebugViewQueriesAllowedTests(SimpleTestCase):
+ # May need a query to initialize MySQL connection
+ allow_database_queries = True
+
+ def test_handle_db_exception(self):
+ """
+ Ensure the debug view works when a database exception is raised by
+ performing an invalid query and passing the exception to the debug view.
+ """
+ with connection.cursor() as cursor:
+ try:
+ cursor.execute('INVALID SQL')
+ except DatabaseError:
+ exc_info = sys.exc_info()
+
+ rf = RequestFactory()
+ response = technical_500_response(rf.get('/'), *exc_info)
+ self.assertContains(response, 'OperationalError at /', status_code=500)
+
+
@override_settings(
DEBUG=True,
ROOT_URLCONF="view_tests.urls",