PyXR

c:\python24\lib \ test \ test_cookie.py



0001 # Simple test suite for Cookie.py
0002 
0003 from test.test_support import verify, verbose, run_doctest
0004 import Cookie
0005 
0006 import warnings
0007 warnings.filterwarnings("ignore",
0008                         ".* class is insecure.*",
0009                         DeprecationWarning)
0010 
0011 # Currently this only tests SimpleCookie
0012 
0013 cases = [
0014     ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
0015     ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
0016      {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
0017 
0018     # Check illegal cookies that have an '=' char in an unquoted value
0019     ('keebler=E=mc2;', {'keebler' : 'E=mc2'})
0020     ]
0021 
0022 for data, dict in cases:
0023     C = Cookie.SimpleCookie() ; C.load(data)
0024     print repr(C)
0025     print str(C)
0026     for k, v in sorted(dict.iteritems()):
0027         print ' ', k, repr( C[k].value ), repr(v)
0028         verify(C[k].value == v)
0029         print C[k]
0030 
0031 C = Cookie.SimpleCookie()
0032 C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
0033 
0034 verify(C['Customer'].value == 'WILE_E_COYOTE')
0035 verify(C['Customer']['version'] == '1')
0036 verify(C['Customer']['path'] == '/acme')
0037 
0038 print C.output(['path'])
0039 print C.js_output()
0040 print C.js_output(['path'])
0041 
0042 # Try cookie with quoted meta-data
0043 C = Cookie.SimpleCookie()
0044 C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
0045 verify(C['Customer'].value == 'WILE_E_COYOTE')
0046 verify(C['Customer']['version'] == '1')
0047 verify(C['Customer']['path'] == '/acme')
0048 
0049 print "If anything blows up after this line, it's from Cookie's doctest."
0050 run_doctest(Cookie)
0051 

Generated by PyXR 0.9.4
SourceForge.net Logo