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/01 20:19:56 UTC

[GitHub] [airflow] o-nikolas commented on a diff in pull request #24057: Amazon appflow

o-nikolas commented on code in PR #24057:
URL: https://github.com/apache/airflow/pull/24057#discussion_r887258904


##########
tests/providers/amazon/aws/operators/test_appflow.py:
##########
@@ -0,0 +1,172 @@
+# 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.
+
+from datetime import datetime
+from unittest import mock
+from unittest.mock import ANY
+
+import pytest
+
+from airflow.providers.amazon.aws.operators.appflow import (
+    AppflowRecordsShortCircuitOperator,
+    AppflowRunAfterOperator,
+    AppflowRunBeforeOperator,
+    AppflowRunDailyOperator,
+    AppflowRunFullOperator,
+    AppflowRunOperator,
+)
+from airflow.utils import timezone
+
+CONN_ID = "aws_default"
+DAG_ID = "dag_id"
+TASK_ID = "task_id"
+SHORT_CIRCUIT_TASK_ID = "short_circuit_task_id"
+FLOW_NAME = "flow0"
+EXECUTION_ID = "ex_id"
+CONNECTION_TYPE = "Salesforce"
+SOURCE = "salesforce"
+
+DUMP_COMMON_ARGS = {"aws_conn_id": CONN_ID, "task_id": TASK_ID, "source": SOURCE, "name": FLOW_NAME}
+
+
+@pytest.fixture
+def ctx(create_task_instance):
+    ti = create_task_instance(
+        dag_id=DAG_ID,
+        task_id=TASK_ID,
+        schedule_interval="0 12 * * *",
+    )
+    yield {"task_instance": ti}
+
+
+@pytest.fixture
+def appflow_conn():
+    with mock.patch("airflow.providers.amazon.aws.hooks.appflow.AppflowHook.conn") as mock_conn:
+        mock_conn.describe_flow.return_value = {
+            'sourceFlowConfig': {'connectorType': CONNECTION_TYPE},
+            'tasks': [],
+            'triggerConfig': {'triggerProperties': None},
+            'flowName': FLOW_NAME,
+            'destinationFlowConfigList': {},
+            'lastRunExecutionDetails': {
+                'mostRecentExecutionStatus': 'Successful',
+                'mostRecentExecutionTime': datetime(3000, 1, 1, tzinfo=timezone.utc),
+            },
+        }
+        mock_conn.update_flow.return_value = {}
+        mock_conn.start_flow.return_value = {"executionId": EXECUTION_ID}
+        mock_conn.describe_flow_execution_records.return_value = {
+            "flowExecutions": [{"executionId": EXECUTION_ID, "executionResult": {"recordsProcessed": 1}}]
+        }
+        yield mock_conn
+
+
+def run_assertions_base(appflow_conn, tasks):

Review Comment:
   Nice, I like this helper method for the assertions :smile: 



##########
airflow/providers/amazon/aws/hooks/appflow.py:
##########
@@ -0,0 +1,51 @@
+# 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.
+
+from typing import TYPE_CHECKING
+
+from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
+
+if TYPE_CHECKING:
+    from mypy_boto3_appflow.client import AppflowClient
+
+

Review Comment:
   +1
   This approach is especially nice because it makes the testing for the Hooks very lightweight as well. We just need to ensure the Boto session is being created, no need to faff around with Moto for mocking Boto APIs.



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