python-2.5.2/win32/Lib/test/test_cookie.py
changeset 0 ae805ac0140d
equal deleted inserted replaced
-1:000000000000 0:ae805ac0140d
       
     1 # Simple test suite for Cookie.py
       
     2 
       
     3 from test.test_support import verify, verbose, run_doctest
       
     4 import Cookie
       
     5 
       
     6 import warnings
       
     7 warnings.filterwarnings("ignore",
       
     8                         ".* class is insecure.*",
       
     9                         DeprecationWarning)
       
    10 
       
    11 # Currently this only tests SimpleCookie
       
    12 
       
    13 cases = [
       
    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 
       
    22 for 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 
       
    31 C = Cookie.SimpleCookie()
       
    32 C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
       
    33 
       
    34 verify(C['Customer'].value == 'WILE_E_COYOTE')
       
    35 verify(C['Customer']['version'] == '1')
       
    36 verify(C['Customer']['path'] == '/acme')
       
    37 
       
    38 print C.output(['path'])
       
    39 print C.js_output()
       
    40 print C.js_output(['path'])
       
    41 
       
    42 # Try cookie with quoted meta-data
       
    43 C = Cookie.SimpleCookie()
       
    44 C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
       
    45 verify(C['Customer'].value == 'WILE_E_COYOTE')
       
    46 verify(C['Customer']['version'] == '1')
       
    47 verify(C['Customer']['path'] == '/acme')
       
    48 
       
    49 print "If anything blows up after this line, it's from Cookie's doctest."
       
    50 run_doctest(Cookie)