Ejemplo n.º 1
0
 def test_format_invalid_default(self):
     with self.assertRaises(InvalidICUParameters):
         trans_html(
             default_locale,
             mock_message_id,
             default="Hello {a} {0} {b}",
             parameters={"a": "you", "0": "!", "b": "2"},
         ),
Ejemplo n.º 2
0
 def test_trans_escapes_tag_attrs(self):
     self.assertEqual(
         trans_html(
             default_locale,
             mock_message_id,
             default="<a0>Hello</a0>",
             tags={"a0": {"tag": "a", "attrs": {"href": "/you?a=b&c=d"}}},
         ),
         '<a href="/you?a=b&amp;c=d">Hello</a>',
     )
Ejemplo n.º 3
0
 def test_trans_params(self):
     self.assertEqual(
         trans_html(
             default_locale,
             mock_message_id,
             default="Hello {a} {param_b} {c}!",
             parameters={"param_b": "there", "a": "you", "d": "tester"},
         ),
         "Hello you there {c}!",
     )
Ejemplo n.º 4
0
 def test_trans_escapes_text(self):
     self.assertEqual(
         trans_html(
             default_locale,
             mock_message_id,
             default="<a0>Hello &<b>&</b></a0>>",
             tags={"a0": {"tag": "a", "attrs": {"href": "/you"}}},
         ),
         '<a href="/you">Hello &amp;&amp;</a>&gt;',
     )
Ejemplo n.º 5
0
 def test_trans_escapes_params(self):
     self.assertEqual(
         trans_html(
             default_locale,
             mock_message_id,
             default="<a0>Hello {name}</a0>{test}",
             parameters={"name": "<b>you</b>", "test": "<b>there</b>"},
             tags={"a0": {"tag": "a", "attrs": {"href": "/you"}}},
         ),
         '<a href="/you">Hello &lt;b&gt;you&lt;/b&gt;</a>&lt;b&gt;there&lt;/b&gt;',
     )
Ejemplo n.º 6
0
 def test_trans_params_in_tags(self):
     self.assertEqual(
         trans_html(
             default_locale,
             mock_message_id,
             default="<a0>Hello {name}</a0>{test}",
             parameters={"name": "you", "test": "!"},
             tags={"a0": {"tag": "a", "attrs": {"href": "/you"}}},
         ),
         '<a href="/you">Hello you</a>!',
     )
Ejemplo n.º 7
0
 def test_trans_nested_tags(self):
     self.assertEqual(
         trans_html(
             default_locale,
             mock_message_id,
             default="<a0>Hello<b0>you</b0><div>there</div></a0>",
             parameters={"a": "you"},
             tags={
                 "a0": {"tag": "a", "attrs": {"href": "/you"}},
                 "b0": {"tag": "b", "attrs": {"id": "hi"}},
             },
         ),
         '<a href="/you">Helloyouthere</a>',
     )
Ejemplo n.º 8
0
 def test_trans_tag_placeholders(self):
     self.assertEqual(
         trans_html(
             default_locale,
             mock_message_id,
             default='<span0 class="nope">Hello {first}</span0><span1></span1> {second} <a0>{a}<b></b></a0> < <a1>there<</a1>!<br /><script type="text/javascript" src="mybadscript.js"></script>',
             parameters={"a": "you", "first": "hello", "second": "&"},
             tags={
                 "a0": {"tag": "a", "attrs": {"href": "/you"}},
                 "a1": {
                     "tag": "a",
                     "attrs": {"href": "/there?a=b&c=d", "class": "red big"},
                 },
                 "span0": {"tag": "span", "attrs": {"id": "hi"}},
             },
         ),
         '<span id="hi">Hello hello</span> &amp; <a href="/you">you</a> &lt; <a class="red big" href="/there?a=b&amp;c=d">there&lt;</a>!',
     )
Ejemplo n.º 9
0
 def test_trans_tags(self):
     self.assertEqual(
         trans_html(
             default_locale,
             mock_message_id,
             default='<a0 id="nope">Hello</a0><b0>you</b0><div>there</div>',
             parameters={"a": "you"},
             tags={
                 "a0": {
                     "tag": "a",
                     "attrs": {
                         "href": "/you",
                         "class": "the test",
                         "data-target": "someid",
                     },
                 },
                 "span0": {"tag": "span", "attrs": {"id": "ignore"}},
             },
         ),
         '<a class="the test" data-target="someid" href="/you">Hello</a>youthere',
     )