summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
authorcammil <cammil@MacBook-Pro.local>2021-05-07 21:49:07 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-07-02 11:38:15 +0200
commit313c3d1aa14d80922003f841c257ec4e153f8653 (patch)
treeb7787a1f5f0d282ea7f0dfaa568d4af4f03c62a3 /tests/template_tests
parent9f3cce172f6913c5ac74272fa5fc07f847b4e112 (diff)
downloaddjango-313c3d1aa14d80922003f841c257ec4e153f8653.tar.gz
Fixed #28935 -- Fixed display of errors in extended blocks.
Get the template that caused the exception and get the exception info from that template, using the node that caused the exception.
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/templates/test_extends_block_error.html2
-rw-r--r--tests/template_tests/templates/test_extends_block_error_parent.html1
-rw-r--r--tests/template_tests/tests.py17
3 files changed, 19 insertions, 1 deletions
diff --git a/tests/template_tests/templates/test_extends_block_error.html b/tests/template_tests/templates/test_extends_block_error.html
new file mode 100644
index 0000000000..c4733747a2
--- /dev/null
+++ b/tests/template_tests/templates/test_extends_block_error.html
@@ -0,0 +1,2 @@
+{% extends "test_extends_block_error_parent.html" %}
+{% block content %}{% include "missing.html" %}{% endblock %}
diff --git a/tests/template_tests/templates/test_extends_block_error_parent.html b/tests/template_tests/templates/test_extends_block_error_parent.html
new file mode 100644
index 0000000000..cb0dbe444b
--- /dev/null
+++ b/tests/template_tests/templates/test_extends_block_error_parent.html
@@ -0,0 +1 @@
+{% block content %}{% endblock %}
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index a8f089c351..5ea026723e 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -1,11 +1,14 @@
import sys
from django.contrib.auth.models import Group
-from django.template import Context, Engine, TemplateSyntaxError
+from django.template import (
+ Context, Engine, TemplateDoesNotExist, TemplateSyntaxError,
+)
from django.template.base import UNKNOWN_SOURCE
from django.test import SimpleTestCase, override_settings
from django.urls import NoReverseMatch
from django.utils import translation
+from django.utils.html import escape
class TemplateTests(SimpleTestCase):
@@ -134,6 +137,18 @@ class TemplateTests(SimpleTestCase):
t.render(Context())
self.assertEqual(e.exception.template_debug['during'], '{% badtag %}')
+ def test_render_tag_error_in_extended_block(self):
+ """Errors in extended block are displayed correctly."""
+ e = Engine(app_dirs=True, debug=True)
+ template = e.get_template('test_extends_block_error.html')
+ context = Context()
+ with self.assertRaises(TemplateDoesNotExist) as cm:
+ template.render(context)
+ self.assertEqual(
+ cm.exception.template_debug['during'],
+ escape('{% include "missing.html" %}'),
+ )
+
def test_super_errors(self):
"""
#18169 -- NoReverseMatch should not be silence in block.super.