blob: 8dd0f6f50a0aa168915d82c000fb684352a6efc6 [file] [log] [blame]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +00001# Simple test suite for Cookie.py
2
3import Cookie
4
5# Currently this only tests SimpleCookie
6
7cases = [
8 ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
9 ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
Fred Drake004d5e62000-10-23 17:22:08 +000010 {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
11 ]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000012
13for data, dict in cases:
14 C = Cookie.SimpleCookie() ; C.load(data)
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000015 print repr(C)
16 print str(C)
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000017 for k, v in dict.items():
18 print ' ', k, repr( C[k].value ), repr(v)
Marc-André Lemburg36619082001-01-17 19:11:13 +000019 verify(C[k].value == v)
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000020 print C[k]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000021
22C = Cookie.SimpleCookie()
23C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
24
Marc-André Lemburg36619082001-01-17 19:11:13 +000025verify(C['Customer'].value == 'WILE_E_COYOTE')
26verify(C['Customer']['version'] == '1')
27verify(C['Customer']['path'] == '/acme')
Moshe Zadka514a1022000-08-19 15:57:33 +000028
29print C.output(['path'])
30print C.js_output()
31print C.js_output(['path'])
32
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000033# Try cookie with quoted meta-data
34C = Cookie.SimpleCookie()
35C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
Marc-André Lemburg36619082001-01-17 19:11:13 +000036verify(C['Customer'].value == 'WILE_E_COYOTE')
37verify(C['Customer']['version'] == '1')
38verify(C['Customer']['path'] == '/acme')