Skip to content

Commit c0ce8a8

Browse files
authored
Migrate Google example gcs_to_sftp to new design AIP-47 (#25107)
related: #22447, #22430
1 parent 8aa0b24 commit c0ce8a8

File tree

4 files changed

+48
-75
lines changed

4 files changed

+48
-75
lines changed

docs/apache-airflow-providers-google/operators/transfer/gcs_to_sftp.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Copying a single file
4848

4949
The following Operator copies a single file.
5050

51-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_gcs_to_sftp.py
51+
.. exampleinclude:: /../../tests/system/providers/google/cloud/transfers/example_gcs_to_sftp.py
5252
:language: python
5353
:dedent: 4
5454
:start-after: [START howto_operator_gcs_to_sftp_copy_single_file]
@@ -61,7 +61,7 @@ To move the file use the ``move_object`` parameter. Once the file is copied to S
6161
the original file from the Google Storage is deleted. The ``destination_path`` parameter defines the
6262
full path of the file on the SFTP server.
6363

64-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_gcs_to_sftp.py
64+
.. exampleinclude:: /../../tests/system/providers/google/cloud/transfers/example_gcs_to_sftp.py
6565
:language: python
6666
:dedent: 4
6767
:start-after: [START howto_operator_gcs_to_sftp_move_single_file_destination]
@@ -73,7 +73,7 @@ Copying a directory
7373

7474
Use the ``wildcard`` in ``source_path`` parameter to copy a directory.
7575

76-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_gcs_to_sftp.py
76+
.. exampleinclude:: /../../tests/system/providers/google/cloud/transfers/example_gcs_to_sftp.py
7777
:language: python
7878
:dedent: 4
7979
:start-after: [START howto_operator_gcs_to_sftp_copy_directory]
@@ -85,7 +85,7 @@ Moving specific files
8585
Use the ``wildcard`` in ``source_path`` parameter to move the specific files.
8686
The ``destination_path`` defines the path that is prefixed to all copied files.
8787

88-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_gcs_to_sftp.py
88+
.. exampleinclude:: /../../tests/system/providers/google/cloud/transfers/example_gcs_to_sftp.py
8989
:language: python
9090
:dedent: 4
9191
:start-after: [START howto_operator_gcs_to_sftp_move_specific_files]

tests/providers/google/cloud/transfers/test_gcs_to_sftp_system.py

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.

airflow/providers/google/cloud/example_dags/example_gcs_to_sftp.py renamed to tests/system/providers/google/cloud/transfers/example_gcs_to_sftp.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
from airflow.providers.google.cloud.transfers.gcs_to_sftp import GCSToSFTPOperator
2727
from airflow.providers.sftp.sensors.sftp import SFTPSensor
2828

29+
ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
30+
31+
DAG_ID = "example_gcs_to_sftp"
32+
2933
SFTP_CONN_ID = "ssh_default"
3034
BUCKET_SRC = os.environ.get("GCP_GCS_BUCKET_1_SRC", "test-gcs-sftp")
3135
OBJECT_SRC_1 = "parent-1.bin"
@@ -35,13 +39,12 @@
3539
DESTINATION_PATH_2 = "/tmp/dest-dir-1/"
3640
DESTINATION_PATH_3 = "/tmp/dest-dir-2/"
3741

38-
3942
with models.DAG(
40-
"example_gcs_to_sftp",
43+
DAG_ID,
4144
schedule_interval='@once',
4245
start_date=datetime(2021, 1, 1),
4346
catchup=False,
44-
tags=['example'],
47+
tags=['example', 'gcs'],
4548
) as dag:
4649
# [START howto_operator_gcs_to_sftp_copy_single_file]
4750
copy_file_from_gcs_to_sftp = GCSToSFTPOperator(
@@ -113,9 +116,26 @@
113116
path=os.path.join(DESTINATION_PATH_3, OBJECT_SRC_1),
114117
)
115118

116-
move_file_from_gcs_to_sftp >> check_move_file_from_gcs_to_sftp
117-
copy_dir_from_gcs_to_sftp >> check_copy_file_from_gcs_to_sftp
119+
(
120+
# TEST BODY
121+
copy_file_from_gcs_to_sftp
122+
>> check_copy_file_from_gcs_to_sftp
123+
>> move_file_from_gcs_to_sftp
124+
>> check_move_file_from_gcs_to_sftp
125+
>> copy_dir_from_gcs_to_sftp
126+
>> check_copy_dir_from_gcs_to_sftp
127+
>> move_dir_from_gcs_to_sftp
128+
>> check_move_dir_from_gcs_to_sftp
129+
)
130+
131+
from tests.system.utils.watcher import watcher
132+
133+
# This test needs watcher in order to properly mark success/failure
134+
# when "tearDown" task with trigger rule is part of the DAG
135+
list(dag.tasks) >> watcher()
136+
137+
138+
from tests.system.utils import get_test_run # noqa: E402
118139

119-
copy_dir_from_gcs_to_sftp >> move_dir_from_gcs_to_sftp
120-
copy_dir_from_gcs_to_sftp >> check_copy_dir_from_gcs_to_sftp
121-
move_dir_from_gcs_to_sftp >> check_move_dir_from_gcs_to_sftp
140+
# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)
141+
test_run = get_test_run(dag)

0 commit comments

Comments
 (0)