annotate Lib/test/test_cgi.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents c1a8deb15f0e
children 226ba34bd998
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
1 from test_support import verify, verbose
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2 import cgi
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
3 import os
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
4 import sys
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
5
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
6 class HackedSysModule:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
7 # The regression test will have real values in sys.argv, which
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14606
diff changeset
8 # will completely confuse the test of the cgi module
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
9 argv = []
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
10 stdin = sys.stdin
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
11
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
12 cgi.sys = HackedSysModule()
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
13
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
14 try:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
15 from cStringIO import StringIO
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
16 except ImportError:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
17 from StringIO import StringIO
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
18
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
19 class ComparableException:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
20 def __init__(self, err):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
21 self.err = err
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
22
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
23 def __str__(self):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
24 return str(self.err)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
25
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
26 def __cmp__(self, anExc):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
27 if not isinstance(anExc, Exception):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
28 return -1
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
29 x = cmp(self.err.__class__, anExc.__class__)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
30 if x != 0:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
31 return x
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
32 return cmp(self.err.args, anExc.args)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
33
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
34 def __getattr__(self, attr):
15936
bec0f61cfcd5 Fix a bizarre typo in the helper class ComparableException: the
Guido van Rossum <guido@python.org>
parents: 15305
diff changeset
35 return getattr(self.err, attr)
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
36
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
37 def do_test(buf, method):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
38 env = {}
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
39 if method == "GET":
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
40 fp = None
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
41 env['REQUEST_METHOD'] = 'GET'
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
42 env['QUERY_STRING'] = buf
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
43 elif method == "POST":
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
44 fp = StringIO(buf)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
45 env['REQUEST_METHOD'] = 'POST'
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
46 env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
47 env['CONTENT_LENGTH'] = str(len(buf))
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
48 else:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
49 raise ValueError, "unknown method: %s" % method
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
50 try:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
51 return cgi.parse(fp, env, strict_parsing=1)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
52 except StandardError, err:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
53 return ComparableException(err)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
54
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
55 # A list of test cases. Each test case is a a two-tuple that contains
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
56 # a string with the query and a dictionary with the expected result.
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14606
diff changeset
57
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
58 parse_test_cases = [
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
59 ("", ValueError("bad query field: ''")),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
60 ("&", ValueError("bad query field: ''")),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
61 ("&&", ValueError("bad query field: ''")),
14606
f2fc66a6153b fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14196
diff changeset
62 (";", ValueError("bad query field: ''")),
f2fc66a6153b fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14196
diff changeset
63 (";&;", ValueError("bad query field: ''")),
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
64 # Should the next few really be valid?
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
65 ("=", {}),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
66 ("=&=", {}),
14606
f2fc66a6153b fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14196
diff changeset
67 ("=;=", {}),
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
68 # This rest seem to make sense
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
69 ("=a", {'': ['a']}),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
70 ("&=a", ValueError("bad query field: ''")),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
71 ("=a&", ValueError("bad query field: ''")),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
72 ("=&a", ValueError("bad query field: 'a'")),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
73 ("b=a", {'b': ['a']}),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
74 ("b+=a", {'b ': ['a']}),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
75 ("a=b=a", {'a': ['b=a']}),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
76 ("a=+b=a", {'a': [' b=a']}),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
77 ("&b=a", ValueError("bad query field: ''")),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
78 ("b&=a", ValueError("bad query field: 'b'")),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
79 ("a=a+b&b=b+c", {'a': ['a b'], 'b': ['b c']}),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
80 ("a=a+b&a=b+a", {'a': ['a b', 'b a']}),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
81 ("x=1&y=2.0&z=2-3.%2b0", {'x': ['1'], 'y': ['2.0'], 'z': ['2-3.+0']}),
14606
f2fc66a6153b fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14196
diff changeset
82 ("x=1;y=2.0&z=2-3.%2b0", {'x': ['1'], 'y': ['2.0'], 'z': ['2-3.+0']}),
f2fc66a6153b fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14196
diff changeset
83 ("x=1;y=2.0;z=2-3.%2b0", {'x': ['1'], 'y': ['2.0'], 'z': ['2-3.+0']}),
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
84 ("Hbc5161168c542333633315dee1182227:key_store_seqid=400006&cuyer=r&view=bustomer&order_id=0bb2e248638833d48cb7fed300000f1b&expire=964546263&lobale=en-US&kid=130003.300038&ss=env",
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
85 {'Hbc5161168c542333633315dee1182227:key_store_seqid': ['400006'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
86 'cuyer': ['r'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
87 'expire': ['964546263'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
88 'kid': ['130003.300038'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
89 'lobale': ['en-US'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
90 'order_id': ['0bb2e248638833d48cb7fed300000f1b'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
91 'ss': ['env'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
92 'view': ['bustomer'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
93 }),
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14606
diff changeset
94
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
95 ("group_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=Browse",
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
96 {'SUBMIT': ['Browse'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
97 '_assigned_to': ['31392'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
98 '_category': ['100'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
99 '_status': ['1'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
100 'group_id': ['5470'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
101 'set': ['custom'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
102 })
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
103 ]
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
104
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
105 def norm(list):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
106 if type(list) == type([]):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
107 list.sort()
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
108 return list
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
109
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
110 def first_elts(list):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
111 return map(lambda x:x[0], list)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
112
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
113 def first_second_elts(list):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
114 return map(lambda p:(p[0], p[1][0]), list)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
115
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
116 def main():
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
117 for orig, expect in parse_test_cases:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
118 # Test basic parsing
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
119 print repr(orig)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
120 d = do_test(orig, "GET")
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
121 verify(d == expect, "Error parsing %s" % repr(orig))
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
122 d = do_test(orig, "POST")
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
123 verify(d == expect, "Error parsing %s" % repr(orig))
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
124
14196
41234ae95d2a Closing patch #101120 -- After everyone agreed.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 13842
diff changeset
125 env = {'QUERY_STRING': orig}
41234ae95d2a Closing patch #101120 -- After everyone agreed.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 13842
diff changeset
126 fcd = cgi.FormContentDict(env)
41234ae95d2a Closing patch #101120 -- After everyone agreed.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 13842
diff changeset
127 sd = cgi.SvFormContentDict(env)
41234ae95d2a Closing patch #101120 -- After everyone agreed.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 13842
diff changeset
128 fs = cgi.FieldStorage(environ=env)
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
129 if type(expect) == type({}):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
130 # test dict interface
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
131 verify(len(expect) == len(fcd))
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
132 verify(norm(expect.keys()) == norm(fcd.keys()))
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
133 verify(norm(expect.values()) == norm(fcd.values()))
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
134 verify(norm(expect.items()) == norm(fcd.items()))
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
135 verify(fcd.get("nonexistent field", "default") == "default")
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
136 verify(len(sd) == len(fs))
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
137 verify(norm(sd.keys()) == norm(fs.keys()))
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
138 verify(fs.getvalue("nonexistent field", "default") == "default")
14196
41234ae95d2a Closing patch #101120 -- After everyone agreed.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 13842
diff changeset
139 # test individual fields
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
140 for key in expect.keys():
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
141 expect_val = expect[key]
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
142 verify(fcd.has_key(key))
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
143 verify(norm(fcd[key]) == norm(expect[key]))
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
144 verify(fcd.get(key, "default") == fcd[key])
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
145 verify(fs.has_key(key))
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
146 if len(expect_val) > 1:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
147 single_value = 0
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
148 else:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
149 single_value = 1
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
150 try:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
151 val = sd[key]
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
152 except IndexError:
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
153 verify(not single_value)
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
154 verify(fs.getvalue(key) == expect_val)
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
155 else:
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
156 verify(single_value)
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
157 verify(val == expect_val[0])
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
158 verify(fs.getvalue(key) == expect_val[0])
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
159 verify(norm(sd.getlist(key)) == norm(expect_val))
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
160 if single_value:
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
161 verify(norm(sd.values()) == \
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
162 first_elts(norm(expect.values())))
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
163 verify(norm(sd.items()) == \
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
164 first_second_elts(norm(expect.items())))
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
165
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
166 # Test the weird FormContentDict classes
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
167 env = {'QUERY_STRING': "x=1&y=2.0&z=2-3.%2b0&1=1abc"}
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
168 expect = {'x': 1, 'y': 2.0, 'z': '2-3.+0', '1': '1abc'}
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
169 d = cgi.InterpFormContentDict(env)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
170 for k, v in expect.items():
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
171 verify(d[k] == v)
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
172 for k, v in d.items():
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
173 verify(expect[k] == v)
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15936
diff changeset
174 verify(norm(expect.values()) == norm(d.values()))
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
175
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
176 print "Testing log"
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
177 cgi.initlog()
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
178 cgi.log("Testing")
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
179 cgi.logfp = sys.stdout
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
180 cgi.initlog("%s", "Testing initlog 1")
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
181 cgi.log("%s", "Testing log 2")
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
182 if os.path.exists("/dev/null"):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
183 cgi.logfp = None
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
184 cgi.logfile = "/dev/null"
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
185 cgi.initlog("%s", "Testing log 3")
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
186 cgi.log("Testing log 4")
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
187
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
188 main()