Skip to content

Commit 81b2761

Browse files
authored
add example dag and system test for GoogleSheetsToGCSOperator (#9056)
* add example dag and system test for sheets_to_gcs * remove sheets_to_gcs in missing example dags
1 parent decf7e8 commit 81b2761

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
import os
20+
21+
from airflow import models
22+
from airflow.providers.google.cloud.operators.sheets_to_gcs import GoogleSheetsToGCSOperator
23+
from airflow.utils.dates import days_ago
24+
25+
BUCKET = os.environ.get("GCP_GCS_BUCKET", "test28397yeo")
26+
SPREADSHEET_ID = os.environ.get("SPREADSHEET_ID", "1234567890qwerty")
27+
28+
default_args = {"start_date": days_ago(1)}
29+
30+
with models.DAG(
31+
"example_sheets_to_gcs",
32+
default_args=default_args,
33+
schedule_interval=None, # Override to match your needs
34+
tags=["example"],
35+
) as dag:
36+
# [START upload_sheet_to_gcs]
37+
upload_sheet_to_gcs = GoogleSheetsToGCSOperator(
38+
task_id="upload_sheet_to_gcs",
39+
destination_bucket=BUCKET,
40+
spreadsheet_id=SPREADSHEET_ID,
41+
)
42+
# [END upload_sheet_to_gcs]

β€Ždocs/howto/operator/gcp/sheets_to_gcs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Upload data from Google Sheets to GCS
4242
To upload data from Google Spreadsheet to Google Cloud Storage you can use the
4343
:class:`~airflow.providers.google.cloud.operators.sheets_to_gcs.GoogleSheetsToGCSOperator`.
4444

45-
.. exampleinclude:: ../../../../airflow/providers/google/suite/example_dags/example_sheets.py
45+
.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_sheets_to_gcs.py
4646
:language: python
4747
:dedent: 4
4848
:start-after: [START upload_sheet_to_gcs]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
import pytest
19+
20+
from airflow.providers.google.cloud.example_dags.example_life_sciences import BUCKET
21+
from tests.providers.google.cloud.utils.gcp_authenticator import GCP_GCS_KEY
22+
from tests.test_utils.gcp_system_helpers import CLOUD_DAG_FOLDER, GoogleSystemTest, provide_gcp_context
23+
24+
25+
@pytest.mark.backend("mysql", "postgres")
26+
@pytest.mark.credential_file(GCP_GCS_KEY)
27+
class GoogleSheetsToGCSExampleDagsSystemTest(GoogleSystemTest):
28+
29+
@provide_gcp_context(GCP_GCS_KEY)
30+
def setUp(self):
31+
super().setUp()
32+
self.create_gcs_bucket(BUCKET)
33+
34+
@provide_gcp_context(GCP_GCS_KEY)
35+
def test_run_example_dag_function(self):
36+
self.run_dag('example_sheets_to_gcs', CLOUD_DAG_FOLDER)
37+
38+
@provide_gcp_context(GCP_GCS_KEY)
39+
def tearDown(self):
40+
self.delete_gcs_bucket(BUCKET)
41+
super().tearDown()

β€Žtests/test_project_structure.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ class TestGoogleProviderProjectStructure(unittest.TestCase):
137137
('cloud', 'mysql_to_gcs'),
138138
('cloud', 'mssql_to_gcs'),
139139
('cloud', 'local_to_gcs'),
140-
('cloud', 'sheets_to_gcs'),
141140
('suite', 'gcs_to_sheets'),
142141
}
143142

0 commit comments

Comments
 (0)