def test_ssl_verify(self): '''Should verify SSL certificate by default.''' handler = MockHandler() os.environ['DASHBOARD_SERVER_URL'] = '{protocol}://{hostname}:8889' converter.bundle(handler, 'test/resources/no_imports.ipynb') kwargs = converter.requests.post.kwargs self.assertEqual(kwargs['verify'], True)
def test_no_ssl_verify(self): '''Should skip SSL certificate verification.''' os.environ['DASHBOARD_SERVER_NO_SSL_VERIFY'] = 'yes' os.environ['DASHBOARD_SERVER_URL'] = '{protocol}://{hostname}:8889' handler = MockHandler() converter.bundle(handler, 'test/resources/no_imports.ipynb') kwargs = converter.requests.post.kwargs self.assertEqual(kwargs['verify'], False)
def test_url_interpolation(self): '''Should build the server URL from the request Host header.''' os.environ['DASHBOARD_SERVER_URL'] = '{protocol}://{hostname}:8889' handler = MockHandler('notebook-server:8888', 'https') converter.bundle(handler, 'test/resources/no_imports.ipynb') args = converter.requests.post.args self.assertEqual(args[0], 'https://notebook-server:8889/_api/notebooks/no_imports') self.assertEqual(handler.last_redirect, dashboard_link)
def test_upload_token(self): '''Should include an auth token in the request.''' os.environ['DASHBOARD_SERVER_URL'] = 'http://dashboard-server' os.environ['DASHBOARD_SERVER_AUTH_TOKEN'] = 'fake-token' handler = MockHandler() converter.bundle(handler, 'test/resources/no_imports.ipynb') kwargs = converter.requests.post.kwargs self.assertEqual(kwargs['headers'], {'Authorization' : 'token fake-token'})
def test_redirect(self): '''Should redirect to the given URL''' os.environ['DASHBOARD_SERVER_URL'] = '{protocol}://{hostname}:8889' os.environ['DASHBOARD_REDIRECT_URL'] = 'http://{hostname}:3000' handler = MockHandler('notebook-server:8888', 'https') converter.bundle(handler, 'test/resources/no_imports.ipynb') args = converter.requests.post.args self.assertEqual(args[0], 'https://notebook-server:8889/_api/notebooks/no_imports') self.assertEqual(handler.last_redirect, 'http://notebook-server:3000/dashboards/no_imports')
def test_upload_notebook(self): '''Should POST the notebook and redirect to the dashboard server.''' os.environ['DASHBOARD_SERVER_URL'] = 'http://dashboard-server' handler = MockHandler() converter.bundle(handler, 'test/resources/no_imports.ipynb') args = converter.requests.post.args kwargs = converter.requests.post.kwargs self.assertEqual(args[0], 'http://dashboard-server/_api/notebooks/no_imports') self.assertTrue(kwargs['files']['file']) self.assertEqual(kwargs['headers'], {}) self.assertEqual(handler.last_redirect, dashboard_link)
def test_redirect_fallback(self): '''Should redirect to the given URL''' converter.requests.post = MockPost(200, False) os.environ['DASHBOARD_SERVER_URL'] = '{protocol}://{hostname}:8889' os.environ['DASHBOARD_REDIRECT_URL'] = 'http://{hostname}:3000' handler = MockHandler('notebook-server:8888', 'https') converter.bundle(handler, 'test/resources/no_imports.ipynb') args = converter.requests.post.args self.assertEqual(args[0], 'https://notebook-server:8889/_api/notebooks/no_imports') self.assertEqual(handler.last_redirect, 'http://notebook-server:3000/dashboards/no_imports')
def test_upload_zip(self): ''' Should POST the notebook in a zip with resources and redirect to the dashboard server. ''' os.environ['DASHBOARD_SERVER_URL'] = 'http://dashboard-server' handler = MockHandler() converter.requests.post = MockZipPost(200) converter.bundle(handler, 'test/resources/some.ipynb') args = converter.requests.post.args kwargs = converter.requests.post.kwargs self.assertEqual(args[0], 'http://dashboard-server/_api/notebooks/some') self.assertTrue(kwargs['files']['file']) self.assertEqual(kwargs['headers'], {}) self.assertEqual(handler.last_redirect, dashboard_link) self.assertTrue('index.ipynb' in converter.requests.post.zipped_files) self.assertTrue('some.csv' in converter.requests.post.zipped_files)