test_cookie.py 1.34 KB
Newer Older
1 2
# Simple test suite for Cookie.py

3
from test_support import verify
4
import Cookie
5
from test_support import verify, verbose
6
import doctest
7 8 9 10 11 12

# Currently this only tests SimpleCookie

cases = [
    ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
    ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
13
     {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
14 15 16

    # Check illegal cookies that have an '=' char in an unquoted value
    ('keebler=E=mc2;', {'keebler' : 'E=mc2'})
17
    ]
18 19 20

for data, dict in cases:
    C = Cookie.SimpleCookie() ; C.load(data)
21 22
    print repr(C)
    print str(C)
23 24
    for k, v in dict.items():
        print ' ', k, repr( C[k].value ), repr(v)
25
        verify(C[k].value == v)
26
        print C[k]
27 28 29 30

C = Cookie.SimpleCookie()
C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')

31 32 33
verify(C['Customer'].value == 'WILE_E_COYOTE')
verify(C['Customer']['version'] == '1')
verify(C['Customer']['path'] == '/acme')
34 35 36 37 38

print C.output(['path'])
print C.js_output()
print C.js_output(['path'])

39 40 41
# Try cookie with quoted meta-data
C = Cookie.SimpleCookie()
C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
42 43 44
verify(C['Customer'].value == 'WILE_E_COYOTE')
verify(C['Customer']['version'] == '1')
verify(C['Customer']['path'] == '/acme')
45 46 47

print "If anything blows up after this line, it's from Cookie's doctest."
doctest.testmod(Cookie)