Skip to content

Commit

Permalink
Migrate Google search_ads DAG to new design AIP-47 (#24298)
Browse files Browse the repository at this point in the history
related: #22447, #22430
  • Loading branch information
chenglongyan committed Jun 19, 2022
1 parent 55b1644 commit a35f342
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Inserting a report
To insert a Search Ads report use the
:class:`~airflow.providers.google.marketing_platform.operators.search_ads.GoogleSearchAdsInsertReportOperator`.

.. exampleinclude:: /../../airflow/providers/google/marketing_platform/example_dags/example_search_ads.py
.. exampleinclude:: /../../tests/system/providers/google/marketing_platform/example_search_ads.py
:language: python
:dedent: 4
:start-after: [START howto_search_ads_generate_report_operator]
Expand All @@ -46,7 +46,7 @@ parameters which allows you to dynamically determine values. You can provide rep
.json`` file as this operator supports this template extension.
The result is saved to :ref:`XCom <concepts:xcom>`, which allows it to be used by other operators:

.. exampleinclude:: /../../airflow/providers/google/marketing_platform/example_dags/example_search_ads.py
.. exampleinclude:: /../../tests/system/providers/google/marketing_platform/example_search_ads.py
:language: python
:dedent: 4
:start-after: [START howto_search_ads_get_report_id]
Expand All @@ -60,7 +60,7 @@ Awaiting for a report
To wait for a report to be ready for download use
:class:`~airflow.providers.google.marketing_platform.sensors.search_ads.GoogleSearchAdsReportSensor`.

.. exampleinclude:: /../../airflow/providers/google/marketing_platform/example_dags/example_search_ads.py
.. exampleinclude:: /../../tests/system/providers/google/marketing_platform/example_search_ads.py
:language: python
:dedent: 4
:start-after: [START howto_search_ads_get_report_operator]
Expand All @@ -78,7 +78,7 @@ Downloading a report
To download a Search Ads report to Google Cloud Storage bucket use the
:class:`~airflow.providers.google.marketing_platform.operators.search_ads.GoogleSearchAdsDownloadReportOperator`.

.. exampleinclude:: /../../airflow/providers/google/marketing_platform/example_dags/example_search_ads.py
.. exampleinclude:: /../../tests/system/providers/google/marketing_platform/example_search_ads.py
:language: python
:dedent: 4
:start-after: [START howto_search_ads_getfile_report_operator]
Expand Down

This file was deleted.

17 changes: 17 additions & 0 deletions tests/system/providers/google/marketing_platform/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
)
from airflow.providers.google.marketing_platform.sensors.search_ads import GoogleSearchAdsReportSensor

ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
DAG_ID = "example_search_ads"

# [START howto_search_ads_env_variables]
AGENCY_ID = os.environ.get("GMP_AGENCY_ID")
ADVERTISER_ID = os.environ.get("GMP_ADVERTISER_ID")
Expand All @@ -45,10 +48,11 @@
# [END howto_search_ads_env_variables]

with models.DAG(
"example_search_ads",
DAG_ID,
schedule_interval='@once', # Override to match your needs,
start_date=datetime(2021, 1, 1),
catchup=False,
tags=["example"],
) as dag:
# [START howto_search_ads_generate_report_operator]
generate_report = GoogleSearchAdsInsertReportOperator(report=REPORT, task_id="generate_report")
Expand All @@ -73,3 +77,9 @@
# Task dependencies created via `XComArgs`:
# generate_report >> wait_for_report
# generate_report >> download_report


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)

0 comments on commit a35f342

Please sign in to comment.