]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add HTTPServer's type test to WSGIApplication, and fix another python3 bug.
authorBen Darnell <ben@bendarnell.com>
Sat, 24 Mar 2012 20:46:06 +0000 (13:46 -0700)
committerBen Darnell <ben@bendarnell.com>
Sat, 24 Mar 2012 20:46:06 +0000 (13:46 -0700)
tornado/test/wsgi_test.py
tornado/wsgi.py

index 66996c0658dc06e359d8f0fa93c97dc7cd5040d9..54c374065d256924a5455c9e30f922806a744d37 100644 (file)
@@ -1,6 +1,8 @@
 from __future__ import absolute_import, division, with_statement
 from wsgiref.validate import validator
 
+from tornado.escape import json_decode
+from tornado.test.httpserver_test import TypeCheckHandler
 from tornado.testing import AsyncHTTPTestCase, LogTrapTestCase
 from tornado.util import b
 from tornado.web import RequestHandler
@@ -39,6 +41,7 @@ class WSGIApplicationTest(AsyncHTTPTestCase, LogTrapTestCase):
         return WSGIContainer(validator(WSGIApplication([
                         ("/", HelloHandler),
                         ("/path/(.*)", PathQuotingHandler),
+                        ("/typecheck", TypeCheckHandler),
                         ])))
 
     def test_simple(self):
@@ -49,6 +52,16 @@ class WSGIApplicationTest(AsyncHTTPTestCase, LogTrapTestCase):
         response = self.fetch("/path/foo%20bar%C3%A9")
         self.assertEqual(response.body, u"foo bar\u00e9".encode("utf-8"))
 
+    def test_types(self):
+        headers = {"Cookie": "foo=bar"}
+        response = self.fetch("/typecheck?foo=bar", headers=headers)
+        data = json_decode(response.body)
+        self.assertEqual(data, {})
+
+        response = self.fetch("/typecheck", method="POST", body="foo=bar", headers=headers)
+        data = json_decode(response.body)
+        self.assertEqual(data, {})
+
 # This is kind of hacky, but run some of the HTTPServer tests through
 # WSGIContainer and WSGIApplication to make sure everything survives
 # repeated disassembly and reassembly.
index b756f7022eac4e93439ce3d01d6f4cda9716d427..73e0af1bd1f04832d845a9f99f8af84094627d48 100644 (file)
@@ -116,7 +116,7 @@ class HTTPRequest(object):
         self.query = environ.get("QUERY_STRING", "")
         if self.query:
             self.uri += "?" + self.query
-            arguments = cgi.parse_qs(self.query)
+            arguments = parse_qs_bytes(native_str(self.query))
             for name, values in arguments.iteritems():
                 values = [v for v in values if v]
                 if values: