Exemplo n.º 1
0
class TestGatewayAppBase(AsyncHTTPTestCase, LogTrapTestCase):
    '''
    Base class for integration style tests using HTTP/Websockets against an
    instance of the gateway app..
    '''
    def tearDown(self):
        if self.app:
            self.app.shutdown()
        super(TestGatewayAppBase, self).tearDown()

    def get_new_ioloop(self):
        '''Use a global zmq ioloop for tests.'''
        return ioloop.IOLoop.current()

    def get_app(self):
        '''Returns a tornado.web.Application for system tests.'''
        if hasattr(self, '_app'):
            return self._app
        self.app = KernelGatewayApp(log_level=logging.CRITICAL)
        self.setup_app()
        self.app.init_configurables()
        self.app.init_webapp()
        return self.app.web_app

    def setup_app(self):
        '''
        Override to configure KernelGatewayApp instance before initializing
        configurables and the web app.
        '''
        pass
Exemplo n.º 2
0
    def test_load_notebook_local(self):
        nb_path = os.path.join(RESOURCES, 'weirdly%20named#notebook.ipynb')
        os.environ['KG_SEED_URI'] = nb_path
        with open(nb_path) as nb_fh:
            nb_contents = nbformat.read(nb_fh, 4)

        app = KernelGatewayApp()
        app.init_configurables()
        self.assertEqual(app.seed_notebook, nb_contents)
Exemplo n.º 3
0
class TestGatewayAppBase(AsyncHTTPTestCase, LogTrapTestCase):
    def tearDown(self):
        if self.app:
            self.app.shutdown()
        super(TestGatewayAppBase, self).tearDown()

    def get_new_ioloop(self):
        '''Use a global zmq ioloop for tests.'''
        return ioloop.IOLoop.current()

    def get_app(self):
        '''Returns a tornado.web.Application for system tests.'''
        if hasattr(self, '_app'):
            return self._app
        self.app = KernelGatewayApp(log_level=logging.CRITICAL)
        self.setup_app()
        self.app.init_configurables()
        self.app.init_webapp()
        return self.app.web_app

    def setup_app(self):
        '''
        Override to configure KernelGatewayApp instance before initializing
        configurables and the web app.
        '''
        pass

    @coroutine
    def spawn_kernel(self, kernel_body='{}'):
        '''
        Code to spawn a kernel and return a websocket connection to it.
        '''
        # Request a kernel
        response = yield self.http_client.fetch(
            self.get_url('/api/kernels'),
            method='POST',
            body=kernel_body
        )
        self.assertEqual(response.code, 201)

        # Connect to the kernel via websocket
        kernel = json_decode(response.body)
        ws_url = 'ws://localhost:{}/api/kernels/{}/channels'.format(
            self.get_http_port(),
            url_escape(kernel['id'])
        )

        ws = yield websocket_connect(ws_url)
        raise Return(ws)
Exemplo n.º 4
0
class TestGatewayAppBase(AsyncHTTPTestCase, LogTrapTestCase):
    """Base class for integration style tests using HTTP/Websockets against an
    instance of the gateway app..

    Attributes
    ----------
    app : KernelGatewayApp
        Instance of the app
    """

    def tearDown(self):
        """Shuts down the app after test run."""
        if self.app:
            self.app.shutdown()
        # Make sure the generated Swagger output is reset for subsequent tests
        SwaggerSpecHandler.output = None
        super(TestGatewayAppBase, self).tearDown()

    def get_new_ioloop(self):
        """Uses a global zmq ioloop for tests."""
        return ioloop.IOLoop.current()

    def get_app(self):
        """Returns a tornado.web.Application for the Tornado test runner."""
        if hasattr(self, "_app"):
            return self._app
        self.app = KernelGatewayApp(log_level=logging.CRITICAL)
        self.setup_app()
        self.app.init_configurables()
        self.setup_configurables()
        self.app.init_webapp()
        return self.app.web_app

    def setup_app(self):
        """Override to configure KernelGatewayApp instance before initializing
        configurables and the web app.
        """
        pass

    def setup_configurables(self):
        """Override to configure further settings, such as the personality.
        """
        pass
Exemplo n.º 5
0
class TestGatewayAppBase(AsyncHTTPTestCase, ExpectLog):
    """Base class for integration style tests using HTTP/Websockets against an
    instance of the gateway app.

    Attributes
    ----------
    app : KernelGatewayApp
        Instance of the app
    """
    def tearDown(self):
        """Shuts down the app after test run."""
        if self.app:
            self.app.shutdown()
        # Make sure the generated Swagger output is reset for subsequent tests
        SwaggerSpecHandler.output = None
        super(TestGatewayAppBase, self).tearDown()

    def get_new_ioloop(self):
        """Uses a global zmq ioloop for tests."""
        return ioloop.IOLoop.current()

    def get_app(self):
        """Returns a tornado.web.Application for the Tornado test runner."""
        if hasattr(self, '_app'):
            return self._app
        self.app = KernelGatewayApp(log_level=logging.CRITICAL)
        self.setup_app()
        self.app.init_configurables()
        self.setup_configurables()
        self.app.init_webapp()
        return self.app.web_app

    def setup_app(self):
        """Override to configure KernelGatewayApp instance before initializing
        configurables and the web app.
        """
        pass

    def setup_configurables(self):
        """Override to configure further settings, such as the personality.
        """
        pass