Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/template_tests/filter_tests/test_rjust.py
blob: 1926b49e38beb769b4f66237a1536309102ceb63 (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
from django.template.defaultfilters import rjust
from django.test import SimpleTestCase
from django.utils.safestring import mark_safe

from ..utils import setup


class RjustTests(SimpleTestCase):

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

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


class FunctionTests(SimpleTestCase):

    def test_rjust(self):
        self.assertEqual(rjust('test', 10), '      test')

    def test_less_than_string_length(self):
        self.assertEqual(rjust('test', 3), 'test')

    def test_non_string_input(self):
        self.assertEqual(rjust(123, 4), ' 123')