-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_templates.py
39 lines (29 loc) · 1.04 KB
/
test_templates.py
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
from jingo.tests.test_helpers import render
from nose.tools import eq_
def test_safe():
"""Ensure _() calls won't be escaped by Jinja2."""
txt = '<strong>Hello</strong>'
rendered = render('{{ _("%s") }}' % txt)
eq_(rendered, txt)
def test_interpolation_nonsafe():
"""Ensure '_() % something' is not safe."""
tpl = '{{ _("Hello %s") % "<p>" }}'
rendered = render(tpl)
eq_(rendered, 'Hello <p>')
def test_format_nonsafe():
"""Ensure '_()|f(something)' is not safe."""
tpl = '{{ _("Hello {0}")|f("<p>") }}'
rendered = render(tpl)
eq_(rendered, 'Hello <p>')
def test_trans_tag():
"""Trans block with tags should not be escaped."""
s = '{% trans %}this is a <b>test</b>{% endtrans %}'
eq_(render(s), 'this is a <b>test</b>')
def test_trans_interpolation():
"""Trans block with interpolation should be escaped."""
s = """
{% trans what="<a>" %}
this is a <b>{{ what }}</b>
{% endtrans %}
""".strip()
eq_(render(s), 'this is a <b><a></b>')