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/07/16 07:41:46 UTC

[airflow] branch main updated: Migrate Google analytics example to new design AIP-47 (#25006)

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 9b7e4a7324 Migrate Google analytics example to new design AIP-47 (#25006)
9b7e4a7324 is described below

commit 9b7e4a732496e60ef1c275c1ac17c7ed05b27b54
Author: Chenglong Yan <al...@gmail.com>
AuthorDate: Sat Jul 16 15:41:34 2022 +0800

    Migrate Google analytics example to new design AIP-47 (#25006)
    
    related: #22447, #22430
---
 .../operators/marketing_platform/analytics.rst     |  6 +--
 .../operators/test_analytics_system.py             | 60 ----------------------
 .../marketing_platform}/example_analytics.py       | 12 ++++-
 3 files changed, 14 insertions(+), 64 deletions(-)

diff --git a/docs/apache-airflow-providers-google/operators/marketing_platform/analytics.rst b/docs/apache-airflow-providers-google/operators/marketing_platform/analytics.rst
index 706ddd1130..fd06a85105 100644
--- a/docs/apache-airflow-providers-google/operators/marketing_platform/analytics.rst
+++ b/docs/apache-airflow-providers-google/operators/marketing_platform/analytics.rst
@@ -35,7 +35,7 @@ List the Accounts
 To list accounts from Analytics you can use the
 :class:`~airflow.providers.google.marketing_platform.operators.analytics.GoogleAnalyticsListAccountsOperator`.
 
-.. exampleinclude:: /../../airflow/providers/google/marketing_platform/example_dags/example_analytics.py
+.. exampleinclude:: /../../tests/system/providers/google/marketing_platform/example_analytics.py
     :language: python
     :dedent: 4
     :start-after: [START howto_marketing_platform_list_accounts_operator]
@@ -53,7 +53,7 @@ Returns a web property-Google Ads link to which the user has access.
 To list web property-Google Ads link you can use the
 :class:`~airflow.providers.google.marketing_platform.operators.analytics.GoogleAnalyticsGetAdsLinkOperator`.
 
-.. exampleinclude:: /../../airflow/providers/google/marketing_platform/example_dags/example_analytics.py
+.. exampleinclude:: /../../tests/system/providers/google/marketing_platform/example_analytics.py
     :language: python
     :dedent: 4
     :start-after: [START howto_marketing_platform_get_ads_link_operator]
@@ -71,7 +71,7 @@ Operator returns a list of entity Google Ads links.
 To list Google Ads links you can use the
 :class:`~airflow.providers.google.marketing_platform.operators.analytics.GoogleAnalyticsRetrieveAdsLinksListOperator`.
 
-.. exampleinclude:: /../../airflow/providers/google/marketing_platform/example_dags/example_analytics.py
+.. exampleinclude:: /../../tests/system/providers/google/marketing_platform/example_analytics.py
     :language: python
     :dedent: 4
     :start-after: [START howto_marketing_platform_retrieve_ads_links_list_operator]
diff --git a/tests/providers/google/marketing_platform/operators/test_analytics_system.py b/tests/providers/google/marketing_platform/operators/test_analytics_system.py
deleted file mode 100644
index ca0931435c..0000000000
--- a/tests/providers/google/marketing_platform/operators/test_analytics_system.py
+++ /dev/null
@@ -1,60 +0,0 @@
-# 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.
-
-import pytest
-
-from airflow.providers.google.marketing_platform.example_dags.example_analytics import BUCKET, BUCKET_FILENAME
-from tests.providers.google.cloud.utils.gcp_authenticator import GMP_KEY
-from tests.test_utils.gcp_system_helpers import MARKETING_DAG_FOLDER, GoogleSystemTest, provide_gcp_context
-
-DATA = """pagePath,dimension1
-how_to_make_pizza,1
-how_to_make_doughnuts,2
-how_to_build_a_treehouse,3
-how_to_make_paper_airplanes,4
-"""
-
-
-# Required scopes
-SCOPES = [
-    'https://www.googleapis.com/auth/analytics',
-    'https://www.googleapis.com/auth/analytics.edit',
-    'https://www.googleapis.com/auth/cloud-platform',
-]
-
-
-@pytest.fixture
-def helper():
-    GoogleSystemTest.create_gcs_bucket(BUCKET)
-    GoogleSystemTest.upload_content_to_gcs(DATA, BUCKET, BUCKET_FILENAME)
-    yield
-    GoogleSystemTest.delete_gcs_bucket(BUCKET)
-
-
-@pytest.mark.system("google.marketing_platform")
-@pytest.mark.credential_file(GMP_KEY)
-class TestSystemGoogleAds(GoogleSystemTest):
-    def setUp(self):
-        super().setUp()
-
-    @pytest.mark.usefixtures("helper")
-    @provide_gcp_context(GMP_KEY, scopes=SCOPES)
-    def test_run_example_dag(self):
-        self.run_dag('example_google_analytics', MARKETING_DAG_FOLDER)
-
-    def tearDown(self):
-        super().tearDown()
diff --git a/airflow/providers/google/marketing_platform/example_dags/example_analytics.py b/tests/system/providers/google/marketing_platform/example_analytics.py
similarity index 91%
rename from airflow/providers/google/marketing_platform/example_dags/example_analytics.py
rename to tests/system/providers/google/marketing_platform/example_analytics.py
index cc08b2a52c..b5de17148d 100644
--- a/airflow/providers/google/marketing_platform/example_dags/example_analytics.py
+++ b/tests/system/providers/google/marketing_platform/example_analytics.py
@@ -30,6 +30,9 @@ from airflow.providers.google.marketing_platform.operators.analytics import (
     GoogleAnalyticsRetrieveAdsLinksListOperator,
 )
 
+ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
+DAG_ID = "example_google_analytics"
+
 ACCOUNT_ID = os.environ.get("GA_ACCOUNT_ID", "123456789")
 
 BUCKET = os.environ.get("GMP_ANALYTICS_BUCKET", "test-airflow-analytics-bucket")
@@ -39,10 +42,11 @@ WEB_PROPERTY_AD_WORDS_LINK_ID = os.environ.get("GA_WEB_PROPERTY_AD_WORDS_LINK_ID
 DATA_ID = "kjdDu3_tQa6n8Q1kXFtSmg"
 
 with models.DAG(
-    "example_google_analytics",
+    DAG_ID,
     schedule_interval='@once',  # Override to match your needs,
     start_date=datetime(2021, 1, 1),
     catchup=False,
+    tags=["example", "analytics"],
 ) as dag:
     # [START howto_marketing_platform_list_accounts_operator]
     list_account = GoogleAnalyticsListAccountsOperator(task_id="list_account")
@@ -86,3 +90,9 @@ with models.DAG(
     )
 
     upload >> [delete, transform]
+
+
+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)