summaryrefslogtreecommitdiff
path: root/tests/view_tests
diff options
context:
space:
mode:
authorGiebisch <rafael@giebisch-mail.de>2022-11-21 16:54:57 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-11-25 08:16:10 +0100
commit80c66e40f7beecbd5ee501f757a2e61236597349 (patch)
tree26d3bc257e6f379894a103406a7e80d9dd3f953d /tests/view_tests
parent70c945d6b31b41b320e57088702077864428fdc0 (diff)
downloaddjango-80c66e40f7beecbd5ee501f757a2e61236597349.tar.gz
Fixed #33747 -- Added exception notes to the technical 500 debug page.
Diffstat (limited to 'tests/view_tests')
-rw-r--r--tests/view_tests/tests/test_debug.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index 7224a2b6b6..a9b7625617 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -7,7 +7,7 @@ import tempfile
import threading
from io import StringIO
from pathlib import Path
-from unittest import mock, skipIf
+from unittest import mock, skipIf, skipUnless
from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile
@@ -22,6 +22,7 @@ from django.urls.converters import IntConverter
from django.utils.functional import SimpleLazyObject
from django.utils.regex_helper import _lazy_re_compile
from django.utils.safestring import mark_safe
+from django.utils.version import PY311
from django.views.debug import (
CallableSettingWrapper,
ExceptionCycleWarning,
@@ -659,6 +660,40 @@ class ExceptionReporterTests(SimpleTestCase):
text,
)
+ @skipUnless(PY311, "Exception notes were added in Python 3.11.")
+ def test_exception_with_notes(self):
+ request = self.rf.get("/test_view/")
+ try:
+ try:
+ raise RuntimeError("Oops")
+ except Exception as err:
+ err.add_note("First Note")
+ err.add_note("Second Note")
+ err.add_note(mark_safe("<script>alert(1);</script>"))
+ raise err
+ except Exception:
+ exc_type, exc_value, tb = sys.exc_info()
+
+ reporter = ExceptionReporter(request, exc_type, exc_value, tb)
+ html = reporter.get_traceback_html()
+ self.assertIn(
+ '<pre class="exception_value">Oops\nFirst Note\nSecond Note\n'
+ "&lt;script&gt;alert(1);&lt;/script&gt;</pre>",
+ html,
+ )
+ self.assertIn(
+ "Exception Value: Oops\nFirst Note\nSecond Note\n"
+ "&lt;script&gt;alert(1);&lt;/script&gt;",
+ html,
+ )
+
+ text = reporter.get_traceback_text()
+ self.assertIn(
+ "Exception Value: Oops\nFirst Note\nSecond Note\n"
+ "<script>alert(1);</script>",
+ text,
+ )
+
def test_mid_stack_exception_without_traceback(self):
try:
try: