Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/template_tests/filter_tests/test_center.py
blob: 306de331017fe4112846077750fa9c1e0f6be8f3 (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
from django.template.defaultfilters import center
from django.test import SimpleTestCase
from django.utils.safestring import mark_safe

from ..utils import setup


class CenterTests(SimpleTestCase):

    @setup({'center01':
        '{% autoescape off %}.{{ a|center:"5" }}. .{{ b|center:"5" }}.{% endautoescape %}'})
    def test_center01(self):
        output = self.engine.render_to_string('center01', {"a": "a&b", "b": mark_safe("a&b")})
        self.assertEqual(output, ". a&b . . a&b .")

    @setup({'center02': '.{{ a|center:"5" }}. .{{ b|center:"5" }}.'})
    def test_center02(self):
        output = self.engine.render_to_string('center02', {"a": "a&b", "b": mark_safe("a&b")})
        self.assertEqual(output, ". a&b . . a&b .")


class FunctionTests(SimpleTestCase):

    def test_center(self):
        self.assertEqual(center('test', 6), ' test ')

    def test_non_string_input(self):
        self.assertEqual(center(123, 5), ' 123 ')