Beispiel #1
0
 def test_custom_webhook_url_pulled_from_secrets(self, monkeypatch):
     req = MagicMock()
     monkeypatch.setattr(requests, "post", req)
     t = SlackTask(webhook_secret="MY_URL")
     with set_temporary_config({"cloud.use_local_secrets": True}):
         with context({"secrets": dict(MY_URL="http://foo/bar")}):
             res = t.run(message="o hai mark")
     assert req.call_args[0] == ("http://foo/bar", )
     assert req.call_args[1]["json"]["text"] == "o hai mark"
 def test_webhook_url_pulled_from_secrets(self, monkeypatch):
     req = MagicMock()
     monkeypatch.setattr("prefect.tasks.notifications.slack_task.requests", req)
     t = SlackTask()
     with set_temporary_config({"cloud.use_local_secrets": True}):
         with context({"secrets": dict(SLACK_WEBHOOK_URL="http://foo/bar")}):
             res = t.run(message="o hai mark")
     assert req.post.call_args[0] == ("http://foo/bar",)
     assert req.post.call_args[1]["json"]["text"] == "o hai mark"
        ShouldNotify
        NotificationMessage
        Notify [SlackTask]
    """
    repository = Parameter("repository", default="prefect")
    owner = Parameter("owner", default="PrefectHQ")

    stars = GetStars(name="Get Stars",
                     max_retries=2,
                     retry_delay=timedelta(minutes=1))(repository=repository,
                                                       owner=owner)

    should_notify = ShouldNotify()(stars=stars)

    with case(should_notify, True):
        message = NotificationMessage()(repository=repository,
                                        owner=owner,
                                        stars=stars)

        notification = SlackTask(
            webhook_secret="STARGAZERS_SLACK_WEBHOOK_TOKEN")(message=message)

flow.storage = GitHub(
    repo="znicholasbrown/stargazers",
    path="/stargazers.flow.py",
    secrets=["GITHUB_AUTH_TOKEN"],
)

flow.register(project_name="PROJECT: Nicholas")
# flow.run()
Beispiel #4
0
 def test_kwargs_get_passed_to_task_init(self):
     t = SlackTask(name="bob", checkpoint=True, tags=["foo"])
     assert t.name == "bob"
     assert t.checkpoint is True
     assert t.tags == {"foo"}
Beispiel #5
0
 def test_inits_with_no_args(self):
     t = SlackTask()
     assert t
Beispiel #6
0
from prefect import Task, Flow
from prefect.tasks.notifications import SlackTask

class GetValue(Task):
    def run(self):
        return "Test SlackTask!"


flow = Flow("slack-test")

value = GetValue()
slack_task = SlackTask()

slack_task.set_upstream(value, key="message", flow=flow)

flow.run()