|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +import os |
| 19 | + |
| 20 | +import pytest |
| 21 | + |
| 22 | +from airflow.providers.google.cloud.example_dags.example_gcs_to_local import ( |
| 23 | + BUCKET, |
| 24 | + PATH_TO_REMOTE_FILE, |
| 25 | + PATH_TO_LOCAL_FILE, |
| 26 | +) |
| 27 | +from tests.providers.google.cloud.utils.gcp_authenticator import GCP_GCS_KEY |
| 28 | +from tests.test_utils.gcp_system_helpers import CLOUD_DAG_FOLDER, GoogleSystemTest, provide_gcp_context |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.backend("mysql", "postgres") |
| 32 | +@pytest.mark.credential_file(GCP_GCS_KEY) |
| 33 | +class GoogleCloudStorageExampleDagsTest(GoogleSystemTest): |
| 34 | + @provide_gcp_context(GCP_GCS_KEY) |
| 35 | + def setUp(self): |
| 36 | + super().setUp() |
| 37 | + self.create_gcs_bucket(BUCKET) |
| 38 | + self.upload_content_to_gcs( |
| 39 | + lines=f"{os.urandom(1 * 1024 * 1024)}", bucket=BUCKET, filename=PATH_TO_REMOTE_FILE |
| 40 | + ) |
| 41 | + |
| 42 | + @provide_gcp_context(GCP_GCS_KEY) |
| 43 | + def tearDown(self): |
| 44 | + self.delete_gcs_bucket(BUCKET) |
| 45 | + os.remove(PATH_TO_LOCAL_FILE) |
| 46 | + super().tearDown() |
| 47 | + |
| 48 | + @provide_gcp_context(GCP_GCS_KEY) |
| 49 | + def test_run_example_dag(self): |
| 50 | + self.run_dag('example_gcs_to_local', CLOUD_DAG_FOLDER) |
0 commit comments