http: Rename 'setup_routes()' to 'get_request_handlers()'

This commit is contained in:
Stein Magnus Jodal 2014-05-20 22:20:48 +02:00
parent e8291d471e
commit 1838f10dcf
2 changed files with 16 additions and 10 deletions

View File

@ -77,14 +77,16 @@ class Router(object):
"""Get the absolute URL to the root of this router."""
return 'http://%s:%s/%s/' % (self.hostname, self.port, self.name)
def setup_routes(self):
def get_request_handlers(self):
"""
Configure routes for this interface.
Get request handlers for the URL namespace owned by this router.
Implementation must return list of routes, compatible with
The default implementation of this method serves static files from
:attr:`static_file_path`. To extend the HTTP server with more
server side functionality, this method must be overridden.
Must return a list of request handlers compatible with
:class:`tornado.web.Application`.
:return: list of Tornado routes
"""
if self.static_file_path is None:

View File

@ -49,10 +49,14 @@ class HttpRouterTest(unittest.TestCase):
def test_default_router(self):
router = TestRouter(self.config)
self.assertEqual(router.setup_routes()[0][0], r'/test/(.*)')
self.assertIs(router.setup_routes()[0][1], http.StaticFileHandler)
self.assertEqual(router.setup_routes()[0][2]['path'],
os.path.join(os.path.dirname(__file__), 'static'))
handlers = router.get_request_handlers()
(pattern, handler_class, kwargs) = handlers[0]
self.assertEqual(pattern, r'/test/(.*)')
self.assertIs(handler_class, http.StaticFileHandler)
self.assertEqual(
kwargs['path'], os.path.join(os.path.dirname(__file__), 'static'))
def test_default_router_missing_name(self):
with self.assertRaises(ValueError):
@ -60,7 +64,7 @@ class HttpRouterTest(unittest.TestCase):
def test_default_router_missing_path(self):
with self.assertRaises(ValueError):
TestRouterMissingPath(self.config).setup_routes()
TestRouterMissingPath(self.config).get_request_handlers()
def test_default_uri_helper(self):
router = TestRouter(self.config)