Пример #1
0
    def test_creds_are_pulled_from_secret_at_runtime(self, monkeypatch):
        task = CreateGitHubPR(token_secret="GITHUB_ACCESS_TOKEN")

        req = MagicMock()
        monkeypatch.setattr(requests, "post", req)

        with prefect.context(secrets=dict(GITHUB_ACCESS_TOKEN={"key": 42})):
            task.run(repo="org/repo")

        assert req.call_args[1]["headers"]["AUTHORIZATION"] == "token {'key': 42}"
Пример #2
0
    def test_creds_secret_can_be_overwritten(self, monkeypatch):
        task = CreateGitHubPR(token_secret="MY_SECRET")

        req = MagicMock()
        monkeypatch.setattr("prefect.tasks.github.prs.requests", req)

        with set_temporary_config({"cloud.use_local_secrets": True}):
            with prefect.context(secrets=dict(MY_SECRET={"key": 42})):
                task.run(repo="org/repo")

        assert req.post.call_args[1]["headers"][
            "AUTHORIZATION"] == "token {'key': 42}"
Пример #3
0
    def test_creds_are_pulled_from_secret_at_runtime(self, monkeypatch):
        task = CreateGitHubPR()

        req = MagicMock()
        monkeypatch.setattr("prefect.tasks.github.prs.requests", req)

        with set_temporary_config({"cloud.use_local_secrets": True}):
            with prefect.context(secrets=dict(
                    GITHUB_ACCESS_TOKEN={"key": 42})):
                task.run(repo="org/repo")

        assert req.post.call_args[1]["headers"][
            "AUTHORIZATION"] == "token {'key': 42}"
Пример #4
0
 def test_initializes_with_nothing_and_sets_defaults(self):
     task = CreateGitHubPR()
     assert task.repo is None
     assert task.body is None
     assert task.title is None
     assert task.head is None
     assert task.base is None
Пример #5
0
 def test_initializes_with_nothing_and_sets_defaults(self):
     task = CreateGitHubPR()
     assert task.repo is None
     assert task.body is None
     assert task.title is None
     assert task.head is None
     assert task.base is None
     assert task.token_secret == "GITHUB_ACCESS_TOKEN"
Пример #6
0
 def test_repo_is_required_eventually(self):
     task = CreateGitHubPR()
     with pytest.raises(ValueError, match="repo"):
         task.run()
Пример #7
0
 def test_initializes_attr_from_kwargs(self, attr):
     task = CreateGitHubPR(**{attr: "my-value"})
     assert getattr(task, attr) == "my-value"
Пример #8
0
 def test_additional_kwargs_passed_upstream(self):
     task = CreateGitHubPR(name="test-task", checkpoint=True, tags=["bob"])
     assert task.name == "test-task"
     assert task.checkpoint is True
     assert task.tags == {"bob"}
Пример #9
0
relevant debug information.
"""
import datetime

import pendulum

from prefect import Flow, task
from prefect.schedules import IntervalSchedule
from prefect.tasks.github import CreateGitHubPR, OpenGitHubIssue
from prefect.triggers import any_failed

pr_task = CreateGitHubPR(
    name="Open dev->master PR",
    repo="PrefectHQ/cloud",
    base="master",
    head="dev",
    title="Bi-weekly Release",
    max_retries=1,
    retry_delay=datetime.timedelta(minutes=1),
)


@task(trigger=any_failed)
def prepare_exception(exc):
    return repr(exc)


issue_task = OpenGitHubIssue(
    name="Open Release Issue",
    repo="PrefectHQ/cloud",
    title="Release Cycle is Broken",
Пример #10
0
 def test_repo_is_required_eventually(self):
     task = CreateGitHubPR()
     with pytest.raises(ValueError) as exc:
         task.run()
     assert "repo" in str(exc.value)