blob: a275cf239c4c841845ea9fa1d514248207c699fc [file] [log] [blame]
Guido van Rossum6f8f92f2000-09-01 19:27:34 +00001
2# Simple test suite for Cookie.py
3
4import Cookie
5
6# Currently this only tests SimpleCookie
7
8cases = [
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;'}),
12 ]
13
14for data, dict in cases:
15 C = Cookie.SimpleCookie() ; C.load(data)
16 print repr(C)
17 print str(C)
18 for k, v in dict.items():
19 print ' ', k, repr( C[k].value ), repr(v)
20 assert C[k].value == v
21 print C[k]
22
23C = Cookie.SimpleCookie()
24C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
25
26assert C['Customer'].value == 'WILE_E_COYOTE'
27assert C['Customer']['version'] == '1'
28assert C['Customer']['path'] == '/acme'
29
30print C.output(['path'])
31print C.js_output()
32print C.js_output(['path'])
33
34# Try cookie with quoted meta-data
35C = Cookie.SimpleCookie()
36C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
37assert C['Customer'].value == 'WILE_E_COYOTE'
38assert C['Customer']['version'] == '1'
39assert C['Customer']['path'] == '/acme'
40