Exemple #1
0
def test_build_no_upload_if_file(monkeypatch):
    storage = Azure(container="container", stored_as_script=True)

    with pytest.raises(ValueError):
        storage.build()

    storage = Azure(container="container", stored_as_script=True, blob_name="flow.py")
    assert storage == storage.build()
Exemple #2
0
def test_upload_flow_to_azure_blob_name(monkeypatch):
    client = MagicMock(upload_blob=MagicMock())
    service = MagicMock(get_blob_client=MagicMock(return_value=client))
    monkeypatch.setattr("prefect.storage.Azure._azure_block_blob_service", service)

    storage = Azure(container="container", blob_name="name")

    f = Flow("test")
    assert storage.add_flow(f)
    assert storage.build()

    assert service.get_blob_client.call_args[1]["container"] == "container"
    assert service.get_blob_client.call_args[1]["blob"] == "name"
Exemple #3
0
def test_upload_flow_to_azure(monkeypatch):
    client = MagicMock(upload_blob=MagicMock())
    service = MagicMock(get_blob_client=MagicMock(return_value=client))
    monkeypatch.setattr("prefect.storage.Azure._azure_block_blob_service", service)

    storage = Azure(container="container")

    f = Flow("test")
    assert f.name not in storage
    assert storage.add_flow(f)
    assert storage.build()
    assert client.upload_blob.called
    assert f.name in storage
def test_upload_flow_to_azure_blob_overwrite(monkeypatch, overwrite):
    client = MagicMock(upload_blob=MagicMock())
    service = MagicMock(get_blob_client=MagicMock(return_value=client))
    monkeypatch.setattr("prefect.storage.Azure._azure_block_blob_service",
                        service)

    storage = Azure(container="container", overwrite=overwrite)

    f = Flow("test")
    assert storage.add_flow(f)
    assert storage.build()

    client.upload_blob.assert_called_once_with(unittest.mock.ANY,
                                               overwrite=overwrite)
def test_upload_flow_to_azure(monkeypatch):
    client = MagicMock(upload_blob=MagicMock())
    service = MagicMock(get_blob_client=MagicMock(return_value=client))
    monkeypatch.setattr("prefect.storage.Azure._azure_block_blob_service",
                        service)

    storage = Azure(container="container")

    f = Flow("test")
    assert f.name not in storage
    assert storage.add_flow(f)
    assert storage.build()
    client.upload_blob.assert_called_once_with(flow_to_bytes_pickle(f),
                                               overwrite=False)
    assert f.name in storage