You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/06/12 09:59:35 UTC
[airflow] branch main updated: Migrate Google calendar example DAG to new design AIP-47 (#24333)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 6eb60f816c Migrate Google calendar example DAG to new design AIP-47 (#24333)
6eb60f816c is described below
commit 6eb60f816cb6103d42c023ce5fba9ac31a64f9ce
Author: Chenglong Yan <al...@gmail.com>
AuthorDate: Sun Jun 12 17:59:29 2022 +0800
Migrate Google calendar example DAG to new design AIP-47 (#24333)
related: #22447
---
.../operators/transfer/calendar_to_gcs.rst | 2 +-
.../google/calendar}/example_calendar_to_gcs.py | 44 +++++++++++++++++++---
2 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/docs/apache-airflow-providers-google/operators/transfer/calendar_to_gcs.rst b/docs/apache-airflow-providers-google/operators/transfer/calendar_to_gcs.rst
index e8762670b8..42dae95bdf 100644
--- a/docs/apache-airflow-providers-google/operators/transfer/calendar_to_gcs.rst
+++ b/docs/apache-airflow-providers-google/operators/transfer/calendar_to_gcs.rst
@@ -37,7 +37,7 @@ Upload data from Google Calendar to GCS
To upload data from Google Calendar to Google Cloud Storage you can use the
:class:`~airflow.providers.google.cloud.transfers.calendar_to_gcs.GoogleCalendarToGCSOperator`.
-.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_calendar_to_gcs.py
+.. exampleinclude:: /../../tests/system/providers/google/calendar/example_calendar_to_gcs.py
:language: python
:dedent: 4
:start-after: [START upload_calendar_to_gcs]
diff --git a/airflow/providers/google/cloud/example_dags/example_calendar_to_gcs.py b/tests/system/providers/google/calendar/example_calendar_to_gcs.py
similarity index 51%
rename from airflow/providers/google/cloud/example_dags/example_calendar_to_gcs.py
rename to tests/system/providers/google/calendar/example_calendar_to_gcs.py
index aab3a1fe65..7f6a058b2f 100644
--- a/airflow/providers/google/cloud/example_dags/example_calendar_to_gcs.py
+++ b/tests/system/providers/google/calendar/example_calendar_to_gcs.py
@@ -20,24 +20,58 @@ import os
from datetime import datetime
from airflow import models
+from airflow.providers.google.cloud.operators.gcs import GCSCreateBucketOperator, GCSDeleteBucketOperator
from airflow.providers.google.cloud.transfers.calendar_to_gcs import GoogleCalendarToGCSOperator
+from airflow.utils.trigger_rule import TriggerRule
-BUCKET = os.environ.get("GCP_GCS_BUCKET", "test28397yeo")
+ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
+PROJECT_ID = os.environ.get("SYSTEM_TESTS_GCP_PROJECT")
+DAG_ID = "example_calendar_to_gcs"
+
+BUCKET_NAME = f"bucket_{DAG_ID}_{ENV_ID}"
CALENDAR_ID = os.environ.get("CALENDAR_ID", "1234567890qwerty")
API_VERSION = "v3"
with models.DAG(
- "example_calendar_to_gcs",
+ DAG_ID,
schedule_interval='@once', # Override to match your needs
- start_date=datetime(2022, 1, 1),
+ start_date=datetime(2021, 1, 1),
catchup=False,
- tags=["example"],
+ tags=["example", "calendar"],
) as dag:
+ create_bucket = GCSCreateBucketOperator(
+ task_id="create_bucket", bucket_name=BUCKET_NAME, project_id=PROJECT_ID
+ )
+
# [START upload_calendar_to_gcs]
upload_calendar_to_gcs = GoogleCalendarToGCSOperator(
task_id="upload_calendar_to_gcs",
- destination_bucket=BUCKET,
+ destination_bucket=BUCKET_NAME,
calendar_id=CALENDAR_ID,
api_version=API_VERSION,
)
# [END upload_calendar_to_gcs]
+
+ delete_bucket = GCSDeleteBucketOperator(
+ task_id="delete_bucket", bucket_name=BUCKET_NAME, trigger_rule=TriggerRule.ALL_DONE
+ )
+
+ (
+ # TEST SETUP
+ create_bucket
+ # TEST BODY
+ >> upload_calendar_to_gcs
+ # TEST TEARDOWN
+ >> delete_bucket
+ )
+
+ from tests.system.utils.watcher import watcher
+
+ # This test needs watcher in order to properly mark success/failure
+ # when "tearDown" task with trigger rule is part of the DAG
+ list(dag.tasks) >> watcher()
+
+from tests.system.utils import get_test_run # noqa: E402
+
+# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)
+test_run = get_test_run(dag)