@@ -190,17 +190,20 @@ def g():
190190
191191 def testUnicodeInput (self ):
192192 urls = (
193- "/.*" , "foo"
193+ "( /.*) " , "foo"
194194 )
195195 class foo :
196- def GET (self ):
196+ def GET (self , path ):
197197 i = web .input (name = '' )
198198 return repr (i .name )
199199
200- def POST (self ):
201- return repr (web .data ())
202- i = web .input (name = {})
203- return repr (i )
200+ def POST (self , path ):
201+ if path == '/multipart' :
202+ i = web .input (file = {})
203+ return i .file .value
204+ else :
205+ i = web .input ()
206+ return repr (dict (i ))
204207
205208 app = web .application (urls , locals ())
206209
@@ -210,11 +213,14 @@ def f(name):
210213
211214 f (u'\u1234 ' )
212215 f (u'foo' )
216+
217+ response = app .request ('/' , method = 'POST' , data = dict (name = 'foo' ))
218+ self .assertEquals (response .data , "{'name': u'foo'}" )
213219
214- data = '--boundary\r \n Content-Disposition: form-data; name="name"; filename="a.txt"\r \n Content-Type: text/plain\r \n \r \n a\r \n --boundary--\r \n '
215- headers = {'Content-Type' : 'multipart/form-data; boundary=-- boundary' }
216- response = app .request ('/' , method = "POST" , data = data , headers = headers )
217- # self.assertEquals(response.data, 'a')
220+ data = '--boundary\r \n Content-Disposition: form-data; name="x" \r \n foo \r \n --boundary \r \n Content-Disposition: form-data; name="file "; filename="a.txt"\r \n Content-Type: text/plain\r \n \r \n a\r \n --boundary--\r \n '
221+ headers = {'Content-Type' : 'multipart/form-data; boundary=boundary' }
222+ response = app .request ('/multipart ' , method = "POST" , data = data , headers = headers )
223+ self .assertEquals (response .data , 'a' )
218224
219225 def testCustomNotFound (self ):
220226 urls_a = ("/" , "a" )
@@ -242,6 +248,6 @@ def assert_notfound(path, message):
242248 app .notfound = lambda : web .HTTPError ("404 Not Found" , {}, "not found 2" )
243249 assert_notfound ("/a/foo" , "not found 1" )
244250 assert_notfound ("/b/foo" , "not found 2" )
245-
251+
246252if __name__ == '__main__' :
247253 webtest .main ()
0 commit comments