append(): Fixing the test for convertability after consultation with
[python/dscho.git] / Lib / test / test_cookie.py
blob35befb209a0e63378ad98882c39f2fde11c0e968
1 # Simple test suite for Cookie.py
3 from test.test_support import verify, verbose, run_doctest
4 import Cookie
6 # Currently this only tests SimpleCookie
8 cases = [
9 ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
10 ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
11 {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
13 # Check illegal cookies that have an '=' char in an unquoted value
14 ('keebler=E=mc2;', {'keebler' : 'E=mc2'})
17 for data, dict in cases:
18 C = Cookie.SimpleCookie() ; C.load(data)
19 print repr(C)
20 print str(C)
21 items = dict.items()
22 items.sort()
23 for k, v in items:
24 print ' ', k, repr( C[k].value ), repr(v)
25 verify(C[k].value == v)
26 print C[k]
28 C = Cookie.SimpleCookie()
29 C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
31 verify(C['Customer'].value == 'WILE_E_COYOTE')
32 verify(C['Customer']['version'] == '1')
33 verify(C['Customer']['path'] == '/acme')
35 print C.output(['path'])
36 print C.js_output()
37 print C.js_output(['path'])
39 # Try cookie with quoted meta-data
40 C = Cookie.SimpleCookie()
41 C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
42 verify(C['Customer'].value == 'WILE_E_COYOTE')
43 verify(C['Customer']['version'] == '1')
44 verify(C['Customer']['path'] == '/acme')
46 print "If anything blows up after this line, it's from Cookie's doctest."
47 run_doctest(Cookie)