Esempio n. 1
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)
     doc = pq(x.__html__())
     links = doc('a[href="http://addons.mozilla.org/foo"][rel="nofollow"]')
     assert links[0].text == 'bar'
     assert doc('b')[0].text == 'markup'
Esempio n. 2
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 href="http://external.url" '
         u'rel="nofollow">http://example.com</a>')
Esempio n. 3
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" '
         u'rel="nofollow">bar</a>')
Esempio n. 4
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>')
Esempio n. 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)
     doc = pq(x.__html__())
     links = doc('a[href="http://addons.mozilla.org/foo"][rel="nofollow"]')
     assert links[0].text == 'bar'
     assert doc('b')[0].text == 'markup'
Esempio n. 6
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)
     doc = pq(x.__html__())
     links = doc('a[href="http://external.url"][rel="nofollow"]')
     assert links[0].text == 'http://example.com'
     assert doc('b')[0].text == 'markup'
Esempio n. 7
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)
     doc = pq(x.__html__())
     links = doc('a[href="http://external.url"][rel="nofollow"]')
     assert links[0].text == 'http://example.com'
     assert doc('b')[0].text == 'markup'
Esempio n. 8
0
def test_truncate_purified_field_xss():
    """Truncating should not introduce xss issues."""
    s = 'safe <script>alert("omg")</script>'
    t = PurifiedTranslation(localized_string=s)
    actual = jingo.env.from_string('{{ s|truncate(100) }}').render(s=t)
    eq_(actual, 'safe &lt;script&gt;alert("omg")&lt;/script&gt;')
    actual = jingo.env.from_string('{{ s|truncate(5) }}').render(s=t)
    eq_(actual, 'safe ...')
Esempio n. 9
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'))
Esempio n. 10
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'))
Esempio n. 11
0
 def test_raw_text(self):
     s = u'   This is some text   '
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(), 'This is some text')
Esempio n. 12
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;')
Esempio n. 13
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>')
Esempio n. 14
0
 def test_raw_text(self):
     s = u'   This is some text   '
     x = PurifiedTranslation(localized_string=s)
     eq_(x.__html__(), 'This is some text')
Esempio n. 15
0
 def test_output(self):
     assert isinstance(PurifiedTranslation().__html__(), unicode)
Esempio n. 16
0
def test_purified_translation_html():
    """__html__() should return a string."""
    s = u'<b>heyhey</b>'
    x = PurifiedTranslation(localized_string=s)
    assert isinstance(x.__html__(), unicode)
    eq_(x.__html__(), s)
Esempio n. 17
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>')
Esempio n. 18
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;')
Esempio n. 19
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)
Esempio n. 20
0
def test_purified_translation_html():
    """__html__() should return a string."""
    s = u'<b>heyhey</b>'
    x = PurifiedTranslation(localized_string=s)
    assert isinstance(x.__html__(), unicode)
    eq_(x.__html__(), s)
Esempio n. 21
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" '
         u'rel="nofollow">bar</a>')