Пример #1
0
def test_add_flow_to_codecommit_already_added():
    storage = CodeCommit(repo="test/repo", path="flow.py", commit="master")

    f = Flow("test")
    assert f.name not in storage
    assert storage.add_flow(f) == "flow.py"
    assert f.name in storage

    with pytest.raises(ValueError):
        storage.add_flow(f)
Пример #2
0
def test_add_flow_to_codecommit_storage():
    storage = CodeCommit(repo="test/repo", path="flow.py", commit="master")

    f = Flow("test")
    assert f.name not in storage
    assert storage.add_flow(f) == "flow.py"
    assert f.name in storage
Пример #3
0
def test_get_flow_codecommit(monkeypatch):
    client = MagicMock()
    d = {"fileContent": b'import prefect; flow = prefect.Flow("test")'}
    client.__getitem__.side_effect = d.__getitem__
    boto3 = MagicMock(get_file=MagicMock(return_value=client))
    monkeypatch.setattr("prefect.storage.CodeCommit._boto3_client", boto3)

    f = Flow("test")

    monkeypatch.setattr(
        "prefect.storage.github.extract_flow_from_file",
        MagicMock(return_value=f),
    )

    with pytest.raises(ValueError):
        storage = CodeCommit(repo="test/repo")
        storage.get_flow()

    storage = CodeCommit(repo="test/repo", path="flow", commit="master")

    assert f.name not in storage
    flow_location = storage.add_flow(f)

    new_flow = storage.get_flow(flow_location)
    assert new_flow.run()
Пример #4
0
def test_get_flow_codecommit(monkeypatch):
    client = MagicMock()
    d = {"fileContent": b'import prefect; flow = prefect.Flow("test")'}
    client.__getitem__.side_effect = d.__getitem__
    boto3 = MagicMock(get_file=MagicMock(return_value=client))
    monkeypatch.setattr("prefect.storage.CodeCommit._boto3_client", boto3)

    f = Flow("test")

    extract_flow_from_file = MagicMock(return_value=f)
    monkeypatch.setattr(
        "prefect.storage.codecommit.extract_flow_from_file",
        extract_flow_from_file,
    )

    storage = CodeCommit(repo="test/repo", path="flow", commit="master")

    assert f.name not in storage
    storage.add_flow(f)

    new_flow = storage.get_flow(f.name)
    assert extract_flow_from_file.call_args[1]["flow_name"] == f.name
    assert new_flow.run()