Exemplo n.º 1
0
    def __init__(self,
                 debug_mode=False,
                 static_path='./static',
                 adapters=None):
        """Initialise the HttpServer object.

        :param debug_mode: Set True to enable Tornado debug mode
        :param static_path: Set the path to static file content rendered by default route
        :param adapters: list of adapters to register with API route
        """
        settings = {
            "debug": debug_mode,
            "log_function": self.log_request,
        }

        # Create an API route
        self.api_route = ApiRoute()

        # Register adapters with the API route and get handlers
        for adapter in adapters:
            self.api_route.register_adapter(adapters[adapter])

        handlers = self.api_route.get_handlers()

        # Create a default route for static content and get handlers
        default_route = DefaultRoute(static_path)
        handlers += default_route.get_handlers()

        # Create the Tornado web application for these handlers
        self.application = tornado.web.Application(handlers, **settings)
Exemplo n.º 2
0
    def __init__(self):

        self.route = ApiRoute()
        self.adapter_name = 'async_dummy'
        self.adapter_module = 'odin.adapters.async_dummy.AsyncDummyAdapter'
        self.adapter_config = AdapterConfig(self.adapter_name,
                                            self.adapter_module)

        self.route.register_adapter(self.adapter_config)

        self.initialize_mock = AsyncMock()
        self.route.adapters[
            self.adapter_name].initialize = self.initialize_mock

        self.cleanup_mock = AsyncMock()
        self.route.adapters[self.adapter_name].cleanup = self.cleanup_mock
Exemplo n.º 3
0
    def __init__(self,
                 debug_mode=False,
                 access_logging=None,
                 static_path='./static',
                 adapters=None):
        """Initialise the HttpServer object.

        :param debug_mode: Set True to enable Tornado debug mode
        :param static_path: Set the path to static file content rendered by default route
        :param adapters: list of adapters to register with API route
        """
        settings = {
            "debug": debug_mode,
            "log_function": self.log_request,
        }

        # Set the up the access log level
        if access_logging is not None:
            try:
                level_val = getattr(logging, access_logging.upper())
                access_log.setLevel(level_val)
            except AttributeError:
                logging.error("Access logging level {} not recognised".format(
                    access_logging))

        # Create an API route
        self.api_route = ApiRoute()

        # Register adapters with the API route and get handlers
        for adapter in adapters:
            self.api_route.register_adapter(adapters[adapter])

        # Initialize adapters for all those that require inter adapter communication
        self.api_route.initialize_adapters()

        handlers = self.api_route.get_handlers()

        # Create a default route for static content and get handlers
        default_route = DefaultRoute(static_path)
        handlers += default_route.get_handlers()

        # Create the Tornado web application for these handlers
        self.application = tornado.web.Application(handlers, **settings)
Exemplo n.º 4
0
 def setup_class(cls):
     cls.api_route = ApiRoute()
Exemplo n.º 5
0
def test_api_route():
    """Simple test fixture that creates an ApiRoute object."""
    ar = ApiRoute()
    yield ar