This is an automated email from the ASF dual-hosted git repository.

kamilbregula 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 3a2eb961ca Fix tests using has_calls to use assert_has_calls. (#23001)
3a2eb961ca is described below

commit 3a2eb961ca628d962ed5fad68760ef3439b2f40b
Author: Karthikeyan Singaravelan <tir.kar...@gmail.com>
AuthorDate: Sat Apr 16 15:35:29 2022 +0530

    Fix tests using has_calls to use assert_has_calls. (#23001)
---
 .../google/cloud/hooks/test_cloud_memorystore.py   | 42 +++++++++++++++++-----
 tests/providers/google/cloud/hooks/test_looker.py  |  2 +-
 .../google/cloud/transfers/test_calendar_to_gcs.py | 36 +++++++++----------
 3 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/tests/providers/google/cloud/hooks/test_cloud_memorystore.py 
b/tests/providers/google/cloud/hooks/test_cloud_memorystore.py
index 8badc7431a..696ef60a64 100644
--- a/tests/providers/google/cloud/hooks/test_cloud_memorystore.py
+++ b/tests/providers/google/cloud/hooks/test_cloud_memorystore.py
@@ -109,10 +109,20 @@ class 
TestCloudMemorystoreWithDefaultProjectIdHook(TestCase):
             timeout=TEST_TIMEOUT,
             metadata=TEST_METADATA,
         )
-        mock_get_conn.return_value.get_instance.has_calls(
+        mock_get_conn.return_value.get_instance.assert_has_calls(
             [
-                mock.call(name=TEST_NAME, retry=TEST_RETRY, 
timeout=TEST_TIMEOUT, metadata=TEST_METADATA),
-                mock.call(name=TEST_NAME, retry=TEST_RETRY, 
timeout=TEST_TIMEOUT, metadata=TEST_METADATA),
+                mock.call(
+                    request=dict(name=TEST_NAME_DEFAULT_PROJECT_ID),
+                    retry=TEST_RETRY,
+                    timeout=TEST_TIMEOUT,
+                    metadata=TEST_METADATA,
+                ),
+                mock.call(
+                    request=dict(name=TEST_NAME_DEFAULT_PROJECT_ID),
+                    retry=TEST_RETRY,
+                    timeout=TEST_TIMEOUT,
+                    metadata=TEST_METADATA,
+                ),
             ]
         )
         mock_get_conn.return_value.create_instance.assert_called_once_with(
@@ -263,16 +273,20 @@ class 
TestCloudMemorystoreWithoutDefaultProjectIdHook(TestCase):
             timeout=TEST_TIMEOUT,
             metadata=TEST_METADATA,
         )
-        mock_get_conn.return_value.get_instance.has_calls(
+        mock_get_conn.return_value.get_instance.assert_has_calls(
             [
                 mock.call(
-                    
name="projects/test-project-id/locations/test-location/instances/test-instance-id",
+                    request=dict(
+                        
name="projects/test-project-id/locations/test-location/instances/test-instance-id"
+                    ),
                     retry=TEST_RETRY,
                     timeout=TEST_TIMEOUT,
                     metadata=TEST_METADATA,
                 ),
                 mock.call(
-                    
name="projects/test-project-id/locations/test-location/instances/test-instance-id",
+                    request=dict(
+                        
name="projects/test-project-id/locations/test-location/instances/test-instance-id"
+                    ),
                     retry=TEST_RETRY,
                     timeout=TEST_TIMEOUT,
                     metadata=TEST_METADATA,
@@ -500,10 +514,20 @@ class 
TestCloudMemorystoreMemcachedWithDefaultProjectIdHook(TestCase):
             timeout=TEST_TIMEOUT,
             metadata=TEST_METADATA,
         )
-        mock_get_conn.return_value.get_instance.has_calls(
+        mock_get_conn.return_value.get_instance.assert_has_calls(
             [
-                mock.call(name=TEST_NAME, retry=TEST_RETRY, 
timeout=TEST_TIMEOUT, metadata=TEST_METADATA),
-                mock.call(name=TEST_NAME, retry=TEST_RETRY, 
timeout=TEST_TIMEOUT, metadata=TEST_METADATA),
+                mock.call(
+                    name=TEST_NAME_DEFAULT_PROJECT_ID,
+                    retry=TEST_RETRY,
+                    timeout=TEST_TIMEOUT,
+                    metadata=TEST_METADATA,
+                ),
+                mock.call(
+                    name=TEST_NAME_DEFAULT_PROJECT_ID,
+                    retry=TEST_RETRY,
+                    timeout=TEST_TIMEOUT,
+                    metadata=TEST_METADATA,
+                ),
             ]
         )
         mock_get_conn.return_value.create_instance.assert_called_once_with(
diff --git a/tests/providers/google/cloud/hooks/test_looker.py 
b/tests/providers/google/cloud/hooks/test_looker.py
index a818d59a86..78cd4d68ee 100644
--- a/tests/providers/google/cloud/hooks/test_looker.py
+++ b/tests/providers/google/cloud/hooks/test_looker.py
@@ -62,7 +62,7 @@ class TestLookerHook(unittest.TestCase):
             mock.call(materialization_id=JOB_ID),
             mock.call(materialization_id=JOB_ID),
         ]
-        mock_pdt_build_status.has_calls(calls)
+        mock_pdt_build_status.assert_has_calls(calls)
 
     @mock.patch(HOOK_PATH.format("get_looker_sdk"))
     def test_check_pdt_build(self, mock_sdk):
diff --git a/tests/providers/google/cloud/transfers/test_calendar_to_gcs.py 
b/tests/providers/google/cloud/transfers/test_calendar_to_gcs.py
index 540a01af32..54defcfc23 100644
--- a/tests/providers/google/cloud/transfers/test_calendar_to_gcs.py
+++ b/tests/providers/google/cloud/transfers/test_calendar_to_gcs.py
@@ -85,6 +85,7 @@ class TestGoogleCalendarToGCSOperator:
         context = {}
         data = [EVENT]
         mock_upload_data.side_effect = PATH
+        mock_calendar_hook.return_value.get_events.return_value = data
 
         op = GoogleCalendarToGCSOperator(
             api_version=API_VERSION,
@@ -104,26 +105,23 @@ class TestGoogleCalendarToGCSOperator:
             impersonation_chain=IMPERSONATION_CHAIN,
         )
 
-        call = mock.call(
+        mock_calendar_hook.return_value.get_events.assert_called_once_with(
             calendar_id=CALENDAR_ID,
-            iCalUID=None,
-            maxAttendees=None,
-            maxResults=None,
-            orderBy=None,
-            pageToken=None,
-            privateExtendedProperty=None,
+            i_cal_uid=None,
+            max_attendees=None,
+            max_results=None,
+            order_by=None,
+            private_extended_property=None,
             q=None,
-            sharedExtendedProperty=None,
-            showDeleted=False,
-            showHiddenInvitations=False,
-            singleEvents=False,
-            syncToken=None,
-            timeMax=None,
-            timeMin=None,
-            timeZone=None,
-            updatedMin=None,
+            shared_extended_property=None,
+            show_deleted=None,
+            show_hidden_invitation=None,
+            single_events=None,
+            sync_token=None,
+            time_max=None,
+            time_min=None,
+            time_zone=None,
+            updated_min=None,
         )
-        mock_calendar_hook.return_value.get_values.has_calls(call)
 
-        call = mock.call(data)
-        mock_upload_data.has_calls(call)
+        mock_upload_data.assert_called_once_with(data)

Reply via email to