blob: 40c881ff1677364c4f22b4edbd39fbed95814675 [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
Tim Peterseb26f952001-04-06 21:20:58 +00006import doctest
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +00007
8# Currently this only tests SimpleCookie
9
10cases = [
11 ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
12 ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
Fred Drake004d5e62000-10-23 17:22:08 +000013 {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
Andrew M. Kuchling8b94b1c2001-02-21 01:17:54 +000014
15 # Check illegal cookies that have an '=' char in an unquoted value
16 ('keebler=E=mc2;', {'keebler' : 'E=mc2'})
Fred Drake004d5e62000-10-23 17:22:08 +000017 ]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000018
19for data, dict in cases:
20 C = Cookie.SimpleCookie() ; C.load(data)
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000021 print repr(C)
22 print str(C)
Tim Peters2f228e72001-05-13 00:19:31 +000023 items = dict.items()
24 items.sort()
25 for k, v in items:
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000026 print ' ', k, repr( C[k].value ), repr(v)
Marc-André Lemburg36619082001-01-17 19:11:13 +000027 verify(C[k].value == v)
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000028 print C[k]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000029
30C = Cookie.SimpleCookie()
31C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
32
Marc-André Lemburg36619082001-01-17 19:11:13 +000033verify(C['Customer'].value == 'WILE_E_COYOTE')
34verify(C['Customer']['version'] == '1')
35verify(C['Customer']['path'] == '/acme')
Moshe Zadka514a1022000-08-19 15:57:33 +000036
37print C.output(['path'])
38print C.js_output()
39print C.js_output(['path'])
40
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000041# Try cookie with quoted meta-data
42C = Cookie.SimpleCookie()
43C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
Marc-André Lemburg36619082001-01-17 19:11:13 +000044verify(C['Customer'].value == 'WILE_E_COYOTE')
45verify(C['Customer']['version'] == '1')
46verify(C['Customer']['path'] == '/acme')
Tim Peterseb26f952001-04-06 21:20:58 +000047
48print "If anything blows up after this line, it's from Cookie's doctest."
49doctest.testmod(Cookie)