You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/06/02 09:43:32 UTC

[GitHub] [airflow] turbaszek commented on a change in pull request #9023: Add snowflake to slack operator

turbaszek commented on a change in pull request #9023:
URL: https://github.com/apache/airflow/pull/9023#discussion_r433752229



##########
File path: tests/providers/snowflake/operators/test_snowflake_to_slack.py
##########
@@ -0,0 +1,80 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+from unittest import mock
+
+from airflow.models import DAG
+from airflow.providers.snowflake.operators.snowflake_to_slack import SnowflakeToSlackOperator
+from airflow.utils import timezone
+
+TEST_DAG_ID = 'snowflake_to_slack_unit_test'
+DEFAULT_DATE = timezone.datetime(2017, 1, 1)
+
+
+class TestSnowflakeToSlackOperator(unittest.TestCase):
+    def setUp(self):
+        self.example_dag = DAG('unit_test_dag_snowflake_to_slack', start_date=DEFAULT_DATE)
+
+    @staticmethod
+    def _construct_operator(**kwargs):
+        operator = SnowflakeToSlackOperator(task_id=TEST_DAG_ID, **kwargs)
+        return operator
+
+    @mock.patch('airflow.providers.snowflake.operators.snowflake_to_slack.SnowflakeHook')
+    @mock.patch('airflow.providers.snowflake.operators.snowflake_to_slack.SlackWebhookHook')
+    def test_hooks_and_rendering(self, mock_slack_hook_class, mock_snowflake_hook_class):
+        operator_args = {
+            'snowflake_conn_id': 'snowflake_connection',
+            'slack_conn_id': 'slack_connection',
+            'sql': "sql {{ ds }}",
+            'results_df_name': 'xxxx',
+            'warehouse': 'test_warehouse',
+            'database': 'test_database',
+            'role': 'test_role',
+            'schema': 'test_schema',
+            'parameters': ['1', '2', '3'],
+            'slack_message': 'message: {{ ds }}, {{ xxxx }}',
+            'slack_token': 'test_token',
+            'dag': self.example_dag
+        }
+        snowflake_to_slack_operator = self._construct_operator(**operator_args)
+
+        snowflake_hook = mock_snowflake_hook_class.return_value
+        snowflake_hook.get_pandas_df.return_value = '1234'
+        slack_webhook_hook = mock_slack_hook_class.return_value
+
+        snowflake_to_slack_operator.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True)
+
+        # Test that the Snowflake hook is instantiated with the right parameters
+        mock_snowflake_hook_class.assert_called_with(database='test_database',

Review comment:
       Nice catch! 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org