From 2b0216251d408c6c2af226fe0180af2d7c3d4ddf Mon Sep 17 00:00:00 2001 From: joppe Date: Sat, 23 May 2020 11:52:25 +0200 Subject: [PATCH 1/2] added small test for bigquery sensor --- .../google/cloud/sensors/test_bigquery.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/providers/google/cloud/sensors/test_bigquery.py diff --git a/tests/providers/google/cloud/sensors/test_bigquery.py b/tests/providers/google/cloud/sensors/test_bigquery.py new file mode 100644 index 0000000000000..0c9735e3b21fd --- /dev/null +++ b/tests/providers/google/cloud/sensors/test_bigquery.py @@ -0,0 +1,53 @@ +# 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. + +from unittest import TestCase, mock + +from airflow.providers.google.cloud.sensors.bigquery import BigQueryTableExistenceSensor + +TEST_PROJECT_ID = "test_project" +TEST_DATASET_ID = 'test_dataset' +TEST_TABLE_ID = 'test_table' +TEST_DELEGATE_TO = "test_delegate_to" +TEST_GCP_CONN_ID = 'test_gcp_conn_id' + + +class TestBigqueryTableExistenceSensor(TestCase): + @mock.patch("airflow.providers.google.cloud.sensors.bigquery.BigQueryHook") + def test_passing_arguments_to_hook(self, mock_hook): + task = BigQueryTableExistenceSensor( + task_id='task-id', + project_id=TEST_PROJECT_ID, + dataset_id=TEST_DATASET_ID, + table_id=TEST_TABLE_ID, + bigquery_conn_id=TEST_GCP_CONN_ID, + delegate_to=TEST_DELEGATE_TO + ) + mock_hook.return_value.table_exists.return_value = True + results = task.poke(mock.MagicMock()) + + self.assertEqual(True, results) + + mock_hook.assert_called_once_with( + bigquery_conn_id=TEST_GCP_CONN_ID, + delegate_to=TEST_DELEGATE_TO + ) + mock_hook.return_value.table_exists.assert_called_once_with( + TEST_PROJECT_ID, + TEST_DATASET_ID, + TEST_TABLE_ID + ) From 426adcec48af4b19da99244662cdffdd3786f77e Mon Sep 17 00:00:00 2001 From: joppe Date: Sat, 23 May 2020 12:04:41 +0200 Subject: [PATCH 2/2] removed file from missing_test_files --- tests/test_project_structure.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_project_structure.py b/tests/test_project_structure.py index 69ec0275eb00a..53a4fe349d32d 100644 --- a/tests/test_project_structure.py +++ b/tests/test_project_structure.py @@ -36,7 +36,6 @@ 'tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py', 'tests/providers/google/cloud/operators/test_datastore.py', 'tests/providers/google/cloud/operators/test_sql_to_gcs.py', - 'tests/providers/google/cloud/sensors/test_bigquery.py', 'tests/providers/google/cloud/utils/test_field_sanitizer.py', 'tests/providers/google/cloud/utils/test_field_validator.py', 'tests/providers/google/cloud/utils/test_mlengine_operator_utils.py',