Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 1 | # Simple test suite for Cookie.py |
| 2 | |
| 3 | import Cookie |
| 4 | |
| 5 | # Currently this only tests SimpleCookie |
| 6 | |
| 7 | cases = [ |
| 8 | ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}), |
| 9 | ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";', |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 10 | {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}), |
| 11 | ] |
Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 12 | |
| 13 | for data, dict in cases: |
| 14 | C = Cookie.SimpleCookie() ; C.load(data) |
Andrew M. Kuchling | 103d526 | 2000-08-24 11:56:19 +0000 | [diff] [blame] | 15 | print repr(C) |
| 16 | print str(C) |
Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 17 | for k, v in dict.items(): |
| 18 | print ' ', k, repr( C[k].value ), repr(v) |
Marc-André Lemburg | 3661908 | 2001-01-17 19:11:13 +0000 | [diff] [blame^] | 19 | verify(C[k].value == v) |
Andrew M. Kuchling | 103d526 | 2000-08-24 11:56:19 +0000 | [diff] [blame] | 20 | print C[k] |
Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 21 | |
| 22 | C = Cookie.SimpleCookie() |
| 23 | C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme') |
| 24 | |
Marc-André Lemburg | 3661908 | 2001-01-17 19:11:13 +0000 | [diff] [blame^] | 25 | verify(C['Customer'].value == 'WILE_E_COYOTE') |
| 26 | verify(C['Customer']['version'] == '1') |
| 27 | verify(C['Customer']['path'] == '/acme') |
Moshe Zadka | 514a102 | 2000-08-19 15:57:33 +0000 | [diff] [blame] | 28 | |
| 29 | print C.output(['path']) |
| 30 | print C.js_output() |
| 31 | print C.js_output(['path']) |
| 32 | |
Andrew M. Kuchling | 103d526 | 2000-08-24 11:56:19 +0000 | [diff] [blame] | 33 | # Try cookie with quoted meta-data |
| 34 | C = Cookie.SimpleCookie() |
| 35 | C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"') |
Marc-André Lemburg | 3661908 | 2001-01-17 19:11:13 +0000 | [diff] [blame^] | 36 | verify(C['Customer'].value == 'WILE_E_COYOTE') |
| 37 | verify(C['Customer']['version'] == '1') |
| 38 | verify(C['Customer']['path'] == '/acme') |