def test_get_flow_from_file_azure_runs(monkeypatch): client = MagicMock(download_blob=MagicMock()) service = MagicMock(get_blob_client=MagicMock(return_value=client)) monkeypatch.setattr( "prefect.environments.storage.Azure._azure_block_blob_service", service ) f = Flow("test") monkeypatch.setattr( "prefect.environments.storage.azure.extract_flow_from_file", MagicMock(return_value=f), ) storage = Azure(container="container", stored_as_script=True) assert f.name not in storage flow_location = storage.add_flow(f) new_flow = storage.get_flow(flow_location) assert client.download_blob.called assert f.name in storage assert isinstance(new_flow, Flow) assert new_flow.name == "test" assert len(new_flow.tasks) == 0 state = new_flow.run() assert state.is_successful()
def test_get_flow_azure(monkeypatch): client = MagicMock(download_blob=MagicMock()) service = MagicMock(get_blob_client=MagicMock(return_value=client)) monkeypatch.setattr( "prefect.environments.storage.Azure._azure_block_blob_service", service ) f = Flow("test") monkeypatch.setattr("cloudpickle.loads", MagicMock(return_value=f)) storage = Azure(container="container") with pytest.raises(ValueError): storage.get_flow() assert f.name not in storage flow_location = storage.add_flow(f) assert storage.get_flow(flow_location) assert client.download_blob.called assert f.name in storage
def test_get_flow_azure_bucket_key(monkeypatch): client = MagicMock(download_blob=MagicMock()) service = MagicMock(get_blob_client=MagicMock(return_value=client)) monkeypatch.setattr( "prefect.environments.storage.Azure._azure_block_blob_service", service ) f = Flow("test") monkeypatch.setattr("cloudpickle.loads", MagicMock(return_value=f)) storage = Azure(container="container", blob_name="name") assert f.name not in storage flow_location = storage.add_flow(f) assert storage.get_flow(flow_location) assert service.get_blob_client.call_args[1]["container"] == "container" assert service.get_blob_client.call_args[1]["blob"] == flow_location