utkarsharma2 commented on code in PR #31360:
URL: https://github.com/apache/airflow/pull/31360#discussion_r1228189249
##########
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:
```
[
(SFTPOperation.GET, (REMOTE_DATASET, LOCAL_DATASET)),
(SFTPOperation.PUT, (LOCAL_DATASET, REMOTE_DATASET)),
],
```
I see this repeating maybe we can refactor it?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]