Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/template_tests/filter_tests/test_make_list.py
blob: 16db76057fd9dd7b10a19df24c1ee6c6b3f0b0af (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
from django.template.defaultfilters import make_list
from django.test import SimpleTestCase
from django.test.utils import str_prefix
from django.utils.safestring import mark_safe

from ..utils import setup


class MakeListTests(SimpleTestCase):
    """
    The make_list filter can destroy existing escaping, so the results are
    escaped.
    """

    @setup({'make_list01': '{% autoescape off %}{{ a|make_list }}{% endautoescape %}'})
    def test_make_list01(self):
        output = self.engine.render_to_string('make_list01', {"a": mark_safe("&")})
        self.assertEqual(output, str_prefix("[%(_)s'&']"))

    @setup({'make_list02': '{{ a|make_list }}'})
    def test_make_list02(self):
        output = self.engine.render_to_string('make_list02', {"a": mark_safe("&")})
        self.assertEqual(output, str_prefix("[%(_)s'&']"))

    @setup({'make_list03':
        '{% autoescape off %}{{ a|make_list|stringformat:"s"|safe }}{% endautoescape %}'})
    def test_make_list03(self):
        output = self.engine.render_to_string('make_list03', {"a": mark_safe("&")})
        self.assertEqual(output, str_prefix("[%(_)s'&']"))

    @setup({'make_list04': '{{ a|make_list|stringformat:"s"|safe }}'})
    def test_make_list04(self):
        output = self.engine.render_to_string('make_list04', {"a": mark_safe("&")})
        self.assertEqual(output, str_prefix("[%(_)s'&']"))


class FunctionTests(SimpleTestCase):

    def test_string(self):
        self.assertEqual(make_list('abc'), ['a', 'b', 'c'])

    def test_integer(self):
        self.assertEqual(make_list(1234), ['1', '2', '3', '4'])