]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Test WSGIApplication and make it work on python3
authorBen Darnell <ben@bendarnell.com>
Sun, 29 May 2011 22:54:53 +0000 (15:54 -0700)
committerBen Darnell <ben@bendarnell.com>
Sun, 29 May 2011 22:54:53 +0000 (15:54 -0700)
tornado/test/wsgi_test.py
tornado/wsgi.py

index 3d2ca68f066d223940ea4b5804ff1c1623909c8c..f2236cea6b339f6fa6bbfa9ae63b9bb9dda03cfd 100644 (file)
@@ -2,6 +2,7 @@ from wsgiref.validate import validator
 
 from tornado.testing import AsyncHTTPTestCase, LogTrapTestCase
 from tornado.util import b
+from tornado.web import RequestHandler
 from tornado.wsgi import WSGIApplication, WSGIContainer
 
 class WSGIContainerTest(AsyncHTTPTestCase, LogTrapTestCase):
@@ -17,3 +18,20 @@ class WSGIContainerTest(AsyncHTTPTestCase, LogTrapTestCase):
     def test_simple(self):
         response = self.fetch("/")
         self.assertEqual(response.body, b("Hello world!"))
+
+class WSGIApplicationTest(AsyncHTTPTestCase, LogTrapTestCase):
+    def get_app(self):
+        class HelloHandler(RequestHandler):
+            def get(self):
+                self.write("Hello world!")
+
+        # It would be better to run the wsgiref server implementation in
+        # another thread instead of using our own WSGIContainer, but this
+        # fits better in our async testing framework and the wsgiref
+        # validator should keep us honest
+        return WSGIContainer(validator(WSGIApplication([
+                        ("/", HelloHandler)])))
+
+    def test_simple(self):
+        response = self.fetch("/")
+        self.assertEqual(response.body, b("Hello world!"))
index 4b079f0d3bf8b2f40f6a9a32e941dd5f35063109..1a62924ab944fc20b3f045e5ae7e28c4c765138f 100644 (file)
@@ -61,6 +61,7 @@ import urllib
 from tornado import escape
 from tornado import httputil
 from tornado import web
+from tornado.escape import native_str
 from tornado.util import b
 
 try:
@@ -87,7 +88,8 @@ class WSGIApplication(web.Application):
         for cookie_dict in getattr(handler, "_new_cookies", []):
             for cookie in cookie_dict.values():
                 headers.append(("Set-Cookie", cookie.OutputString(None)))
-        start_response(status, headers)
+        start_response(status,
+                       [(native_str(k), native_str(v)) for (k,v) in headers])
         return handler._write_buffer