From 1838f10dcf53d1e300984c8fbcca4a62475f86bc Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 20 May 2014 22:20:48 +0200 Subject: [PATCH] http: Rename 'setup_routes()' to 'get_request_handlers()' --- mopidy/http/__init__.py | 12 +++++++----- tests/http/test_router.py | 14 +++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mopidy/http/__init__.py b/mopidy/http/__init__.py index 192405db..cfdc8f43 100644 --- a/mopidy/http/__init__.py +++ b/mopidy/http/__init__.py @@ -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: diff --git a/tests/http/test_router.py b/tests/http/test_router.py index 08829187..aefaf18d 100644 --- a/tests/http/test_router.py +++ b/tests/http/test_router.py @@ -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)