potiuk commented on a change in pull request #4493: [AIRFLOW-3680] Consistency update in tests for All GCP-related operators URL: https://github.com/apache/airflow/pull/4493#discussion_r247300223
########## File path: tests/contrib/utils/base_gcp_system_test_case.py ########## @@ -0,0 +1,256 @@ +# -*- coding: utf-8 -*- +# +# 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 os +import subprocess +import unittest +from glob import glob +from shutil import move +from tempfile import mkdtemp + +from airflow.utils import db as db_utils +from airflow import models, settings, AirflowException, LoggingMixin +from airflow.utils.timezone import datetime +from tests.contrib.utils.gcp_authenticator import GcpAuthenticator +from tests.contrib.utils.run_once_decorator import run_once + +AIRFLOW_MAIN_FOLDER = os.path.realpath(os.path.join( + os.path.dirname(os.path.realpath(__file__)), + os.pardir, os.pardir, os.pardir)) + +AIRFLOW_BREEZE_FOLDER = os.path.realpath(os.path.join(AIRFLOW_MAIN_FOLDER, + os.pardir, os.pardir, os.pardir)) +ENV_FILE_RETRIEVER = os.path.join(AIRFLOW_BREEZE_FOLDER, + "get_system_test_environment_variables.py") + + +# Retrieve environment variables from airflow breeze if it is used +class RetrieveVariables: + @staticmethod + @run_once + def retrieve_variables(): + if os.path.isfile(ENV_FILE_RETRIEVER): + if os.environ.get('AIRFLOW__CORE__UNIT_TEST_MODE'): + raise Exception("Please unset the AIRFLOW__CORE__UNIT_TEST_MODE") + variables = subprocess.check_output([ENV_FILE_RETRIEVER]).decode("utf-8") + print("Applying variables retrieved") + for line in variables.split("\n"): + try: + variable, key = line.split("=") + except ValueError: + continue + print("{}={}".format(variable, key)) + os.environ[variable] = key + + +RetrieveVariables.retrieve_variables() + +DEFAULT_DATE = datetime(2015, 1, 1) + +CONTRIB_OPERATORS_EXAMPLES_DAG_FOLDER = os.path.join( + AIRFLOW_MAIN_FOLDER, "airflow", "contrib", "example_dags") + +OPERATORS_EXAMPLES_DAG_FOLDER = os.path.join( + AIRFLOW_MAIN_FOLDER, "airflow", "example_dags") + +AIRFLOW_HOME = os.environ.get('AIRFLOW_HOME', + os.path.join(os.path.expanduser('~'), 'airflow')) + +DAG_FOLDER = os.path.join(AIRFLOW_HOME, "dags") + + +SKIP_TEST_WARNING = """ +The test is only run when the test is run in with GCP-system-tests enabled +Airflow Breeze environment. You can enable it in one of two ways: Review comment: Ditto ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
