blob: 87d0521b68886fdad60d055e45d3372c77c8334f [file] [log] [blame]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +00001# Simple test suite for Cookie.py
2
Guido van Rossumf27cc5b2001-01-17 21:43:06 +00003from test_support import verify
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +00004import Cookie
Fredrik Lundhf7850422001-01-17 21:51:36 +00005from test_support import verify, verbose
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +00006
7# Currently this only tests SimpleCookie
8
9cases = [
10 ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
11 ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
Fred Drake004d5e62000-10-23 17:22:08 +000012 {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
13 ]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000014
15for data, dict in cases:
16 C = Cookie.SimpleCookie() ; C.load(data)
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000017 print repr(C)
18 print str(C)
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000019 for k, v in dict.items():
20 print ' ', k, repr( C[k].value ), repr(v)
Marc-André Lemburg36619082001-01-17 19:11:13 +000021 verify(C[k].value == v)
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000022 print C[k]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000023
24C = Cookie.SimpleCookie()
25C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
26
Marc-André Lemburg36619082001-01-17 19:11:13 +000027verify(C['Customer'].value == 'WILE_E_COYOTE')
28verify(C['Customer']['version'] == '1')
29verify(C['Customer']['path'] == '/acme')
Moshe Zadka514a1022000-08-19 15:57:33 +000030
31print C.output(['path'])
32print C.js_output()
33print C.js_output(['path'])
34
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000035# Try cookie with quoted meta-data
36C = Cookie.SimpleCookie()
37C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
Marc-André Lemburg36619082001-01-17 19:11:13 +000038verify(C['Customer'].value == 'WILE_E_COYOTE')
39verify(C['Customer']['version'] == '1')
40verify(C['Customer']['path'] == '/acme')