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):
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!"))
from tornado import escape
from tornado import httputil
from tornado import web
+from tornado.escape import native_str
from tornado.util import b
try:
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