Skip to content

Commit 6eb60f8

Browse files
authored
Migrate Google calendar example DAG to new design AIP-47 (#24333)
related: #22447
1 parent 2e8bd9d commit 6eb60f8

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Upload data from Google Calendar to GCS
3737
To upload data from Google Calendar to Google Cloud Storage you can use the
3838
:class:`~airflow.providers.google.cloud.transfers.calendar_to_gcs.GoogleCalendarToGCSOperator`.
3939

40-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_calendar_to_gcs.py
40+
.. exampleinclude:: /../../tests/system/providers/google/calendar/example_calendar_to_gcs.py
4141
:language: python
4242
:dedent: 4
4343
:start-after: [START upload_calendar_to_gcs]

airflow/providers/google/cloud/example_dags/example_calendar_to_gcs.py renamed to tests/system/providers/google/calendar/example_calendar_to_gcs.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,58 @@
2020
from datetime import datetime
2121

2222
from airflow import models
23+
from airflow.providers.google.cloud.operators.gcs import GCSCreateBucketOperator, GCSDeleteBucketOperator
2324
from airflow.providers.google.cloud.transfers.calendar_to_gcs import GoogleCalendarToGCSOperator
25+
from airflow.utils.trigger_rule import TriggerRule
2426

25-
BUCKET = os.environ.get("GCP_GCS_BUCKET", "test28397yeo")
27+
ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
28+
PROJECT_ID = os.environ.get("SYSTEM_TESTS_GCP_PROJECT")
29+
DAG_ID = "example_calendar_to_gcs"
30+
31+
BUCKET_NAME = f"bucket_{DAG_ID}_{ENV_ID}"
2632
CALENDAR_ID = os.environ.get("CALENDAR_ID", "1234567890qwerty")
2733
API_VERSION = "v3"
2834

2935
with models.DAG(
30-
"example_calendar_to_gcs",
36+
DAG_ID,
3137
schedule_interval='@once', # Override to match your needs
32-
start_date=datetime(2022, 1, 1),
38+
start_date=datetime(2021, 1, 1),
3339
catchup=False,
34-
tags=["example"],
40+
tags=["example", "calendar"],
3541
) as dag:
42+
create_bucket = GCSCreateBucketOperator(
43+
task_id="create_bucket", bucket_name=BUCKET_NAME, project_id=PROJECT_ID
44+
)
45+
3646
# [START upload_calendar_to_gcs]
3747
upload_calendar_to_gcs = GoogleCalendarToGCSOperator(
3848
task_id="upload_calendar_to_gcs",
39-
destination_bucket=BUCKET,
49+
destination_bucket=BUCKET_NAME,
4050
calendar_id=CALENDAR_ID,
4151
api_version=API_VERSION,
4252
)
4353
# [END upload_calendar_to_gcs]
54+
55+
delete_bucket = GCSDeleteBucketOperator(
56+
task_id="delete_bucket", bucket_name=BUCKET_NAME, trigger_rule=TriggerRule.ALL_DONE
57+
)
58+
59+
(
60+
# TEST SETUP
61+
create_bucket
62+
# TEST BODY
63+
>> upload_calendar_to_gcs
64+
# TEST TEARDOWN
65+
>> delete_bucket
66+
)
67+
68+
from tests.system.utils.watcher import watcher
69+
70+
# This test needs watcher in order to properly mark success/failure
71+
# when "tearDown" task with trigger rule is part of the DAG
72+
list(dag.tasks) >> watcher()
73+
74+
from tests.system.utils import get_test_run # noqa: E402
75+
76+
# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)
77+
test_run = get_test_run(dag)

0 commit comments

Comments
 (0)