Esempio n. 1
0
def test_locale_html_xss():
    """Test for nastiness-removal in the transfield's locale"""
    testfield = Mock()

    # same language: no need for attributes
    testfield.locale = '<script>alert(1)</script>'
    s = helpers.locale_html(testfield)
    assert '<script>' not in s
    assert '&lt;script&gt;alert(1)&lt;/script&gt;' in s
Esempio n. 2
0
def test_locale_html_xss():
    """Test for nastiness-removal in the transfield's locale"""
    testfield = Mock()

    # same language: no need for attributes
    testfield.locale = '<script>alert(1)</script>'
    s = helpers.locale_html(testfield)
    assert '<script>' not in s
    assert '&lt;script&gt;alert(1)&lt;/script&gt;' in s
Esempio n. 3
0
def test_locale_html():
    """Test HTML attributes for languages different than the site language"""
    testfield = Mock()

    # same language: no need for attributes
    this_lang = translation.get_language()
    testfield.locale = this_lang
    s = helpers.locale_html(testfield)
    assert not s, 'no special HTML attributes for site language'

    # non-rtl language
    testfield.locale = 'de'
    s = helpers.locale_html(testfield)
    eq_(s, ' lang="de" dir="ltr"')

    # rtl language
    for lang in settings.RTL_LANGUAGES:
        testfield.locale = lang
        s = helpers.locale_html(testfield)
        eq_(s, ' lang="%s" dir="rtl"' % testfield.locale)
Esempio n. 4
0
def test_locale_html():
    """Test HTML attributes for languages different than the site language"""
    testfield = Mock()

    # same language: no need for attributes
    this_lang = translation.get_language()
    testfield.locale = this_lang
    s = helpers.locale_html(testfield)
    assert not s, 'no special HTML attributes for site language'

    # non-rtl language
    testfield.locale = 'de'
    s = helpers.locale_html(testfield)
    assert s == ' lang="de" dir="ltr"'

    # rtl language
    for lang in settings.RTL_LANGUAGES:
        testfield.locale = lang
        s = helpers.locale_html(testfield)
        assert s == ' lang="%s" dir="rtl"' % testfield.locale
Esempio n. 5
0
def test_empty_locale_html():
    """locale_html must still work if field is None."""
    s = helpers.locale_html(None)
    assert not s, 'locale_html on None must be empty.'
Esempio n. 6
0
def test_empty_locale_html():
    """locale_html must still work if field is None."""
    s = helpers.locale_html(None)
    assert not s, 'locale_html on None must be empty.'