def test_tag_list(self): addon = Addon.objects.get(id=3615) request = Mock() request.user = addon.authors.all()[0].create_django_user() request.groups = () tags = addon.tags.not_blacklisted() ctx = { 'APP': amo.FIREFOX, 'LANG': 'en-us', 'request': request, 'addon': addon, 'tags': tags } # initialize jingo jingo.load_helpers() cake_csrf_token = lambda: '' cake_csrf_token.__name__ = 'cake_csrf_token' jingo.register.function(cake_csrf_token) # no tags, no list s = render('{{ tag_list(addon) }}', ctx) self.assertEqual(s.strip(), "") s = render('{{ tag_list(addon, tags=tags) }}', ctx) assert s, "Non-empty tags must return tag list." doc = pq(s) eq_(doc('li').length, len(tags))
def test_tag_list(self): addon = Addon.objects.get(id=3615) request = Mock() request.user = addon.authors.all()[0].create_django_user() request.groups = () tags = addon.tags.not_blacklisted() ctx = { 'APP': amo.FIREFOX, 'LANG': 'en-us', 'request': request, 'addon': addon, 'tags': tags } # no tags, no list s = render('{{ tag_list(addon) }}', ctx) self.assertEqual(s.strip(), "") s = render('{{ tag_list(addon, tags=tags) }}', ctx) assert s, "Non-empty tags must return tag list." doc = pq(s) eq_(doc('li').length, len(tags))
def test_tag_list(self): addon = Addon.objects.get(id=3615) request = Mock() request.user = addon.authors.all()[0].create_django_user() request.groups = () tags = addon.tags.not_blacklisted() ctx = { 'APP': amo.FIREFOX, 'LANG': 'en-us', 'request': request, 'addon': addon, 'tags': tags} # initialize jingo jingo.load_helpers() cake_csrf_token = lambda: '' cake_csrf_token.__name__ = 'cake_csrf_token' jingo.register.function(cake_csrf_token) # no tags, no list s = render('{{ tag_list(addon) }}', ctx) self.assertEqual(s.strip(), "") s = render('{{ tag_list(addon, tags=tags) }}', ctx) assert s, "Non-empty tags must return tag list." doc = pq(s) eq_(doc('li').length, len(tags))
def test_template_gettext_functions(): s = '{{ _("yy", "context") }}' eq_(render(s), "yy") s = '{{ gettext("yy", "context") }}' eq_(render(s), "yy") s = '{{ ngettext("1", "2", 1, "context") }}' eq_(render(s), "1")
def test_template_gettext_functions(): s = '{{ _("yy", "context") }}' eq_(render(s), 'yy') s = '{{ gettext("yy", "context") }}' eq_(render(s), 'yy') s = '{{ ngettext("1", "2", 1, "context") }}' eq_(render(s), '1')
def test_template_substitution(): s = '{% trans user="******" %} Hello {{ user }}{% endtrans %}' eq_(render(s), 'Hola wenzel') s = '''{% trans user="******" %} Hello \t\r\n {{ user }} {% endtrans %}''' eq_(render(s), 'Hola wenzel')
def test_template_substitution(): s = '{% trans user="******" %} Hello {{ user }}{% endtrans %}' eq_(render(s), "Hola wenzel") s = """{% trans user="******" %} Hello \t\r\n {{ user }} {% endtrans %}""" eq_(render(s), "Hola wenzel")
def test_template_simple(): s = '{% trans %}this is a test{% endtrans %}' eq_(render(s), 'you ran a test!') s = '''{% trans %} this is a test {% endtrans %}''' eq_(render(s), 'you ran a test!')
def test_tag_list(self): addon = Addon.objects.get(id=3615) request = Mock() request.user = addon.authors.all()[0].create_django_user() request.groups = () tags = addon.tags.filter(blacklisted=False) dev_tags = tags.filter(addon_tags__user__in=addon.authors.all()) user_tags = tags.exclude(addon_tags__user__in=addon.authors.all()) ctx = { 'APP': amo.FIREFOX, 'LANG': 'en-us', 'request': request, 'addon': addon, 'dev_tags': dev_tags, 'user_tags': user_tags, } # initialize jingo jingo.load_helpers() cake_csrf_token = lambda: '' cake_csrf_token.__name__ = 'cake_csrf_token' jingo.register.function(cake_csrf_token) # no tags, no list s = render('{{ tag_list(addon) }}', ctx) self.assertEqual(s.strip(), "") return # regular lists s = render('{{ tag_list(addon, dev_tags=dev_tags) }}', ctx) assert s, "Non-empty tags must return tag list." doc = pq(s) eq_(doc('li.developertag').length, len(dev_tags)) eq_(doc('li').length, len(dev_tags)) s = render('{{ tag_list(addon, user_tags=user_tags) }}', ctx) assert s, "Non-empty tags must return tag list." doc = pq(s) eq_(doc('li.usertag').length, len(user_tags)) eq_(doc('li').length, len(user_tags)) s = render("""{{ tag_list(addon, dev_tags=dev_tags, user_tags=user_tags) }}""", ctx) assert s, "Non-empty tags must return tag list." doc = pq(s) eq_(doc('li.usertag').length, len(user_tags)) eq_(doc('li.developertag').length, len(dev_tags)) eq_(doc('li').length, len(user_tags)+len(dev_tags)) # delete buttons are shown assert doc('li input.removetag').length > 0
def test_template_simple(): s = "{% trans %}this is a test{% endtrans %}" eq_(render(s), "you ran a test!") s = """{% trans %} this is a test {% endtrans %}""" eq_(render(s), "you ran a test!")
def test_template_substitution_with_pluralization(): s = '''{% trans count=1 %} one light ! {% pluralize %} many lights ! {% endtrans %}''' eq_(render(s), 'you found a light!') s = '''{% trans count=8 %} one light ! {% pluralize %} many lights ! {% endtrans %}''' eq_(render(s), 'you found a pile of lights!')
def test_template_substitution_with_pluralization(): s = """{% trans count=1 %} one light ! {% pluralize %} many lights ! {% endtrans %}""" eq_(render(s), "you found a light!") s = """{% trans count=8 %} one light ! {% pluralize %} many lights ! {% endtrans %}""" eq_(render(s), "you found a pile of lights!")
def test_trans_interpolation(): """Trans block with interpolation should be escaped.""" s = """ {% trans what="<a>" %} this is a <b>{{ what }}</b> {% endtrans %} """.strip() eq_(render(s), 'this is a <b><a></b>')
def test_tag_list(self): addon = Addon.objects.get(id=3615) request = Mock() request.user = addon.authors.all()[0].create_django_user() request.groups = () tags = addon.tags.not_blacklisted() ctx = {"APP": amo.FIREFOX, "LANG": "en-us", "request": request, "addon": addon, "tags": tags} # no tags, no list s = render("{{ tag_list(addon) }}", ctx) self.assertEqual(s.strip(), "") s = render("{{ tag_list(addon, tags=tags) }}", ctx) assert s, "Non-empty tags must return tag list." doc = pq(s) eq_(doc("li").length, len(tags))
def test_template_substitution_with_many_plural_forms(): s = '''{% trans count=1 %} There is {{ count }} monkey. {% pluralize %} There are {{ count }} monkeys. {% endtrans %}''' eq_(render(s), 'Monkey count: 1 (Plural: 0)') s = '''{% trans count=3 %} There is {{ count }} monkey. {% pluralize %} There are {{ count }} monkeys. {% endtrans %}''' eq_(render(s), 'Monkey count: 3 (Plural: 1)') s = '''{% trans count=5 %} There is {{ count }} monkey. {% pluralize %} There are {{ count }} monkeys. {% endtrans %}''' eq_(render(s), 'Monkey count: 5 (Plural: 2)')
def test_template_substitution_with_many_plural_forms(): s = """{% trans count=1 %} There is {{ count }} monkey. {% pluralize %} There are {{ count }} monkeys. {% endtrans %}""" eq_(render(s), "Monkey count: 1 (Plural: 0)") s = """{% trans count=3 %} There is {{ count }} monkey. {% pluralize %} There are {{ count }} monkeys. {% endtrans %}""" eq_(render(s), "Monkey count: 3 (Plural: 1)") s = """{% trans count=5 %} There is {{ count }} monkey. {% pluralize %} There are {{ count }} monkeys. {% endtrans %}""" eq_(render(s), "Monkey count: 5 (Plural: 2)")
def test_tag_list(self): addon = Addon.objects.get(id=3615) request = Mock() request.user = addon.authors.all()[0].create_django_user() request.groups = () tags = addon.tags.not_blacklisted() ctx = { 'APP': amo.FIREFOX, 'LANG': 'en-us', 'request': request, 'addon': addon, 'tags': tags} # no tags, no list s = render('{{ tag_list(addon) }}', ctx) self.assertEqual(s.strip(), "") s = render('{{ tag_list(addon, tags=tags) }}', ctx) assert s, "Non-empty tags must return tag list." doc = pq(s) eq_(doc('li').length, len(tags))
def test_interpolation_nonsafe(): """Ensure '_() % something' is not safe.""" tpl = '{{ _("Hello %s") % "<p>" }}' rendered = render(tpl) eq_(rendered, 'Hello <p>')
def test_trans_tag(): """Trans block with tags should not be escaped.""" s = '{% trans %}this is a <b>test</b>{% endtrans %}' eq_(render(s), 'this is a <b>test</b>')
def test_safe(): """Ensure _() calls won't be escaped by Jinja2.""" txt = '<strong>Hello</strong>' rendered = render('{{ _("%s") }}' % txt) eq_(rendered, txt)
def test_format_nonsafe(): """Ensure '_()|f(something)' is not safe.""" tpl = '{{ _("Hello {0}")|f("<p>") }}' rendered = render(tpl) eq_(rendered, 'Hello <p>')