From: Ben Darnell Date: Sun, 29 May 2011 22:54:53 +0000 (-0700) Subject: Test WSGIApplication and make it work on python3 X-Git-Tag: v2.0.0~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f7e8850debb24d2e3bd103cdca0b75ae5cfe9f1;p=thirdparty%2Ftornado.git Test WSGIApplication and make it work on python3 --- diff --git a/tornado/test/wsgi_test.py b/tornado/test/wsgi_test.py index 3d2ca68f0..f2236cea6 100644 --- a/tornado/test/wsgi_test.py +++ b/tornado/test/wsgi_test.py @@ -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!")) diff --git a/tornado/wsgi.py b/tornado/wsgi.py index 4b079f0d3..1a62924ab 100644 --- a/tornado/wsgi.py +++ b/tornado/wsgi.py @@ -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