Skip to content

Commit

Permalink
Fix tests using has_calls to use assert_has_calls. (#23001)
Browse files Browse the repository at this point in the history
  • Loading branch information
tirkarthi authored Apr 16, 2022
1 parent 8e75e23 commit 3a2eb96
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
42 changes: 33 additions & 9 deletions tests/providers/google/cloud/hooks/test_cloud_memorystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,20 @@ def test_create_instance_when_not_exists(self, mock_get_conn, mock_project_id):
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(
Expand Down Expand Up @@ -263,16 +273,20 @@ def test_create_instance_when_not_exists(self, mock_get_conn):
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,
Expand Down Expand Up @@ -500,10 +514,20 @@ def test_create_instance_when_not_exists(self, mock_get_conn, mock_project_id):
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(
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/google/cloud/hooks/test_looker.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_wait_for_job(self, mock_pdt_build_status):
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):
Expand Down
36 changes: 17 additions & 19 deletions tests/providers/google/cloud/transfers/test_calendar_to_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def test_execute(self, mock_upload_data, mock_calendar_hook):
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,
Expand All @@ -104,26 +105,23 @@ def test_execute(self, mock_upload_data, mock_calendar_hook):
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)

0 comments on commit 3a2eb96

Please sign in to comment.