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)
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)
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_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)
def test_initialize_notebook_will_error_on_requirements_pull( self, rg, _client, _requirements, _op, _makedirs): url = 'http://whatever' rg.return_value = MagicMock(spec=requests.Response, status_code=500) platform_persistence.get_client( ).notebooks.get.return_value.requirements_url = url self.assertRaises( NotebookManagementError, lambda: platform_persistence. initialize_notebook_from_platform(TEST_NOTEBOOK_PATH))
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 test_will_regenerate_api_client(self, mock_client): platform_persistence.get_client() mock_client.assert_called_with()
def test_post_save_fetches_urls_from_api(self, _rput, client, _ccc, _op): platform_persistence.post_save({'type': 'notebook'}, '', {}) platform_persistence.get_client( ).notebooks.list_update_links.assert_called_with( TEST_PLATFORM_OBJECT_ID)