You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/01/27 13:05:29 UTC
[airflow] branch main updated: Return slack api call response in slack_hook (#21107)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 0ac3b8c Return slack api call response in slack_hook (#21107)
0ac3b8c is described below
commit 0ac3b8c3dd749c59e60cf0169580b9e7c5049d9e
Author: Ping Zhang <pi...@umich.edu>
AuthorDate: Thu Jan 27 05:04:43 2022 -0800
Return slack api call response in slack_hook (#21107)
---
airflow/providers/slack/hooks/slack.py | 8 ++++++--
docs/spelling_wordlist.txt | 1 +
tests/providers/slack/hooks/test_slack.py | 9 ++++++---
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/airflow/providers/slack/hooks/slack.py b/airflow/providers/slack/hooks/slack.py
index 499802c..c00f010 100644
--- a/airflow/providers/slack/hooks/slack.py
+++ b/airflow/providers/slack/hooks/slack.py
@@ -19,6 +19,7 @@
from typing import Any, Optional
from slack_sdk import WebClient
+from slack_sdk.web.slack_response import SlackResponse
from airflow.exceptions import AirflowException
from airflow.hooks.base import BaseHook
@@ -78,7 +79,7 @@ class SlackHook(BaseHook):
raise AirflowException('Cannot get token: No valid Slack token nor slack_conn_id supplied.')
- def call(self, api_method: str, **kwargs) -> None:
+ def call(self, api_method: str, **kwargs) -> SlackResponse:
"""
Calls Slack WebClient `WebClient.api_call` with given arguments.
@@ -89,5 +90,8 @@ class SlackHook(BaseHook):
form-encoding will take place. Optional.
:param params: The URL parameters to append to the URL. Optional.
:param json: JSON for the body to attach to the request. Optional.
+ :return: The server's response to an HTTP request. Data from the response can be
+ accessed like a dict. If the response included 'next_cursor' it can be
+ iterated on to execute subsequent requests.
"""
- self.client.api_call(api_method, **kwargs)
+ return self.client.api_call(api_method, **kwargs)
diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt
index bff69d3..797a761 100644
--- a/docs/spelling_wordlist.txt
+++ b/docs/spelling_wordlist.txt
@@ -333,6 +333,7 @@ Seedlist
Sendgrid
SerializedDAG
SlackHook
+SlackResponse
SnowflakeHook
Spark
SparkPi
diff --git a/tests/providers/slack/hooks/test_slack.py b/tests/providers/slack/hooks/test_slack.py
index 5a23594..e25f80b 100644
--- a/tests/providers/slack/hooks/test_slack.py
+++ b/tests/providers/slack/hooks/test_slack.py
@@ -122,11 +122,14 @@ class TestSlackHook(unittest.TestCase):
with pytest.raises(SlackApiError):
slack_hook.call(test_method, data=test_api_params)
- @mock.patch('airflow.providers.slack.hooks.slack.WebClient.api_call', autospec=True)
@mock.patch('airflow.providers.slack.hooks.slack.WebClient')
- def test_api_call(self, mock_slack_client, mock_slack_api_call):
+ def test_api_call(self, slack_client_class_mock):
+ slack_client_mock = mock.Mock()
+ slack_client_class_mock.return_value = slack_client_mock
+ slack_client_mock.api_call.return_value = {'ok': True}
+
slack_hook = SlackHook(token='test_token')
test_api_json = {'channel': 'test_channel'}
slack_hook.call("chat.postMessage", json=test_api_json)
- mock_slack_api_call.assert_called_once_with(mock_slack_client, "chat.postMessage", json=test_api_json)
+ slack_client_mock.api_call.assert_called_with("chat.postMessage", json=test_api_json)