Skip to content

Commit dd2000d

Browse files
authored
fix(api_core): support suppress_metrics_header fallback in AuthMetadataPlugin (#18029)
[PR #17616 ](#17616) introduced logic in grpc_helpers.py to pass `suppress_metrics_header=True` to `google.auth.transport.grpc.AuthMetadataPlugin`, falling back to default args if google-auth raises a TypeError. Following the release of `google-auth==2.56.3`, autospec=True unit test mocks record the fallback attempt, causing auth_metadata_plugin.assert_called_once_with to fail due to multiple invocations. Updates `test_create_channel_implicit_with_default_host` across sync and async `google-api-core` unit tests to handle AuthMetadataPlugin call assertions cleanly under both new and fallback google-auth versions.
1 parent 93d1d20 commit dd2000d

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎packages/google-api-core/tests/asyncio/test_grpc_helpers_async.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,15 @@ def test_create_channel_implicit_with_default_host(
421421
assert channel is grpc_secure_channel.return_value
422422

423423
google_auth_default.assert_called_once_with(scopes=None, default_scopes=None)
424-
auth_metadata_plugin.assert_called_once_with(
425-
mock.sentinel.credentials, mock.sentinel.Request, default_host=default_host
426-
)
424+
assert auth_metadata_plugin.call_count == 1
425+
assert auth_metadata_plugin.call_args.args == (
426+
mock.sentinel.credentials,
427+
mock.sentinel.Request,
428+
)
429+
assert auth_metadata_plugin.call_args.kwargs["default_host"] == default_host
430+
# google-auth >= 2.56.3 supports suppress_metrics_header; older versions omit it during fallback
431+
if "suppress_metrics_header" in auth_metadata_plugin.call_args.kwargs:
432+
assert auth_metadata_plugin.call_args.kwargs["suppress_metrics_header"] is True
427433
grpc_secure_channel.assert_called_once_with(
428434
expected_target, composite_creds, compression=None
429435
)

‎packages/google-api-core/tests/unit/test_grpc_helpers.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,15 @@ def test_create_channel_implicit_with_default_host(
453453
assert channel is grpc_secure_channel.return_value
454454

455455
google_auth_default.assert_called_once_with(scopes=None, default_scopes=None)
456-
auth_metadata_plugin.assert_called_once_with(
457-
mock.sentinel.credentials, mock.sentinel.Request, default_host=default_host
456+
assert auth_metadata_plugin.call_count == 1
457+
assert auth_metadata_plugin.call_args.args == (
458+
mock.sentinel.credentials,
459+
mock.sentinel.Request,
458460
)
461+
assert auth_metadata_plugin.call_args.kwargs["default_host"] == default_host
462+
# google-auth >= 2.56.3 supports suppress_metrics_header; older versions omit it during fallback
463+
if "suppress_metrics_header" in auth_metadata_plugin.call_args.kwargs:
464+
assert auth_metadata_plugin.call_args.kwargs["suppress_metrics_header"] is True
459465

460466
grpc_secure_channel.assert_called_once_with(
461467
expected_target, composite_creds, compression=None

0 commit comments

Comments
 (0)