示例#1
0
def test_safe():
    # Test setting 'safe' parameter does what it should do
    quote_by_default = "<>"
    assert quote(quote_by_default, safe=quote_by_default) == quote_by_default

    ret = quote(quote_by_default, safe=quote_by_default, plus=True)
    assert ret == quote_by_default
示例#2
0
def test_default_quoting_partial():
    partial_quote = "ab[]cd"
    expected = "ab%5B%5Dcd"
    result = quote(partial_quote)
    assert expected == result
    result = quote(partial_quote, plus=True)
    assert expected == result
示例#3
0
def test_default_quoting(char):
    # Make sure all characters that should be quoted are by default sans
    # space (separate test for that).
    result = quote(char)
    assert hexescape(char) == result
    result = quote(char, plus=True)
    assert hexescape(char) == result
示例#4
0
def test_never_quote():
    # Make sure quote() does not quote letters, digits, and "_,.-"
    do_not_quote = ''.join([
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz",
        "0123456789", "_.-"
    ])
    assert quote(do_not_quote) == do_not_quote
    quote(do_not_quote, plus=True) == do_not_quote
示例#5
0
def test_quote_plus_with_unicode():
    # Characters in Latin-1 range, encoded by default in UTF-8
    given = "\xa2\xd8ab\xff"
    expect = "%C2%A2%C3%98ab%C3%BF"
    result = quote(given, plus=True)
    assert expect == result
    # Characters in BMP, encoded by default in UTF-8
    given = "\u6f22\u5b57"  # "Kanji"
    expect = "%E6%BC%A2%E5%AD%97"
    result = quote(given, plus=True)
    assert expect == result
示例#6
0
def test_quoting_space():
    # Make sure quote() and quote_plus() handle spaces as specified in
    # their unique way
    result = quote(' ')
    assert result == hexescape(' ')
    result = quote(' ', plus=True)
    assert result == '+'

    given = "a b cd e f"
    expect = given.replace(' ', hexescape(' '))
    result = quote(given)
    assert expect == result
    expect = given.replace(' ', '+')
    result = quote(given, plus=True)
    assert expect == result
示例#7
0
def test_default_quoting_percent():
    result = quote('%25')
    assert '%25' == result
    result = quote('%25', plus=True)
    assert '%25' == result
示例#8
0
def test_quote_from_bytes():
    assert quote('archaeological arcana') == 'archaeological%20arcana'
    assert quote('') == ''
示例#9
0
def test_bad_types():
    with pytest.raises(TypeError):
        quote(123)
    with pytest.raises(TypeError):
        unquote(123)
示例#10
0
def test_empty_string():
    assert quote('') == ''
    assert unquote('') == ''
示例#11
0
def test_None():
    assert quote(None) is None
    assert unquote(None) is None
示例#12
0
def test_quote_unfinished():
    with pytest.raises(ValueError):
        quote('%F%F')
示例#13
0
def test_quote_not_allowed():
    with pytest.raises(ValueError):
        quote('%HH')
示例#14
0
def test_quoting_plus():
    assert quote('alpha+beta gamma', plus=True) == 'alpha%2Bbeta+gamma'
    assert quote('alpha+beta gamma', safe='+', plus=True) == 'alpha+beta+gamma'