-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_template_validator.py
More file actions
53 lines (41 loc) · 1.75 KB
/
test_template_validator.py
File metadata and controls
53 lines (41 loc) · 1.75 KB
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
from django.core.exceptions import ValidationError
from django.test import TestCase
from common.validators import TemplateValidator
class TemplateValidatorTest(TestCase):
def test_empty_template(self):
validator = TemplateValidator()
value = ""
validator(value)
def test_syntax_error(self):
validator = TemplateValidator()
value = "{{ }}"
with self.assertRaises(ValidationError) as cm:
validator(value)
self.assertEqual(cm.exception.message, "Empty variable tag on line 1")
def test_invalid_tag_syntax(self):
validator = TemplateValidator()
value = "{% now %}"
with self.assertRaises(ValidationError) as cm:
validator(value)
self.assertEqual(cm.exception.message, "'now' statement takes one argument")
def test_allowed_builtin_tag(self):
validator = TemplateValidator()
value = '{% now "jS F Y H:i" %}'
validator(value)
def test_disallowed_builtin_tag(self):
validator = TemplateValidator()
value = "{% load statistics_tags %}"
expected_msg = "{} tags are not allowed".format(
", ".join(TemplateValidator.disallowed_tags)
)
with self.assertRaises(ValidationError) as cm:
validator(value)
self.assertEqual(cm.exception.message, expected_msg)
def test_allows_statistics_tag(self):
validator = TemplateValidator()
value = "{% num_incidents %}"
validator(value)
def test_should_unescape_html_quotations(self):
validator = TemplateValidator()
value = "<p>{% num_journalist_targets categories=10 date_lower="2019-01-01" %} journalists have faced physical attacks in 2019</p>"
validator(value)