source: trunk/essentials/dev-lang/python/Lib/test/test_cookie.py@ 3317

Last change on this file since 3317 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 1.5 KB
Line 
1# Simple test suite for Cookie.py
2
3from test.test_support import verify, verbose, run_doctest
4import Cookie
5
6import warnings
7warnings.filterwarnings("ignore",
8 ".* class is insecure.*",
9 DeprecationWarning)
10
11# Currently this only tests SimpleCookie
12
13cases = [
14 ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
15 ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;"',
16 {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
17
18 # Check illegal cookies that have an '=' char in an unquoted value
19 ('keebler=E=mc2', {'keebler' : 'E=mc2'})
20 ]
21
22for data, dict in cases:
23 C = Cookie.SimpleCookie() ; C.load(data)
24 print repr(C)
25 print C.output(sep='\n')
26 for k, v in sorted(dict.iteritems()):
27 print ' ', k, repr( C[k].value ), repr(v)
28 verify(C[k].value == v)
29 print C[k]
30
31C = Cookie.SimpleCookie()
32C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
33
34verify(C['Customer'].value == 'WILE_E_COYOTE')
35verify(C['Customer']['version'] == '1')
36verify(C['Customer']['path'] == '/acme')
37
38print C.output(['path'])
39print C.js_output()
40print C.js_output(['path'])
41
42# Try cookie with quoted meta-data
43C = Cookie.SimpleCookie()
44C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
45verify(C['Customer'].value == 'WILE_E_COYOTE')
46verify(C['Customer']['version'] == '1')
47verify(C['Customer']['path'] == '/acme')
48
49print "If anything blows up after this line, it's from Cookie's doctest."
50run_doctest(Cookie)
Note: See TracBrowser for help on using the repository browser.