def test_all_controllers_returns_all_imported_controllers(): clear_expectations() clear() class TestController2(Controller): pass controllers = Controller.all() assert controllers assert len(controllers) == 1 assert controllers[0] == TestController2
def get_dispatcher(self): routes_dispatcher = cherrypy.dispatch.RoutesDispatcher() class MediaController(): def __init__(self, apps): self.apps = apps def serve_media(self, media_url): for app in self.apps: extension = splitext(media_url)[-1] app_module = reduce(getattr, app.split('.')[1:], __import__(app)) path = inspect.getfile(app_module) media_path = abspath(join("/".join(split(path)[:-1]), 'media', media_url)) if exists(media_path): if extension == ".jpg": content_type = "image/jpeg" elif extension == ".gif": content_type = "image/gif" elif extension == ".png": content_type = "image/png" elif extension == ".js": content_type = "text/javascript" elif extension == ".css": content_type = "text/css" elif extension.startswith('.htm'): content_type = "text/html" else: content_type = "text/plain" return serve_file(media_path, content_type=content_type) raise cherrypy.HTTPError(404) for controller_type in Controller.all(): controller = controller_type() controller.server = self controller.register_routes(routes_dispatcher) media_controller = MediaController(self.apps) routes_dispatcher.connect("media", "/media/{media_url:(.+)}", controller=media_controller, action="serve_media") route_name = "healthcheck" controller = Controller() controller.server = self routes_dispatcher.connect("healthcheck", "/healthcheck", controller=controller, action="healthcheck") dispatcher = routes_dispatcher return dispatcher
def get_dispatcher(self): routes_dispatcher = cherrypy.dispatch.RoutesDispatcher() for controller_type in Controller.all(): controller = controller_type() controller.server = self controller.register_routes(routes_dispatcher) route_name = "healthcheck" controller = Controller() controller.server = self routes_dispatcher.connect("healthcheck", "/healthcheck", controller=controller, action="healthcheck") dispatcher = routes_dispatcher return dispatcher