Skip to content

Commit cc1df59

Browse files
authored
test(secretmanager): align OTel transport unit tests with GAPIC generator templates
1 parent fb9b7e7 commit cc1df59

1 file changed

Lines changed: 10 additions & 43 deletions

File tree

packages/google-cloud-secret-manager/tests/unit/gapic/secretmanager_v1/test_secret_manager_service.py

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
from google.auth import credentials as ga_credentials
6363
from google.auth.exceptions import MutualTLSChannelError
6464
from google.cloud.location import locations_pb2
65+
66+
# NOTE: Isolated import block preserves import shielding for service_account
67+
# to prevent ruff/flake8 sorting conflicts between local hooks and CI environments.
6568
from google.oauth2 import service_account
6669

6770
from google.cloud.secretmanager_v1.services.secret_manager_service import (
@@ -478,13 +481,6 @@ def test_secret_manager_service_client_client_options(
478481

479482

480483
def test_secret_manager_service_client_otel_channel_injection_enabled():
481-
"""Proves that when OpenTelemetry tracing is enabled:
482-
483-
1. SecretManagerServiceClient obtains the channel interceptor via
484-
_observability.get_otel_interceptor passing client_options.
485-
2. The interceptor is passed into transport kwargs under 'interceptors',
486-
allowing the Transport to apply it via apply_channel_interceptors.
487-
"""
488484
mock_interceptor = mock.Mock()
489485
mock_obs = mock.Mock()
490486
mock_obs.get_otel_interceptor.return_value = mock_interceptor
@@ -506,11 +502,6 @@ def test_secret_manager_service_client_otel_channel_injection_enabled():
506502

507503

508504
def test_secret_manager_service_client_otel_channel_injection_disabled():
509-
"""Proves that when OpenTelemetry tracing is disabled:
510-
511-
1. SecretManagerServiceClient checks for an OTel interceptor and receives None.
512-
2. No OTel interceptor is added to the transport constructor kwargs.
513-
"""
514505
mock_obs = mock.Mock()
515506
mock_obs.get_otel_interceptor.return_value = None
516507
with (
@@ -526,33 +517,10 @@ def test_secret_manager_service_client_otel_channel_injection_disabled():
526517

527518
mock_obs.get_otel_interceptor.assert_called_once_with(client._client_options)
528519
called_kwargs = patched_transport_init.call_args.kwargs
529-
interceptors = called_kwargs.get("interceptors", [])
530-
assert not interceptors
531-
532-
533-
def test_secret_manager_service_client_observability_import_error():
534-
"""Proves that when _observability cannot be imported (older google-api-core),
535-
SecretManagerServiceClient instantiates gracefully without error.
536-
"""
537-
with (
538-
mock.patch(
539-
"google.cloud.secretmanager_v1.services.secret_manager_service.client._observability",
540-
None,
541-
),
542-
mock.patch.object(
543-
transports.SecretManagerServiceGrpcTransport, "__init__", return_value=None
544-
) as patched_transport_init,
545-
):
546-
SecretManagerServiceClient(transport="grpc")
547-
called_kwargs = patched_transport_init.call_args.kwargs
548520
assert not called_kwargs.get("interceptors", [])
549521

550522

551-
def test_secret_manager_service_grpc_transport_interceptors():
552-
"""Proves that SecretManagerServiceGrpcTransport accepts channel interceptors
553-
and invokes grpc_helpers.apply_channel_interceptors to apply them to the underlying
554-
gRPC channel.
555-
"""
523+
def test_secret_manager_service_grpc_transport_channel_interceptors():
556524
mock_interceptor = mock.Mock()
557525
mock_channel = mock.Mock()
558526

@@ -562,8 +530,9 @@ def test_secret_manager_service_grpc_transport_interceptors():
562530
"create_channel",
563531
return_value=mock_channel,
564532
),
565-
mock.patch(
566-
"google.api_core.grpc_helpers.apply_channel_interceptors",
533+
mock.patch.object(
534+
grpc_helpers,
535+
"apply_channel_interceptors",
567536
return_value=mock_channel,
568537
create=True,
569538
) as mock_apply_interceptors,
@@ -579,14 +548,12 @@ def test_secret_manager_service_grpc_transport_interceptors():
579548

580549

581550
def test_secret_manager_service_grpc_transport_custom_channel_interceptors():
582-
"""Proves that SecretManagerServiceGrpcTransport wraps explicitly passed custom channels
583-
using grpc_helpers.apply_channel_interceptors.
584-
"""
585551
mock_interceptor = mock.Mock()
586552
mock_custom_channel = mock.Mock(spec=grpc.Channel)
587553

588-
with mock.patch(
589-
"google.api_core.grpc_helpers.apply_channel_interceptors",
554+
with mock.patch.object(
555+
grpc_helpers,
556+
"apply_channel_interceptors",
590557
return_value=mock_custom_channel,
591558
create=True,
592559
) as mock_apply_interceptors:

0 commit comments

Comments
 (0)