Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 1 | # Simple test suite for Cookie.py |
| 2 | |
Tim Peters | a0a6222 | 2001-09-09 06:12:01 +0000 | [diff] [blame^] | 3 | from test_support import verify, verbose, run_doctest |
Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 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;";', |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 11 | {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}), |
Andrew M. Kuchling | 8b94b1c | 2001-02-21 01:17:54 +0000 | [diff] [blame] | 12 | |
| 13 | # Check illegal cookies that have an '=' char in an unquoted value |
| 14 | ('keebler=E=mc2;', {'keebler' : 'E=mc2'}) |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 15 | ] |
Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 16 | |
| 17 | for data, dict in cases: |
| 18 | C = Cookie.SimpleCookie() ; C.load(data) |
Andrew M. Kuchling | 103d526 | 2000-08-24 11:56:19 +0000 | [diff] [blame] | 19 | print repr(C) |
| 20 | print str(C) |
Tim Peters | 2f228e7 | 2001-05-13 00:19:31 +0000 | [diff] [blame] | 21 | items = dict.items() |
| 22 | items.sort() |
| 23 | for k, v in items: |
Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 24 | print ' ', k, repr( C[k].value ), repr(v) |
Marc-André Lemburg | 3661908 | 2001-01-17 19:11:13 +0000 | [diff] [blame] | 25 | verify(C[k].value == v) |
Andrew M. Kuchling | 103d526 | 2000-08-24 11:56:19 +0000 | [diff] [blame] | 26 | print C[k] |
Andrew M. Kuchling | cdec8c7 | 2000-08-19 15:21:12 +0000 | [diff] [blame] | 27 | |
| 28 | C = Cookie.SimpleCookie() |
| 29 | C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme') |
| 30 | |
Marc-André Lemburg | 3661908 | 2001-01-17 19:11:13 +0000 | [diff] [blame] | 31 | verify(C['Customer'].value == 'WILE_E_COYOTE') |
| 32 | verify(C['Customer']['version'] == '1') |
| 33 | verify(C['Customer']['path'] == '/acme') |
Moshe Zadka | 514a102 | 2000-08-19 15:57:33 +0000 | [diff] [blame] | 34 | |
| 35 | print C.output(['path']) |
| 36 | print C.js_output() |
| 37 | print C.js_output(['path']) |
| 38 | |
Andrew M. Kuchling | 103d526 | 2000-08-24 11:56:19 +0000 | [diff] [blame] | 39 | # Try cookie with quoted meta-data |
| 40 | C = Cookie.SimpleCookie() |
| 41 | C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"') |
Marc-André Lemburg | 3661908 | 2001-01-17 19:11:13 +0000 | [diff] [blame] | 42 | verify(C['Customer'].value == 'WILE_E_COYOTE') |
| 43 | verify(C['Customer']['version'] == '1') |
| 44 | verify(C['Customer']['path'] == '/acme') |
Tim Peters | eb26f95 | 2001-04-06 21:20:58 +0000 | [diff] [blame] | 45 | |
| 46 | print "If anything blows up after this line, it's from Cookie's doctest." |
Tim Peters | a0a6222 | 2001-09-09 06:12:01 +0000 | [diff] [blame^] | 47 | run_doctest(Cookie) |