Beispiel #1
0
 def test_initialize_notebook_will_get_nb_from_platform(
         self, rg, _client, _op):
     rg.return_value = MagicMock(spec=requests.Response,
                                 status_code=200,
                                 response={})
     platform_persistence.initialize_notebook_from_platform()
     platform_persistence.get_client().notebooks.get.assert_called_with(
         TEST_PLATFORM_OBJECT_ID)
Beispiel #2
0
 def test_initialize_notebook_will_use_s3_notebook_if_not_new_and_git_notebook_exists(self, rg, _client, _op,
                                                                                      _makedirs, nbwrite, isfile):
     rg.return_value = MagicMock(spec=requests.Response, status_code=200, content=SAMPLE_NOTEBOOK)
     platform_persistence.get_client().notebooks.get.return_value.notebooks_url = 'something'
     platform_persistence.get_client().notebooks.get.return_value.requirements_url = None
     isfile.return_value = True
     platform_persistence.initialize_notebook_from_platform(TEST_NOTEBOOK_PATH)
     nbwrite.assert_called_with(ANY, ANY)
Beispiel #3
0
 def test_initialize_notebook_will_pull_nb_from_url(self, rg, _client, requirements, _op, _makedirs):
     url = 'http://whatever'
     rg.return_value = MagicMock(spec=requests.Response, status_code=200, content=SAMPLE_NOTEBOOK)
     platform_persistence.get_client().notebooks.get.return_value.notebook_url = url
     platform_persistence.get_client().notebooks.get.return_value.requirements_url = None
     platform_persistence.initialize_notebook_from_platform(TEST_NOTEBOOK_PATH)
     rg.assert_called_with(url)
     requirements.assert_not_called()
 def test_initialize_notebook_will_get_nb_from_platform(
         self, rg, _client, _op, _makedirs):
     rg.return_value = MagicMock(spec=requests.Response,
                                 status_code=200,
                                 content=SAMPLE_NOTEBOOK)
     platform_persistence.initialize_notebook_from_platform(
         TEST_NOTEBOOK_PATH)
     platform_persistence.get_client().notebooks.get.assert_called_with(
         TEST_PLATFORM_OBJECT_ID)
 def test_initialize_notebook_will_create_directories_if_needed(
         self, rg, makedirs, _client, _op):
     rg.return_value = MagicMock(spec=requests.Response,
                                 status_code=200,
                                 content=SAMPLE_NOTEBOOK)
     platform_persistence.initialize_notebook_from_platform(
         TEST_NOTEBOOK_PATH)
     directory = os.path.dirname(TEST_NOTEBOOK_PATH)
     makedirs.assert_called_with(directory)
Beispiel #6
0
 def test_initialize_notebook_will_pull_requirements(
         self, rg, _client, requirements, _op):
     url = 'http://whatever'
     rg.return_value = MagicMock(spec=requests.Response,
                                 status_code=200,
                                 response={})
     platform_persistence.get_client(
     ).notebooks.get.return_value.requirements_url = url
     platform_persistence.initialize_notebook_from_platform()
     requirements.assert_called_with(url)
def get_notebook(notebook_full_path):
    try:
        platform_persistence.initialize_notebook_from_platform(
            notebook_full_path)
        platform_persistence.post_save({'type': 'notebook'},
                                       notebook_full_path, None)
    except platform_persistence.NotebookManagementError as e:
        platform_persistence.logger.error(str(e))
        platform_persistence.logger.warn(
            'Killing the notebook process b/c of a startup issue')
        os.kill(os.getpid(), signal.SIGTERM)
 def test_initialize_notebook_will_set_new_notebook_flag_to_false(
         self, rg, _client, _op, _makedirs, nbwrite):
     rg.return_value = MagicMock(spec=requests.Response,
                                 status_code=200,
                                 content=SAMPLE_NEW_NOTEBOOK)
     platform_persistence.get_client(
     ).notebooks.get.return_value.notebooks_url = 'something'
     platform_persistence.get_client(
     ).notebooks.get.return_value.requirements_url = None
     platform_persistence.initialize_notebook_from_platform(
         TEST_NOTEBOOK_PATH)
     nbwrite.assert_called_with(NotebookWithoutNewFlag(), ANY)
Beispiel #9
0
 def test_initialize_notebook_will_throw_error_on_nb_pull(
         self, rg, _client, _op):
     rg.return_value = MagicMock(spec=requests.Response,
                                 status_code=500,
                                 response={})
     self.assertRaises(
         NotebookManagementError,
         lambda: platform_persistence.initialize_notebook_from_platform())
Beispiel #10
0
 def test_initialize_notebook_will_error_on_requirements_pull(
         self, rg, _client, _requirements, _op):
     url = 'http://whatever'
     rg.return_value = MagicMock(spec=requests.Response,
                                 status_code=500,
                                 response={})
     platform_persistence.get_client(
     ).notebooks.get.return_value.requirements_url = url
     self.assertRaises(
         NotebookManagementError,
         lambda: platform_persistence.initialize_notebook_from_platform())
c.NotebookApp.allow_origin = '*'
c.NotebookApp.port = 8888
c.NotebookApp.open_browser = False
c.NotebookApp.token = ''
c.NotebookApp.tornado_settings = {
    'headers': {
        'Content-Security-Policy': "frame-ancestors *"
    }
}
c.MultiKernelManager.default_kernel_name = os.environ['DEFAULT_KERNEL']
c.NotebookApp.allow_root = True

# Download notebook and initialize post-save hook
try:
    if not os.environ.get('GIT_FILE'):
        platform_persistence.initialize_notebook_from_platform()
    # force a save of the preview so that we have one in case
    # the user never generates one
    _, preview_url = platform_persistence.get_update_urls()
    platform_persistence.generate_and_save_preview(preview_url, NOTEBOOK_PATH)
except NotebookManagementError as e:
    platform_persistence.logger.error(str(e))
    platform_persistence.logger.warn(
        'Killing the notebook process b/c of a startup issue')
    os.kill(os.getpid(), signal.SIGTERM)

git_enabled = os.environ.get('GIT_FILE') is not None
post_save = platform_persistence.post_save(git_enabled=git_enabled)
c.FileContentsManager.post_save_hook = post_save

REQUIREMENTS_PATH = os.path.expanduser(