Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for bigquery sensor #8986

Merged
merged 2 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tests/providers/google/cloud/sensors/test_bigquery.py
Original file line number Diff line number Diff line change
@@ -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
)
1 change: 0 additions & 1 deletion tests/test_project_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down