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 2022/06/26 07:30:18 UTC

[GitHub] [airflow] eladkal commented on a diff in pull request #24663: Adding generic SqlToSlackOperator

eladkal commented on code in PR #24663:
URL: https://github.com/apache/airflow/pull/24663#discussion_r906770142


##########
tests/providers/presto/transfers/test_presto_to_slack.py:
##########
@@ -41,37 +41,60 @@ def _construct_operator(**kwargs):
         operator = PrestoToSlackOperator(task_id=TEST_DAG_ID, **kwargs)
         return operator
 
-    @mock.patch('airflow.providers.presto.transfers.presto_to_slack.PrestoHook')
-    @mock.patch('airflow.providers.presto.transfers.presto_to_slack.SlackWebhookHook')
-    def test_hooks_and_rendering(self, mock_slack_hook_class, mock_presto_hook_class):
+    @mock.patch('airflow.providers.slack.transfers.sql_to_slack.SlackWebhookHook')
+    def test_hooks_and_rendering_with_slack_conn(self, mock_slack_hook_class):

Review Comment:
   This test file should be minimal now.. only the tests that we need to verify that `PrestoToSlackOperator` is successfully "converted" into the new operator. All the other tests logic should be in `test_sql_to_slack.py`
   The reasoning for this is that once we remove `PrestoToSlackOperator` we will also remove it's test file and by doing so we don't want to lose any tests that are important.



##########
tests/system/providers/slack/example_sql_to_slack.py:
##########
@@ -0,0 +1,55 @@
+#
+# 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.
+"""
+Example DAG using SqlToSlackOperator.
+"""
+
+import os
+from datetime import datetime
+
+from airflow import models
+from airflow.providers.slack.transfers.sql_to_slack import SqlToSlackOperator
+
+PRESTO_TABLE = os.environ.get("PRESTO_TABLE", "test_table")
+SQL_CONN_ID = 'presto_default'
+ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
+DAG_ID = "example_sql_to_slack"
+
+with models.DAG(
+    dag_id=DAG_ID,
+    schedule_interval='@once',  # Override to match your needs
+    start_date=datetime(2022, 1, 1),
+    catchup=False,
+    tags=["example"],
+) as dag:
+    # [START howto_operator_sql_to_slack]
+    SqlToSlackOperator(
+        task_id="presto_to_slack",
+        sql_conn_id=SQL_CONN_ID,
+        sql=f"SELECT col FROM {PRESTO_TABLE}",

Review Comment:
   ```suggestion
           sql=f"SELECT col FROM {SQL_TABLE}",
   ```



##########
tests/providers/snowflake/transfers/test_snowflake_to_slack.py:
##########
@@ -20,6 +20,7 @@
 from airflow.models import DAG
 from airflow.providers.snowflake.transfers.snowflake_to_slack import SnowflakeToSlackOperator
 from airflow.utils import timezone
+from tests.test_utils.config import conf_vars
 from tests.test_utils.db import clear_db_runs
 

Review Comment:
   Same comment like on the presto test file



##########
tests/system/providers/slack/example_sql_to_slack.py:
##########
@@ -0,0 +1,55 @@
+#
+# 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.
+"""
+Example DAG using SqlToSlackOperator.
+"""
+
+import os
+from datetime import datetime
+
+from airflow import models
+from airflow.providers.slack.transfers.sql_to_slack import SqlToSlackOperator
+
+PRESTO_TABLE = os.environ.get("PRESTO_TABLE", "test_table")

Review Comment:
   Lets not use Presto names as it's not longer Presto example :)
   ```suggestion
   SQL_TABLE = os.environ.get("SQL_TABLE", "test_table")
   ```



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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