File: test_get_language_info.py

package info (click to toggle)
python-django 3%3A5.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 61,236 kB
  • sloc: python: 361,585; javascript: 19,250; xml: 211; makefile: 182; sh: 28
file content (55 lines) | stat: -rw-r--r-- 1,928 bytes parent folder | download | duplicates (3)
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
54
55
from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from django.utils import translation

from ...utils import setup


class I18nGetLanguageInfoTagTests(SimpleTestCase):
    libraries = {
        "custom": "template_tests.templatetags.custom",
        "i18n": "django.templatetags.i18n",
    }

    # retrieving language information
    @setup(
        {
            "i18n28_2": "{% load i18n %}"
            '{% get_language_info for "de" as l %}'
            "{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}"
        }
    )
    def test_i18n28_2(self):
        output = self.engine.render_to_string("i18n28_2")
        self.assertEqual(output, "de: German/Deutsch bidi=False")

    @setup(
        {
            "i18n29": "{% load i18n %}"
            "{% get_language_info for LANGUAGE_CODE as l %}"
            "{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}"
        }
    )
    def test_i18n29(self):
        output = self.engine.render_to_string("i18n29", {"LANGUAGE_CODE": "fi"})
        self.assertEqual(output, "fi: Finnish/suomi bidi=False")

    # Test whitespace in filter arguments
    @setup(
        {
            "i18n38": "{% load i18n custom %}"
            '{% get_language_info for "de"|noop:"x y" as l %}'
            "{{ l.code }}: {{ l.name }}/{{ l.name_local }}/"
            "{{ l.name_translated }} bidi={{ l.bidi }}"
        }
    )
    def test_i18n38(self):
        with translation.override("cs"):
            output = self.engine.render_to_string("i18n38")
        self.assertEqual(output, "de: German/Deutsch/německy bidi=False")

    @setup({"template": "{% load i18n %}{% get_language_info %}"})
    def test_no_for_as(self):
        msg = "'get_language_info' requires 'for string as variable' (got [])"
        with self.assertRaisesMessage(TemplateSyntaxError, msg):
            self.engine.render_to_string("template")