py-cvs-rel2_1 (Rev 1.2) merge
[python/dscho.git] / Lib / test / test_cookie.py
blob40c881ff1677364c4f22b4edbd39fbed95814675
1 # 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
8 # Currently this only tests SimpleCookie
10 cases = [
11 ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
12 ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
13 {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
15 # Check illegal cookies that have an '=' char in an unquoted value
16 ('keebler=E=mc2;', {'keebler' : 'E=mc2'})
19 for data, dict in cases:
20 C = Cookie.SimpleCookie() ; C.load(data)
21 print repr(C)
22 print str(C)
23 items = dict.items()
24 items.sort()
25 for k, v in items:
26 print ' ', k, repr( C[k].value ), repr(v)
27 verify(C[k].value == v)
28 print C[k]
30 C = Cookie.SimpleCookie()
31 C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
33 verify(C['Customer'].value == 'WILE_E_COYOTE')
34 verify(C['Customer']['version'] == '1')
35 verify(C['Customer']['path'] == '/acme')
37 print C.output(['path'])
38 print C.js_output()
39 print C.js_output(['path'])
41 # Try cookie with quoted meta-data
42 C = Cookie.SimpleCookie()
43 C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
44 verify(C['Customer'].value == 'WILE_E_COYOTE')
45 verify(C['Customer']['version'] == '1')
46 verify(C['Customer']['path'] == '/acme')
48 print "If anything blows up after this line, it's from Cookie's doctest."
49 doctest.testmod(Cookie)