You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by da...@apache.org on 2017/11/16 01:52:22 UTC

incubator-airflow git commit: [AIRFLOW-1819] Fix slack operator unittest bug

Repository: incubator-airflow
Updated Branches:
  refs/heads/master d8e8f9014 -> 3c8f7747b


[AIRFLOW-1819] Fix slack operator unittest bug

Fix failing slack operator unittest and add test
coverage.

Closes #2791 from yrqls21/kevin-yang-fix-unit-test


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/3c8f7747
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/3c8f7747
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/3c8f7747

Branch: refs/heads/master
Commit: 3c8f7747b08ca5c23233799e56a040f60e3d0fc6
Parents: d8e8f90
Author: Kevin Yang <ke...@airbnb.com>
Authored: Wed Nov 15 17:52:06 2017 -0800
Committer: Dan Davydov <da...@airbnb.com>
Committed: Wed Nov 15 17:52:09 2017 -0800

----------------------------------------------------------------------
 tests/operators/slack_operator.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/3c8f7747/tests/operators/slack_operator.py
----------------------------------------------------------------------
diff --git a/tests/operators/slack_operator.py b/tests/operators/slack_operator.py
index 5e40648..4d6b553 100644
--- a/tests/operators/slack_operator.py
+++ b/tests/operators/slack_operator.py
@@ -58,6 +58,7 @@ class SlackAPIPostOperatorTestCase(unittest.TestCase):
             }
         ]
         self.test_attachments_in_json = json.dumps(self.test_attachments)
+        self.test_api_params = {'key': 'value'}
         self.test_kwarg = 'test_kwarg'
 
         self.expected_method = 'chat.postMessage'
@@ -69,7 +70,7 @@ class SlackAPIPostOperatorTestCase(unittest.TestCase):
             'attachments': self.test_attachments_in_json,
         }
 
-    def __construct_operator(self, test_token, test_slack_conn_id):
+    def __construct_operator(self, test_token, test_slack_conn_id, test_api_params=None):
         return SlackAPIPostOperator(
             task_id='slack',
             username=self.test_username,
@@ -79,6 +80,7 @@ class SlackAPIPostOperatorTestCase(unittest.TestCase):
             text=self.test_text,
             icon_url=self.test_icon_url,
             attachments=self.test_attachments,
+            api_params=test_api_params,
             kwarg=self.test_kwarg
         )
 
@@ -96,6 +98,14 @@ class SlackAPIPostOperatorTestCase(unittest.TestCase):
 
         slack_hook_mock.call.assert_called_with(self.expected_method, self.expected_api_params)
 
+        slack_api_post_operator = self.__construct_operator(test_token, None, self.test_api_params)
+
+        slack_api_post_operator.execute()
+
+        slack_hook_class_mock.assert_called_with(token=test_token, slack_conn_id=None)
+
+        slack_hook_mock.call.assert_called_with(self.expected_method, self.test_api_params)
+
     @mock.patch('airflow.operators.slack_operator.SlackHook')
     def test_execute_with_slack_conn_id_only(self, slack_hook_class_mock):
         slack_hook_mock = mock.Mock()
@@ -121,13 +131,13 @@ class SlackAPIPostOperatorTestCase(unittest.TestCase):
         test_token = 'test_token'
         test_slack_conn_id = 'test_slack_conn_id'
 
-        slack_api_post_operator = self.__construct_operator(test_token, None)
+        slack_api_post_operator = self.__construct_operator(test_token, None, self.test_api_params)
         self.assertEqual(slack_api_post_operator.token, test_token)
         self.assertEqual(slack_api_post_operator.slack_conn_id, None)
         self.assertEqual(slack_api_post_operator.method, self.expected_method)
         self.assertEqual(slack_api_post_operator.text, self.test_text)
         self.assertEqual(slack_api_post_operator.channel, self.test_channel)
-        self.assertEqual(slack_api_post_operator.api_params, self.expected_api_params)
+        self.assertEqual(slack_api_post_operator.api_params, self.test_api_params)
         self.assertEqual(slack_api_post_operator.username, self.test_username)
         self.assertEqual(slack_api_post_operator.icon_url, self.test_icon_url)
         self.assertEqual(slack_api_post_operator.attachments, self.test_attachments)