From: Ben Darnell Date: Sat, 2 Nov 2013 19:55:45 +0000 (-0400) Subject: Add test for specifying handlers by name. X-Git-Tag: v3.2.0b1~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10c0e77b33ddef3d53226c5c4688d68076c3c7f5;p=thirdparty%2Ftornado.git Add test for specifying handlers by name. --- diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 153c8ccbf..6136172fc 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -61,6 +61,11 @@ class SimpleHandlerTestCase(WebTestCase): return [('/', self.Handler)] +class HelloHandler(RequestHandler): + def get(self): + self.write('hello') + + class CookieTestRequestHandler(RequestHandler): # stub out enough methods to make the secure_cookie functions work def __init__(self): @@ -1760,3 +1765,21 @@ class DefaultHandlerArgumentsTest(WebTestCase): def test_403(self): response = self.fetch('/') self.assertEqual(response.code, 403) + + +@wsgi_safe +class HandlerByNameTest(WebTestCase): + def get_handlers(self): + # All three are equivalent. + return [('/hello1', HelloHandler), + ('/hello2', 'tornado.test.web_test.HelloHandler'), + url('/hello3', 'tornado.test.web_test.HelloHandler'), + ] + + def test_handler_by_name(self): + resp = self.fetch('/hello1') + self.assertEqual(resp.body, b'hello') + resp = self.fetch('/hello2') + self.assertEqual(resp.body, b'hello') + resp = self.fetch('/hello3') + self.assertEqual(resp.body, b'hello')