Changeset 319
- Timestamp:
- 06/16/05 00:44:26
- Files:
-
- trunk/cherrypy/lib/filter/sessionfilter/sessionfilter.py (modified) (previous)
- trunk/cherrypy/test/helper.py (modified) (6 diffs)
- trunk/cherrypy/test/test_tutorials.py (modified) (1 diff)
- trunk/cherrypy/tutorial/tut11_file_upload.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/test/helper.py
r315 r319 31 31 import sys 32 32 import socket 33 import StringIO 33 34 import httplib 34 35 import threading … … 68 69 69 70 70 def getPage(url, headers=None, method="GET" ):71 def getPage(url, headers=None, method="GET", body=None): 71 72 72 73 # The trying 10 times is simply in case of socket errors. … … 82 83 conn.putheader(key, value) 83 84 conn.endheaders() 85 86 if body is not None: 87 conn.send(body) 84 88 85 89 # Handle response … … 103 107 cpg.response.headers = cpg.response.headerMap 104 108 105 b = cpg.response.body = response.read() 106 ## print "body:", repr(b) 109 cpg.response.body = response.read() 107 110 108 111 conn.close() … … 116 119 117 120 118 def request(url, headers=None, method="GET" ):121 def request(url, headers=None, method="GET", body=None): 119 122 if headers is None: 120 123 headers = [] … … 129 132 if not found: 130 133 headers.append(("Host", "%s:%s" % (HOST, PORT))) 131 cpg.server.request(HOST, HOST, requestLine, headers, None) 134 if body is not None: 135 body = StringIO.StringIO(body) 136 cpg.server.request(HOST, HOST, requestLine, headers, body) 132 137 cpg.response.body = "".join(cpg.response.body) 133 138 else: 134 getPage(url, headers, method )139 getPage(url, headers, method, body) 135 140 trunk/cherrypy/test/test_tutorials.py
r315 r319 176 176 helper.request('/', [('Cookie', dict(cpg.response.headers)['Set-Cookie'])]) 177 177 self.assert_("viewed this page 2 times" in cpg.response.body) 178 178 179 def test11FileUpload(self): 180 load_tut_module("tut11_file_upload") 181 182 h = [("Content-type", "multipart/form-data; boundary=x"), 183 ("Content-Length", "110")] 184 b = """--x 185 Content-Disposition: form-data; name="myFile"; filename="hello.txt" 186 Content-Type: text/plain 187 188 hello 189 --x-- 190 """ 191 helper.request('/upload', h, "POST", b) 192 self.assertEqual(cpg.response.body, ''' 193 <html><body> 194 myFile length: 5<br /> 195 myFile filename: hello.txt<br /> 196 myFile mime-type: text/plain 197 </body></html> 198 ''') 179 199 180 200 if __name__ == "__main__":

