Example #1
0
 def test_external_text_link(self, get_outgoing_url_mock):
     get_outgoing_url_mock.return_value = 'http://external.url'
     s = u'<b>markup</b> http://example.com'
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(),
         u'<b>markup</b> <a rel="nofollow" '
         u'href="http://external.url">http://example.com</a>')
Example #2
0
def test_cache_key():
    # Test that we are not taking the db into account when building our
    # cache keys for django-cache-machine. See bug 928881.
    eq_(Translation._cache_key(1, 'default'),
        Translation._cache_key(1, 'slave'))

    # Test that we are using the same cache no matter what Translation class
    # we use.
    eq_(PurifiedTranslation._cache_key(1, 'default'),
        Translation._cache_key(1, 'default'))
    eq_(LinkifiedTranslation._cache_key(1, 'default'),
        Translation._cache_key(1, 'default'))
Example #3
0
 def test_newlines_empty_tag_nested(self):
     before = ("This is a <b><i></i></b> test!")
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #4
0
 def test_newlines_inline(self):
     before = ("If we end a paragraph w/ a <b>non-block-level tag</b>\n\n"
               "<b>The newlines</b> should be kept")
     after = before  # Should stay the same
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #5
0
 def test_internal_link(self):
     s = u'<b>markup</b> <a href="http://addons.mozilla.org/foo">bar</a>'
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(),
         u'<b>markup</b> <a href="http://addons.mozilla.org/foo">bar</a>')
Example #6
0
 def test_allowed_tags(self):
     s = u'<b>bold text</b> or <code>code</code>'
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(), u'<b>bold text</b> or <code>code</code>')
Example #7
0
 def test_output(self):
     assert isinstance(PurifiedTranslation().__html__(), unicode)
Example #8
0
 def test_newlines_less_than_tight(self):
     before = "abc 3<5 def"
     after = "abc 3&lt;5 def"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #9
0
 def test_newlines_attribute_link_doublequote(self):
     before = '<a href="http://google.com">test</a>'
     after = '<a href="http://google.com">test</a>'
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #10
0
 def test_newlines_nested_inline(self):
     before = "<b>\nThis line is bold.\n\n<i>This is also italic</i></b>"
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #11
0
 def test_newlines_spaced_inline(self):
     before = "Line.\n\n<b>\nThis line is bold.\n</b>\n\nThis isn't."
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #12
0
 def test_newlines_spaced_blocks(self):
     before = ("<blockquote>\n\n<ul>\n\n<li>\n\ntest\n\n</li>\n\n"
               "</ul>\n\n</blockquote>")
     after = "<blockquote><ul><li>test</li></ul></blockquote>"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #13
0
 def test_newlines_li_all_inline(self):
     before = ("Test with <b>no newlines</b> and <code>block level "
               "stuff</code> to see what happens.")
     after = before  # Should stay the same
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #14
0
 def test_newlines_li_newlines_inline(self):
     before = ("<ul><li>\n<b>test\ntest\n\ntest</b>\n</li>"
               "<li>Test <b>test</b> test.</li></ul>")
     after = ("<ul><li><b>test\ntest\n\ntest</b></li>"
              "<li>Test <b>test</b> test.</li></ul>")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #15
0
 def test_newlines_empty_tag_block_nested_spaced(self):
     before = ("Test.\n\n<blockquote>\n\n<ul>\n\n<li>"
               "</li>\n\n</ul>\n\n</blockquote>\ntest.")
     after = ("Test.\n\n<blockquote><ul><li></li></ul></blockquote>test.")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #16
0
 def test_allowed_tags(self):
     s = u'<b>bold text</b> or <code>code</code>'
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(), u'<b>bold text</b> or <code>code</code>')
Example #17
0
 def test_internal_link(self):
     s = u'<b>markup</b> <a href="http://addons.mozilla.org/foo">bar</a>'
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(),
         u'<b>markup</b> <a href="http://addons.mozilla.org/foo">bar</a>')
Example #18
0
 def test_newlines_xss_script(self):
     before = "<script>\n\nalert('test');\n</script>"
     after = "&lt;script&gt;\n\nalert('test');\n&lt;/script&gt;"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #19
0
 def test_newlines_less_than(self):
     before = "3 < 5"
     after = "3 &lt; 5"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #20
0
 def test_newlines_xss_inline(self):
     before = "<b onclick=\"alert('test');\">test</b>"
     after = "<b>test</b>"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #21
0
 def test_external_text_link(self):
     s = u'<b>markup</b> http://example.com'
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(),
         u'<b>markup</b> '
         u'<a href="http://example.com">http://example.com</a>')
Example #22
0
 def test_newlines_attribute_link_doublequote(self, mock_get_outgoing_url):
     mock_get_outgoing_url.return_value = 'http://google.com'
     before = '<a href="http://google.com">test</a>'
     after = '<a rel="nofollow" href="http://google.com">test</a>'
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #23
0
 def test_raw_text(self):
     s = u'   This is some text   '
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(), 'This is some text')
Example #24
0
 def test_newlines_attribute_doublequote(self):
     before = '<abbr title="laugh out loud">lol</abbr>'
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #25
0
 def test_forbidden_tags(self):
     s = u'<script>some naughty xss</script>'
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(), '&lt;script&gt;some naughty xss&lt;/script&gt;')
Example #26
0
 def test_newlines_attribute_nestedquotes_singledouble(self):
     before = '<abbr title=\'laugh "out" loud\'>lol</abbr>'
     after = before
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #27
0
 def test_external_text_link(self):
     s = u'<b>markup</b> http://example.com'
     x = PurifiedTranslation(localized_string=s)
     eq_(
         x.__html__(), u'<b>markup</b> '
         u'<a href="http://example.com">http://example.com</a>')
Example #28
0
 def test_newlines_unclosed_b_wrapped(self):
     before = ("This is a <b>test")
     after = ("This is a <b>test</b>")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #29
0
 def test_newlines_code_inline(self):
     before = ("Code tags aren't blocks.\n\n"
               "<code>alert(test);</code>\n\n"
               "See?")
     after = before  # Should stay the same
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #30
0
 def test_newlines_unclosed_li(self):
     before = ("<ul><li>test</ul>")
     after = ("<ul><li>test</li></ul>")
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #31
0
 def test_raw_text(self):
     s = u'   This is some text   '
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(), 'This is some text')
Example #32
0
 def test_newlines_correct_faketag(self):
     before = "<madonna>"
     after = "&lt;madonna&gt;"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #33
0
 def test_forbidden_tags(self):
     s = u'<script>some naughty xss</script>'
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(), '&lt;script&gt;some naughty xss&lt;/script&gt;')
Example #34
0
 def test_newlines_malformed_tag(self):
     before = "<strong"
     after = ""
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #35
0
 def test_newlines_malformed_tag_surrounded(self):
     before = "This is a <strong of bleach"
     after = "This is a"
     eq_(PurifiedTranslation(localized_string=before).__html__(), after)
Example #36
0
def test_truncate_purified_field():
    s = '<i>one</i><i>two</i>'
    t = PurifiedTranslation(localized_string=s)
    actual = jingo.env.from_string('{{ s|truncate(6) }}').render({'s': t})
    eq_(actual, s)