blob: 57c4fdb5e69c75a739f0db0ebc92ea97fb15724f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
from django.template import Template, TemplateDoesNotExist, TemplateSyntaxError
from django.test import SimpleTestCase
from ..utils import setup
from .test_extends import inheritance_templates
class ExceptionsTests(SimpleTestCase):
@setup({"exception01": "{% extends 'nonexistent' %}"})
def test_exception01(self):
"""
Raise exception for invalid template name
"""
with self.assertRaises(TemplateDoesNotExist):
self.engine.render_to_string("exception01")
@setup({"exception02": "{% extends nonexistent %}"})
def test_exception02(self):
"""
Raise exception for invalid variable template name
"""
if self.engine.string_if_invalid:
with self.assertRaises(TemplateDoesNotExist):
self.engine.render_to_string("exception02")
else:
with self.assertRaises(TemplateSyntaxError):
self.engine.render_to_string("exception02")
@setup(
{
"exception03": "{% extends 'inheritance01' %}"
"{% block first %}2{% endblock %}{% extends 'inheritance16' %}"
},
inheritance_templates,
)
def test_exception03(self):
"""
Raise exception for extra {% extends %} tags
"""
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template("exception03")
@setup(
{
"exception04": (
"{% extends 'inheritance17' %}{% block first %}{% echo 400 %}5678"
"{% endblock %}"
)
},
inheritance_templates,
)
def test_exception04(self):
"""
Raise exception for custom tags used in child with {% load %} tag in
parent, not in child
"""
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template("exception04")
@setup({"exception05": "{% block first %}{{ block.super }}{% endblock %}"})
def test_exception05(self):
"""
Raise exception for block.super used in base template
"""
with self.assertRaises(TemplateSyntaxError):
self.engine.render_to_string("exception05")
def test_unknown_origin_relative_path(self):
files = ["./nonexistent.html", "../nonexistent.html"]
for template_name in files:
with self.subTest(template_name=template_name):
msg = (
f"The relative path '{template_name}' cannot be evaluated due to "
"an unknown template origin."
)
with self.assertRaisesMessage(TemplateSyntaxError, msg):
Template(f"{{% extends '{template_name}' %}}")
|