home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TEST_COOKIE.PY < prev    next >
Encoding:
Text File  |  2000-09-28  |  1.1 KB  |  41 lines

  1.  
  2. # Simple test suite for Cookie.py
  3.  
  4. import Cookie
  5.  
  6. # Currently this only tests SimpleCookie
  7.  
  8. cases = [
  9.     ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
  10.     ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
  11.      {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),    
  12.     ] 
  13.  
  14. for data, dict in cases:
  15.     C = Cookie.SimpleCookie() ; C.load(data)
  16.     print repr(C)
  17.     print str(C)
  18.     for k, v in dict.items():
  19.         print ' ', k, repr( C[k].value ), repr(v)
  20.         assert C[k].value == v
  21.         print C[k]
  22.  
  23. C = Cookie.SimpleCookie()
  24. C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
  25.  
  26. assert C['Customer'].value == 'WILE_E_COYOTE'
  27. assert C['Customer']['version'] == '1'
  28. assert C['Customer']['path'] == '/acme'
  29.  
  30. print C.output(['path'])
  31. print C.js_output()
  32. print C.js_output(['path'])
  33.  
  34. # Try cookie with quoted meta-data
  35. C = Cookie.SimpleCookie()
  36. C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
  37. assert C['Customer'].value == 'WILE_E_COYOTE'
  38. assert C['Customer']['version'] == '1'
  39. assert C['Customer']['path'] == '/acme'
  40.  
  41.