You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "mobuchowski (via GitHub)" <gi...@apache.org> on 2023/07/24 20:41:03 UTC

[GitHub] [airflow] mobuchowski commented on a diff in pull request #31360: openlineage, sftp: add OpenLineage support for SFTPOperator

mobuchowski commented on code in PR #31360:
URL: https://github.com/apache/airflow/pull/31360#discussion_r1272733605


##########
tests/providers/sftp/operators/test_sftp.py:
##########
@@ -478,3 +481,112 @@ def test_return_str_when_local_filepath_was_str(self, mock_get):
         return_value = sftp_op.execute(None)
         assert isinstance(return_value, str)
         assert return_value == local_filepath
+
+    LOCAL_FILEPATH = "/path/local"
+    REMOTE_FILEPATH = "/path/remote"
+    LOCAL_DATASET = [
+        Dataset(namespace=f"file://{socket.gethostbyname(socket.gethostname())}:22", name=LOCAL_FILEPATH)
+    ]
+    REMOTE_DATASET = [Dataset(namespace="file://remotehost:22", name=REMOTE_FILEPATH)]
+
+    @pytest.mark.parametrize(
+        "operation, expected",
+        [
+            (SFTPOperation.GET, (REMOTE_DATASET, LOCAL_DATASET)),
+            (SFTPOperation.PUT, (LOCAL_DATASET, REMOTE_DATASET)),
+        ],
+    )
+    @mock.patch("airflow.providers.ssh.hooks.ssh.SSHHook.get_conn", spec=paramiko.SSHClient)
+    @mock.patch("airflow.providers.ssh.hooks.ssh.SSHHook.get_connection", spec=Connection)
+    def test_extract_ssh_conn_id(self, get_connection, get_conn, operation, expected):
+        get_connection.return_value = Connection(
+            conn_id="sftp_conn_id",
+            conn_type="sftp",
+            host="remotehost",
+            port=22,
+        )
+
+        dag_id = "sftp_dag"
+        task_id = "sftp_task"
+
+        task = SFTPOperator(
+            task_id=task_id,
+            ssh_conn_id="sftp_conn_id",
+            dag=DAG(dag_id),
+            start_date=timezone.utcnow(),
+            local_filepath="/path/local",
+            remote_filepath="/path/remote",
+            operation=operation,
+        )
+        lineage = task.get_openlineage_facets_on_start()
+
+        assert lineage.inputs == expected[0]
+        assert lineage.outputs == expected[1]
+
+    @pytest.mark.parametrize(

Review Comment:
   Done.



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