Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 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) |
Andrew M. Kuchling | 103d526 | 2000-08-24 11:56:19 +0000 | [diff] [blame] | 16 | print repr(C) |
| 17 | print str(C) |
Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 18 | for k, v in dict.items(): |
| 19 | print ' ', k, repr( C[k].value ), repr(v) |
| 20 | assert C[k].value == v |
Andrew M. Kuchling | 103d526 | 2000-08-24 11:56:19 +0000 | [diff] [blame] | 21 | print C[k] |
Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 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' |
Moshe Zadka | 514a102 | 2000-08-19 15:57:33 +0000 | [diff] [blame] | 29 | |
| 30 | print C.output(['path']) |
| 31 | print C.js_output() |
| 32 | print C.js_output(['path']) |
| 33 | |
Andrew M. Kuchling | 103d526 | 2000-08-24 11:56:19 +0000 | [diff] [blame] | 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 | |