Exemplo n.º 1
0
def test_add_flow_to_gitlab_storage():
    storage = GitLab(repo="test/repo", path="flow.py")

    f = Flow("test")
    assert f.name not in storage
    assert storage.add_flow(f) == "flow.py"
    assert f.name in storage
Exemplo n.º 2
0
def test_get_gitlab_client_errors_if_secret_provided_and_not_found(
        monkeypatch):
    mock_gitlab = MagicMock(wraps=gitlab.Gitlab)
    monkeypatch.setattr("gitlab.Gitlab", mock_gitlab)
    storage = GitLab(repo="test/repo",
                     path="flow.py",
                     access_token_secret="MISSING")
    with context(secrets={}):
        with pytest.raises(Exception, match="MISSING"):
            storage._get_gitlab_client()
Exemplo n.º 3
0
def test_add_flow_to_gitlab_already_added():
    storage = GitLab(repo="test/repo", path="flow.py")

    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) as ex:
        storage.add_flow(f)

    assert "Name conflict" in str(ex.value)
Exemplo n.º 4
0
def test_get_gitlab_client(monkeypatch, secret_name, secret_arg, host):
    orig_gitlab = gitlab.Gitlab
    mock_gitlab = MagicMock(wraps=gitlab.Gitlab)
    monkeypatch.setattr("gitlab.Gitlab", mock_gitlab)
    storage = GitLab(repo="test/repo",
                     path="flow.py",
                     host=host,
                     access_token_secret=secret_arg)
    with context(secrets={secret_name: "TEST-VAL"}):
        client = storage._get_gitlab_client()
    assert isinstance(client, orig_gitlab)
    assert mock_gitlab.call_args[0][0] == (host or "https://gitlab.com")
    assert mock_gitlab.call_args[1]["private_token"] == "TEST-VAL"
Exemplo n.º 5
0
def test_create_gitlab_storage_init_args():
    storage = GitLab(repo="test/repo", path="flow.py", secrets=["auth"])
    assert storage
    assert storage.flows == dict()
    assert storage.repo == "test/repo"
    assert storage.path == "flow.py"
    assert storage.secrets == ["auth"]
Exemplo n.º 6
0
def test_get_flow_gitlab(monkeypatch):
    f = Flow("test")

    gitlab = MagicMock()
    monkeypatch.setattr("gitlab.Gitlab", gitlab)

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

    storage = GitLab(repo="test/repo", path="flow.py")

    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()
Exemplo n.º 7
0
def test_gitlab_client_server(monkeypatch):
    gitlab = MagicMock()
    monkeypatch.setattr("prefect.utilities.git.Gitlab", gitlab)

    storage = GitLab(repo="test/repo", host="http://localhost:1234")

    credentials = "ACCESS_TOKEN"
    with context(secrets=dict(GITLAB_ACCESS_TOKEN=credentials)):
        gitlab_client = storage._gitlab_client

    assert gitlab_client
    gitlab.assert_called_with("http://localhost:1234",
                              private_token="ACCESS_TOKEN")
Exemplo n.º 8
0
def test_get_flow_gitlab(monkeypatch):
    f = Flow("test")

    gitlab = MagicMock()
    monkeypatch.setattr("prefect.utilities.git.Gitlab", gitlab)

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

    with pytest.raises(ValueError) as ex:
        storage = GitLab(repo="test/repo")
        storage.get_flow()

    assert "No flow location provided" in str(ex.value)

    storage = GitLab(repo="test/repo", path="flow.py")

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

    new_flow = storage.get_flow(flow_location)
    assert new_flow.run()
Exemplo n.º 9
0
def test_create_gitlab_storage():
    storage = GitLab(repo="test/repo")
    assert storage
    assert storage.logger
Exemplo n.º 10
0
                },
                "run_config": run.serialize(),
            }),
            run,
        )
        assert env_vars["PREFECT__LOGGING__LEVEL"] == expected_logging_level


@pytest.mark.parametrize(
    "storage",
    [
        Local(directory="test"),
        GCS(bucket="test"),
        S3(bucket="test"),
        Azure(container="test"),
        GitLab("test/repo", path="path/to/flow.py"),
        Bitbucket(project="PROJECT", repo="test-repo", path="test-flow.py"),
        CodeCommit("test/repo", path="path/to/flow.py"),
        Webhook(
            build_request_kwargs={"url": "test-service/upload"},
            build_request_http_method="POST",
            get_flow_request_kwargs={"url": "test-service/download"},
            get_flow_request_http_method="GET",
        ),
    ],
)
def test_local_agent_deploy_processes_valid_storage(storage, monkeypatch):
    popen = MagicMock()
    monkeypatch.setattr("prefect.agent.local.agent.Popen", popen)

    agent = LocalAgent()