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/03/27 20:33:47 UTC

[airflow] branch main updated: Issue 20453 google common cloud fixes part 1 (#22213)

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 2af13f2  Issue 20453 google common cloud fixes part 1 (#22213)
2af13f2 is described below

commit 2af13f28126a24465624fcc568c88cf6c6e6824d
Author: Harish Kesava Rao <ha...@gmail.com>
AuthorDate: Sun Mar 27 13:32:49 2022 -0700

    Issue 20453 google common cloud fixes part 1 (#22213)
---
 .../providers/google/cloud/hooks/test_bigquery.py  | 53 ++++++++++++----------
 .../providers/google/cloud/hooks/test_dataproc.py  |  4 +-
 tests/providers/google/cloud/hooks/test_pubsub.py  |  4 +-
 .../google/cloud/transfers/test_sheets_to_gcs.py   |  6 ++-
 .../google/common/hooks/test_base_google.py        | 18 ++++----
 5 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/tests/providers/google/cloud/hooks/test_bigquery.py b/tests/providers/google/cloud/hooks/test_bigquery.py
index 0185b37..6fec9c8 100644
--- a/tests/providers/google/cloud/hooks/test_bigquery.py
+++ b/tests/providers/google/cloud/hooks/test_bigquery.py
@@ -212,7 +212,8 @@ class TestBigQueryHookMethods(_BigQueryBaseTestClass):
         self.hook.running_job_id = running_job_id
         self.hook.cancel_query()
 
-        mock_poll_job_complete.has_calls(mock.call(running_job_id), mock.call(running_job_id))
+        calls = [mock.call(job_id=running_job_id), mock.call(running_job_id)]
+        mock_poll_job_complete.assert_has_calls(calls)
         mock_client.assert_called_once_with(project_id=PROJECT_ID, location=None)
         mock_client.return_value.cancel_job.assert_called_once_with(job_id=running_job_id)
 
@@ -461,7 +462,7 @@ class TestBigQueryHookMethods(_BigQueryBaseTestClass):
             location=LOCATION,
         )
         mock_table.from_api_repr.assert_called_once_with({"tableReference": TABLE_REFERENCE_REPR})
-        mock_schema.has_calls([mock.call(x, "") for x in ["field_1", "field_2"]])
+        mock_schema.assert_has_calls([mock.call(x, "") for x in ["field_1", "field_2"]])
         mock_client.return_value.list_rows.assert_called_once_with(
             table=mock_table.from_api_repr.return_value,
             max_results=10,
@@ -1216,29 +1217,31 @@ class TestBigQueryCursor(_BigQueryBaseTestClass):
         bq_cursor = self.hook.get_cursor()
         bq_cursor.executemany("SELECT %(foo)s", [{"foo": "bar"}, {"foo": "baz"}])
         assert mock_insert.call_count == 2
-        assert mock_insert.has_calls(
-            mock.call(
-                configuration={
-                    'query': {
-                        'query': "SELECT 'bar'",
-                        'priority': 'INTERACTIVE',
-                        'useLegacySql': True,
-                        'schemaUpdateOptions': [],
-                    }
-                },
-                project_id=PROJECT_ID,
-            ),
-            mock.call(
-                configuration={
-                    'query': {
-                        'query': "SELECT 'baz'",
-                        'priority': 'INTERACTIVE',
-                        'useLegacySql': True,
-                        'schemaUpdateOptions': [],
-                    }
-                },
-                project_id=PROJECT_ID,
-            ),
+        mock_insert.assert_has_calls(
+            [
+                mock.call(
+                    configuration={
+                        'query': {
+                            'query': "SELECT 'bar'",
+                            'priority': 'INTERACTIVE',
+                            'useLegacySql': True,
+                            'schemaUpdateOptions': [],
+                        }
+                    },
+                    project_id=PROJECT_ID,
+                ),
+                mock.call(
+                    configuration={
+                        'query': {
+                            'query': "SELECT 'baz'",
+                            'priority': 'INTERACTIVE',
+                            'useLegacySql': True,
+                            'schemaUpdateOptions': [],
+                        }
+                    },
+                    project_id=PROJECT_ID,
+                ),
+            ]
         )
 
     @mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_service")
diff --git a/tests/providers/google/cloud/hooks/test_dataproc.py b/tests/providers/google/cloud/hooks/test_dataproc.py
index 2285aa2..8e7e53b 100644
--- a/tests/providers/google/cloud/hooks/test_dataproc.py
+++ b/tests/providers/google/cloud/hooks/test_dataproc.py
@@ -474,7 +474,7 @@ class TestDataprocHook(unittest.TestCase):
             mock.call(region=GCP_LOCATION, job_id=JOB_ID, project_id=GCP_PROJECT),
             mock.call(region=GCP_LOCATION, job_id=JOB_ID, project_id=GCP_PROJECT),
         ]
-        mock_get_job.has_calls(calls)
+        mock_get_job.assert_has_calls(calls)
 
     @mock.patch(DATAPROC_STRING.format("DataprocHook.get_job"))
     def test_wait_for_job_deprecation_warning(self, mock_get_job):
@@ -495,7 +495,7 @@ class TestDataprocHook(unittest.TestCase):
                 mock.call(region=GCP_LOCATION, job_id=JOB_ID, project_id=GCP_PROJECT),
                 mock.call(region=GCP_LOCATION, job_id=JOB_ID, project_id=GCP_PROJECT),
             ]
-            mock_get_job.has_calls(calls)
+            mock_get_job.assert_has_calls(calls)
             assert warning_message == str(warnings[0].message)
 
         with pytest.raises(TypeError):
diff --git a/tests/providers/google/cloud/hooks/test_pubsub.py b/tests/providers/google/cloud/hooks/test_pubsub.py
index 0d398c1..4beed56 100644
--- a/tests/providers/google/cloud/hooks/test_pubsub.py
+++ b/tests/providers/google/cloud/hooks/test_pubsub.py
@@ -371,7 +371,9 @@ class TestPubSubHook(unittest.TestCase):
             mock.call(topic=EXPANDED_TOPIC, data=message.get("data", b''), **message.get('attributes', {}))
             for message in TEST_MESSAGES
         ]
-        publish_method.has_calls(calls)
+        mock_calls_result = publish_method.mock_calls
+        result_refined = [mock_calls_result[0], mock_calls_result[2], mock_calls_result[4]]
+        assert result_refined == calls
 
     @mock.patch(PUBSUB_STRING.format('PubSubHook.get_conn'))
     def test_publish_api_call_error(self, mock_service):
diff --git a/tests/providers/google/cloud/transfers/test_sheets_to_gcs.py b/tests/providers/google/cloud/transfers/test_sheets_to_gcs.py
index fba432d..e74375f 100644
--- a/tests/providers/google/cloud/transfers/test_sheets_to_gcs.py
+++ b/tests/providers/google/cloud/transfers/test_sheets_to_gcs.py
@@ -114,9 +114,11 @@ class TestGoogleSheetsToGCSOperator:
         )
 
         calls = [mock.call(spreadsheet_id=SPREADSHEET_ID, range_=r) for r in RANGES]
-        mock_sheet_hook.return_value.get_values.has_calls(calls)
+        mock_sheet_hook.return_value.get_values.assert_has_calls(calls)
 
         calls = [mock.call(mock_gcs_hook, mock_sheet_hook, r, v) for r, v in zip(RANGES, data)]
-        mock_upload_data.has_calls(calls)
+        mock_upload_data.assert_called()
+        actual_call_count = mock_upload_data.call_count
+        assert len(RANGES) == actual_call_count
 
         mock_xcom.assert_called_once_with(context, "destination_objects", [PATH, PATH])
diff --git a/tests/providers/google/common/hooks/test_base_google.py b/tests/providers/google/common/hooks/test_base_google.py
index 93b3b2d..bfb4229 100644
--- a/tests/providers/google/common/hooks/test_base_google.py
+++ b/tests/providers/google/common/hooks/test_base_google.py
@@ -684,10 +684,11 @@ class TestProvideAuthorizedGcloud(unittest.TestCase):
         with self.instance.provide_authorized_gcloud():
             assert os.environ[CREDENTIALS] == key_path
 
-        mock_check_output.has_calls(
-            mock.call(['gcloud', 'config', 'set', 'core/project', 'PROJECT_ID']),
+        calls = [
             mock.call(['gcloud', 'auth', 'activate-service-account', '--key-file=/test/key-path']),
-        )
+            mock.call(['gcloud', 'config', 'set', 'core/project', 'PROJECT_ID']),
+        ]
+        mock_check_output.assert_has_calls(calls)
 
     @mock.patch(
         'airflow.providers.google.common.hooks.base_google.GoogleBaseHook.project_id',
@@ -708,12 +709,11 @@ class TestProvideAuthorizedGcloud(unittest.TestCase):
         with self.instance.provide_authorized_gcloud():
             assert os.environ[CREDENTIALS] == file_name
 
-        mock_check_output.has_calls(
-            [
-                mock.call(['gcloud', 'config', 'set', 'core/project', 'PROJECT_ID']),
-                mock.call(['gcloud', 'auth', 'activate-service-account', '--key-file=/test/mock-file']),
-            ]
-        )
+        calls = [
+            mock.call(['gcloud', 'auth', 'activate-service-account', '--key-file=/test/mock-file']),
+            mock.call(['gcloud', 'config', 'set', 'core/project', 'PROJECT_ID']),
+        ]
+        mock_check_output.assert_has_calls(calls)
 
     @mock.patch(
         'airflow.providers.google.common.hooks.base_google.GoogleBaseHook.project_id',