diff options
| author | farhan <farhanalirazaazeemi@gmail.com> | 2025-03-21 20:06:12 +0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-04-17 08:56:53 +0200 |
| commit | 4a293eff6fb10a04de7c65ed705ca3c6a362a587 (patch) | |
| tree | 88a45a60491e846ca3983e2e1c8ba7b9cc3efe91 /tests/template_tests/syntax_tests/test_basic.py | |
| parent | 098c8bc99c84e6b09ee0066ed85b216ec63a046a (diff) | |
Fixed #28050 -- Added template name to TemplateSyntaxError.
Diffstat (limited to 'tests/template_tests/syntax_tests/test_basic.py')
| -rw-r--r-- | tests/template_tests/syntax_tests/test_basic.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/template_tests/syntax_tests/test_basic.py b/tests/template_tests/syntax_tests/test_basic.py index 50e7a4c7b1..04cf5f4401 100644 --- a/tests/template_tests/syntax_tests/test_basic.py +++ b/tests/template_tests/syntax_tests/test_basic.py @@ -1,7 +1,8 @@ -from django.template.base import TemplateSyntaxError +from django.template.base import Origin, Template, TemplateSyntaxError from django.template.context import Context from django.template.loader_tags import BlockContext, BlockNode from django.test import SimpleTestCase +from django.views.debug import ExceptionReporter from ..utils import SilentAttrClass, SilentGetItemClass, SomeClass, setup @@ -402,3 +403,29 @@ class BlockContextTests(SimpleTestCase): "<BlockContext: blocks=defaultdict(<class 'list'>, " "{'content': [<Block Node: content. Contents: []>]})>", ) + + +class TemplateNameInExceptionTests(SimpleTestCase): + template_error_msg = ( + "Invalid block tag on line 1: 'endfor'. Did you forget to register or " + "load this tag?" + ) + + def test_template_name_in_error_message(self): + msg = f"Template: test.html, {self.template_error_msg}" + with self.assertRaisesMessage(TemplateSyntaxError, msg): + Template("{% endfor %}", origin=Origin("test.html")) + + def test_template_name_not_in_debug_view(self): + try: + Template("{% endfor %}", origin=Origin("test.html")) + except TemplateSyntaxError as e: + reporter = ExceptionReporter(None, e.__class__, e, None) + traceback_data = reporter.get_traceback_data() + self.assertEqual(traceback_data["exception_value"], self.template_error_msg) + + def test_unknown_source_template(self): + try: + Template("{% endfor %}") + except TemplateSyntaxError as e: + self.assertEqual(str(e), self.template_error_msg) |
