Пример #1
0
    def test_trust_xheaders(self):

        app = KernelGatewayApp()
        self.assertEqual(app.trust_xheaders, False)
        os.environ['KG_TRUST_XHEADERS'] = 'true'
        app = KernelGatewayApp()
        self.assertEqual(app.trust_xheaders, True)
Пример #2
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
 def test_seed_kernel_not_available(self):
     """
     Server should error because seed notebook requires a kernel that is not
     installed.
     """
     app = KernelGatewayApp()
     app.seed_uri = os.path.join(RESOURCES, "unknown_kernel.ipynb")
     self.assertRaises(NoSuchKernel, app.init_configurables)
 def test_prespawn_max_conflict(self):
     """Server should error if prespawn count is greater than max allowed
     kernels.
     """
     app = KernelGatewayApp()
     app.prespawn_count = 3
     app.max_kernels = 2
     self.assertRaises(RuntimeError, app.init_configurables)
 def test_seed_kernel_not_available(self):
     """
     Server should error because seed notebook requires a kernel that is not
     installed.
     """
     app = KernelGatewayApp()
     app.seed_uri = os.path.join(RESOURCES, 'unknown_kernel.ipynb')
     self.assertRaises(NoSuchKernel, app.init_configurables)
 def test_prespawn_max_conflict(self):
     """Server should error if prespawn count is greater than max allowed
     kernels.
     """
     app = KernelGatewayApp()
     app.prespawn_count = 3
     app.max_kernels = 2
     self.assertRaises(RuntimeError, app.init_configurables)
 def test_seed_kernel_failing(self):
     """
     Server should error because seed notebook requires a kernel that is not
     installed.
     """
     app = KernelGatewayApp()
     app.prespawn_count = 1
     app.seed_uri = os.path.join(RESOURCES, 'failing_code.ipynb')
     self.assertRaises(RuntimeError, app.init_configurables)
Пример #8
0
 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
Пример #9
0
 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.app.init_webapp()
     return self.app.web_app
Пример #10
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)
Пример #11
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)
Пример #12
0
 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.app.init_webapp()
     return self.app.web_app
Пример #13
0
 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
Пример #14
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
Пример #15
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
Пример #16
0
 def test_ssl_options(self):
     app = KernelGatewayApp()
     ssl_options = app._build_ssl_options()
     self.assertIsNone(ssl_options)
     app = KernelGatewayApp()
     os.environ['KG_CERTFILE'] = '/test/fake.crt'
     ssl_options = app._build_ssl_options()
     self.assertEqual(ssl_options['ssl_version'], 5)
Пример #17
0
    def test_config_env_vars(self):
        """Env vars should be honored for traitlets."""
        # Environment vars are always strings
        os.environ['KG_PORT'] = '1234'
        os.environ['KG_PORT_RETRIES'] = '4321'
        os.environ['KG_IP'] = '1.1.1.1'
        os.environ['KG_AUTH_TOKEN'] = 'fake-token'
        os.environ['KG_ALLOW_CREDENTIALS'] = 'true'
        os.environ['KG_ALLOW_HEADERS'] = 'Authorization'
        os.environ['KG_ALLOW_METHODS'] = 'GET'
        os.environ['KG_ALLOW_ORIGIN'] = '*'
        os.environ['KG_EXPOSE_HEADERS'] = 'X-Fake-Header'
        os.environ['KG_MAX_AGE'] = '5'
        os.environ['KG_BASE_URL'] = '/fake/path'
        os.environ['KG_MAX_KERNELS'] = '1'
        os.environ['KG_SEED_URI'] = 'fake-notebook.ipynb'
        os.environ['KG_PRESPAWN_COUNT'] = '1'
        os.environ['KG_FORCE_KERNEL_NAME'] = 'fake_kernel_forced'
        os.environ['KG_DEFAULT_KERNEL_NAME'] = 'fake_kernel'
        os.environ['KG_KEYFILE'] = '/test/fake.key'
        os.environ['KG_CERTFILE'] = '/test/fake.crt'
        os.environ['KG_CLIENT_CA'] = '/test/fake_ca.crt'
        os.environ['KG_SSL_VERSION'] = '3'
        os.environ['KG_TRUST_XHEADERS'] = 'false'

        app = KernelGatewayApp()

        self.assertEqual(app.port, 1234)
        self.assertEqual(app.port_retries, 4321)
        self.assertEqual(app.ip, '1.1.1.1')
        self.assertEqual(app.auth_token, 'fake-token')
        self.assertEqual(app.allow_credentials, 'true')
        self.assertEqual(app.allow_headers, 'Authorization')
        self.assertEqual(app.allow_methods, 'GET')
        self.assertEqual(app.allow_origin, '*')
        self.assertEqual(app.expose_headers, 'X-Fake-Header')
        self.assertEqual(app.max_age, '5')
        self.assertEqual(app.base_url, '/fake/path')
        self.assertEqual(app.max_kernels, 1)
        self.assertEqual(app.seed_uri, 'fake-notebook.ipynb')
        self.assertEqual(app.prespawn_count, 1)
        self.assertEqual(app.default_kernel_name, 'fake_kernel')
        self.assertEqual(app.force_kernel_name, 'fake_kernel_forced')
        self.assertEqual(app.keyfile, '/test/fake.key')
        self.assertEqual(app.certfile, '/test/fake.crt')
        self.assertEqual(app.client_ca, '/test/fake_ca.crt')
        self.assertEqual(app.ssl_version, 3)
        self.assertEqual(app.trust_xheaders, False)
Пример #18
0
    def test_config_env_vars(self):
        """Env vars should be honored for traitlets."""
        # Environment vars are always strings
        os.environ['KG_PORT'] = '1234'
        os.environ['KG_PORT_RETRIES'] = '4321'
        os.environ['KG_IP'] = '1.1.1.1'
        os.environ['KG_AUTH_TOKEN'] = 'fake-token'
        os.environ['KG_ALLOW_CREDENTIALS'] = 'true'
        os.environ['KG_ALLOW_HEADERS'] = 'Authorization'
        os.environ['KG_ALLOW_METHODS'] = 'GET'
        os.environ['KG_ALLOW_ORIGIN'] = '*'
        os.environ['KG_EXPOSE_HEADERS'] = 'X-Fake-Header'
        os.environ['KG_MAX_AGE'] = '5'
        os.environ['KG_BASE_URL'] = '/fake/path'
        os.environ['KG_MAX_KERNELS'] = '1'
        os.environ['KG_SEED_URI'] = 'fake-notebook.ipynb'
        os.environ['KG_PRESPAWN_COUNT'] = '1'
        os.environ['KG_DEFAULT_KERNEL_NAME'] = 'fake_kernel'
        os.environ['KG_LIST_KERNELS'] = 'True'
        os.environ['KG_ALLOW_NOTEBOOK_DOWNLOAD'] = 'True'

        app = KernelGatewayApp()

        self.assertEqual(app.port, 1234)
        self.assertEqual(app.port_retries, 4321)
        self.assertEqual(app.ip, '1.1.1.1')
        self.assertEqual(app.auth_token, 'fake-token')
        self.assertEqual(app.allow_credentials, 'true')
        self.assertEqual(app.allow_headers, 'Authorization')
        self.assertEqual(app.allow_methods, 'GET')
        self.assertEqual(app.allow_origin, '*')
        self.assertEqual(app.expose_headers, 'X-Fake-Header')
        self.assertEqual(app.max_age, '5')
        self.assertEqual(app.base_url, '/fake/path')
        self.assertEqual(app.max_kernels, 1)
        self.assertEqual(app.seed_uri, 'fake-notebook.ipynb')
        self.assertEqual(app.prespawn_count, 1)
        self.assertEqual(app.default_kernel_name, 'fake_kernel')
        self.assertEqual(app.list_kernels, True)
        self.assertEqual(app.allow_notebook_download, True)