blob: c20beeeb1e52558700b8b72a50722f0f7de95786 [file] [log] [blame]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +00001# Simple test suite for Cookie.py
2
Barry Warsaw04f357c2002-07-23 19:04:11 +00003from test.test_support import verify, verbose, run_doctest
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +00004import Cookie
5
Andrew M. Kuchling44644322002-12-29 16:45:06 +00006import warnings
7warnings.filterwarnings("ignore",
8 ".* class is insecure.*",
9 DeprecationWarning)
10
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000011# Currently this only tests SimpleCookie
12
13cases = [
14 ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
Georg Brandl8246c432005-08-25 07:32:42 +000015 ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;"',
Fred Drake004d5e62000-10-23 17:22:08 +000016 {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
Andrew M. Kuchling8b94b1c2001-02-21 01:17:54 +000017
18 # Check illegal cookies that have an '=' char in an unquoted value
Georg Brandl8246c432005-08-25 07:32:42 +000019 ('keebler=E=mc2', {'keebler' : 'E=mc2'})
Fred Drake004d5e62000-10-23 17:22:08 +000020 ]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000021
22for data, dict in cases:
23 C = Cookie.SimpleCookie() ; C.load(data)
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000024 print repr(C)
Georg Brandl8246c432005-08-25 07:32:42 +000025 print C.output(sep='\n')
Raymond Hettingerd73ef062004-01-04 11:14:51 +000026 for k, v in sorted(dict.iteritems()):
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000027 print ' ', k, repr( C[k].value ), repr(v)
Marc-André Lemburg36619082001-01-17 19:11:13 +000028 verify(C[k].value == v)
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000029 print C[k]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000030
31C = Cookie.SimpleCookie()
32C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
33
Marc-André Lemburg36619082001-01-17 19:11:13 +000034verify(C['Customer'].value == 'WILE_E_COYOTE')
35verify(C['Customer']['version'] == '1')
36verify(C['Customer']['path'] == '/acme')
Moshe Zadka514a1022000-08-19 15:57:33 +000037
38print C.output(['path'])
39print C.js_output()
40print C.js_output(['path'])
41
Andrew M. Kuchling103d5262000-08-24 11:56:19 +000042# Try cookie with quoted meta-data
43C = Cookie.SimpleCookie()
44C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
Marc-André Lemburg36619082001-01-17 19:11:13 +000045verify(C['Customer'].value == 'WILE_E_COYOTE')
46verify(C['Customer']['version'] == '1')
47verify(C['Customer']['path'] == '/acme')
Tim Peterseb26f952001-04-06 21:20:58 +000048
49print "If anything blows up after this line, it's from Cookie's doctest."
Tim Petersa0a62222001-09-09 06:12:01 +000050run_doctest(Cookie)