From 3c21a6fb6dfd4b78d62fc06ce16316c1aafaa171 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 2 Nov 2026 18:20:35 +0000 Subject: [PATCH 1/2] ci: add REST only config to showcase unit nox session --- packages/gapic-generator/noxfile.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/gapic-generator/noxfile.py b/packages/gapic-generator/noxfile.py index 50a3c91fc5f8..1f01c3e34fac 100644 --- a/packages/gapic-generator/noxfile.py +++ b/packages/gapic-generator/noxfile.py @@ -243,6 +243,7 @@ def showcase_library( retry_config=True, rest_async_io_enabled=False, install_async_rest_extra=False, + transport="grpc+rest", ): """Install the generated library into the session for showcase tests. @@ -348,7 +349,7 @@ def showcase_library( other_opts + ( f"{template_opt}", - "transport=grpc+rest", + f"transport={transport}", f"service-yaml={tmp_dir}/showcase_v1beta1.yaml", f"retry-config={tmp_dir}/showcase_grpc_service_config.json", ) @@ -645,12 +646,20 @@ def run_showcase_unit_tests( @nox.session(python=ALL_PYTHON) -@nox.parametrize("install_async_rest_extra", [False, True]) +@nox.parametrize( + "install_async_rest_extra,transport", + [ + (False, "grpc+rest"), + (False, "rest"), + (True, "grpc+rest"), + ], +) def showcase_unit( session, install_async_rest_extra=False, templates="DEFAULT", other_opts: typing.Iterable[str] = (), + transport: str = None, ): """Run the generated unit tests against the Showcase library.""" with showcase_library( @@ -658,6 +667,7 @@ def showcase_unit( templates=templates, other_opts=other_opts, install_async_rest_extra=install_async_rest_extra, + transport=transport, ) as lib: session.chdir(lib) run_showcase_unit_tests( From 2023823e03779b839a3e6244916d02fdda902541 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 2 Nov 2026 20:57:12 +0000 Subject: [PATCH 2/2] fix coverage for REST only libraries --- .../%name_%version/%sub/test_%service.py.j2 | 28 +- .../gapic/%name_%version/%sub/test_macros.j2 | 73 ++++- .../unit/gapic/asset_v1/test_asset_service.py | 28 ++ .../credentials_v1/test_iam_credentials.py | 10 + .../unit/gapic/eventarc_v1/test_eventarc.py | 172 +++++++++++ .../logging_v2/test_config_service_v2.py | 10 + .../logging_v2/test_logging_service_v2.py | 10 + .../logging_v2/test_metrics_service_v2.py | 10 + .../logging_v2/test_config_service_v2.py | 10 + .../logging_v2/test_logging_service_v2.py | 10 + .../logging_v2/test_metrics_service_v2.py | 10 + .../unit/gapic/redis_v1/test_cloud_redis.py | 276 ++++++++++++++++++ .../unit/gapic/redis_v1/test_cloud_redis.py | 276 ++++++++++++++++++ .../unit/gapic/showcase_v1beta1/test_echo.py | 240 +++++++++++++++ .../gapic/showcase_v1beta1/test_identity.py | 172 +++++++++++ .../gapic/showcase_v1beta1/test_messaging.py | 262 +++++++++++++++++ .../test_resumable_upload_service.py | 172 +++++++++++ .../showcase_v1beta1/test_sequence_service.py | 172 +++++++++++ .../gapic/showcase_v1beta1/test_testing.py | 172 +++++++++++ .../test_storage_batch_operations.py | 118 ++++++++ 20 files changed, 2221 insertions(+), 10 deletions(-) diff --git a/packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index 136319c7ced0..9b951e15236d 100644 --- a/packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -1431,6 +1431,16 @@ def test_{{ service.name|snake_case }}_base_transport_with_adc(): transport = transports.{{ service.name }}Transport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.{{ service.name }}Transport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_{{ service.name|snake_case }}_auth_adc(): # If no credentials are provided, we should use ADC credentials. @@ -1469,6 +1479,7 @@ def test_{{ service.name|snake_case }}_transport_auth_adc(transport_class): {%- endfor %}), quota_project_id="octopus", ) +{% endif %} {% if 'grpc' in opts.transport and 'rest' in opts.transport %} @@ -1511,6 +1522,7 @@ def test_{{ service.name|snake_case }}_transport_auth_gdch_credentials(transport ) +{% if 'grpc' in opts.transport %} @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -1983,6 +1995,7 @@ async def test_{{ service.name|snake_case }}_{{ method.name|snake_case }}_grpc_a ) in str(exc_info.value) {% endfor %} {% endif %} +{% endif %} {% if service.has_resumable_upload_methods and 'rest' in opts.transport %} {% for method in service.methods.values() if method.is_resumable_upload %} @@ -2226,6 +2239,7 @@ async def test_{{ service.name|snake_case }}_{{ method.name|snake_case }}_rest_a {% endif %} +{% if 'grpc' in opts.transport %} # Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are # removed from grpc/grpc_asyncio transport constructor. @pytest.mark.filterwarnings("ignore::FutureWarning") @@ -2572,17 +2586,18 @@ def test_{{ service.name|snake_case }}_base_transport_wrap_method_older_api_core assert "is_streaming" not in kwargs -{% if 'grpc' in opts.transport %} +{% set async_wrap_transport_class = service.grpc_asyncio_transport_name if 'grpc' in opts.transport else service.name ~ opts.transport[0].capitalize() ~ 'Transport' %} +{% set async_wrap_transport_kind = 'grpc_asyncio' if 'grpc' in opts.transport else opts.transport[0] %} def test_{{ service.name|snake_case }}_base_transport_wrap_async_method_modern_api_core(monkeypatch): monkeypatch.setattr(transports.base, "_ASYNC_WRAP_METHOD_SUPPORTS_TRACING", True) - # 1. Concrete transport: passes client_options=None and kind="grpc_asyncio" + # 1. Concrete transport: passes client_options=None and kind="{{ async_wrap_transport_kind }}" with mock.patch.object(transports.base.gapic_v1.method_async, "wrap_method") as mock_wrap: - transport = transports.{{ service.grpc_asyncio_transport_name }}( + transport = transports.{{ async_wrap_transport_class }}( credentials=ga_credentials.AnonymousCredentials() ) func = mock.MagicMock() transport._wrap_async_method(func) - assert mock_wrap.call_args.kwargs["kind"] == "grpc_asyncio" + assert mock_wrap.call_args.kwargs["kind"] == "{{ async_wrap_transport_kind }}" assert "client_options" in mock_wrap.call_args.kwargs # 2. Base transport: kind raises NotImplementedError and is cleanly omitted @@ -2599,7 +2614,7 @@ def test_{{ service.name|snake_case }}_base_transport_wrap_async_method_modern_a def test_{{ service.name|snake_case }}_base_transport_wrap_async_method_older_api_core_fallbacks(monkeypatch): monkeypatch.setattr(transports.base, "_ASYNC_WRAP_METHOD_SUPPORTS_TRACING", False) with mock.patch.object(transports.base.gapic_v1.method_async, "wrap_method"): - transport = transports.{{ service.grpc_asyncio_transport_name }}( + transport = transports.{{ async_wrap_transport_class }}( credentials=ga_credentials.AnonymousCredentials() ) @@ -2647,7 +2662,7 @@ def test_{{ service.name|snake_case }}_base_transport_wrap_async_method_older_ap is_streaming=False, ) kwargs = mock_wrap.call_args.kwargs - assert kwargs.get("kind") == "grpc_asyncio" + assert kwargs.get("kind") == "{{ async_wrap_transport_kind }}" assert "client_options" not in kwargs assert "method_name" not in kwargs assert "is_streaming" not in kwargs @@ -2668,6 +2683,5 @@ def test_{{ service.name|snake_case }}_base_transport_wrap_async_method_older_ap assert "client_options" not in kwargs assert "method_name" not in kwargs assert "is_streaming" not in kwargs -{% endif %} {% endblock %} diff --git a/packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 b/packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 index 436834c20858..b3caea9f7f3b 100644 --- a/packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 +++ b/packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 @@ -1028,9 +1028,7 @@ def test_{{ method_name }}_raw_page_lro(): {% endmacro %} {% macro rest_required_tests(api, method, service, numeric_enums=False, full_extended_lro=False) %} -{% with method_name = method.client_method_name|snake_case + "_unary" if method.extended_lro and not full_extended_lro else method.client_method_name|snake_case, method_output = method.extended_lro.operation_type if method.extended_lro and not full_extended_lro else method.output %}{% if method.http_options %} -{# TODO(kbandes): remove this if condition when lro and client streaming are supported. #} -{% if not method.client_streaming %} +{% with method_name = method.client_method_name|snake_case + "_unary" if method.extended_lro and not full_extended_lro else method.client_method_name|snake_case, method_output = method.extended_lro.operation_type if method.extended_lro and not full_extended_lro else method.output %} def test_{{ method_name }}_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call @@ -1080,6 +1078,8 @@ def test_{{ method_name }}_rest_use_cached_wrapped_rpc(): assert mock_rpc.call_count == 2 +{% if method.http_options %} +{% if not method.client_streaming %} {% if method.input.required_fields %} def test_{{ method_name }}_rest_required_fields(request_type={{ method.input.ident }}): transport_class = transports.{{ service.rest_transport_name }} @@ -1323,6 +1323,38 @@ def test_{{ method_name }}_rest_flattened(): {% endwith %} {# TODO(kbandes) - reverse-transcode request args to check all request fields #} + {% if method.flattened_oneof_fields() %} + # Verify flattened oneof fields on the constructed request without + # conflicting with HTTP path template transcoding. + with mock.patch.object( + type(client.transport.{{ method.transport_safe_name|snake_case }}), + "__call__", + ) as call: + {% if method.void %} + call.return_value = None + {% elif method.lro %} + call.return_value = operations_pb2.Operation(name="operations/op") + {% elif method.server_streaming %} + call.return_value = iter([{{ method.output.ident }}()]) + {% elif method.is_resumable_upload %} + call.return_value = {{ method.client_output.ident }}() + {% else %} + call.return_value = {{ method.output.ident }}() + {% endif %} + client.{{ method_name }}( + {% for field in method.flattened_fields.values() %} + {{ field.name }}={{ field.mock_value }}, + {% endfor %} + ) + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + {% for oneofs in method.flattened_oneof_fields().values() %} + {% with field = oneofs[-1] %} + assert args[0].{{ method.flattened_field_to_key[field.name] }} == {{ field.mock_value }} + {% endwith %} + {% endfor %} + {% endif %} + def test_{{ method_name }}_rest_flattened_error(transport: str = 'rest'): client = {{ service.client_name }}( @@ -1474,6 +1506,11 @@ def test_{{ method_name }}_rest_pager(transport: str = 'rest'): assert page_.raw_page.next_page_token == token +{% elif method.lro and "next_page_token" in method.lro.response_type.fields.keys() %} +def test_{{ method_name }}_rest_raw_page_lro(): + response = {{ method.lro.response_type.ident }}() + assert response.raw_page is response + {%- endif %}{# paged_result_field #} {% else %}{# this is an lro or streaming method #} @@ -1753,6 +1790,7 @@ def test_unsupported_parameter_rest_asyncio(): {% if 'rest' in transport %} {{ bad_request_mixins_test(service, api, name, sig, transport, is_async) }} {{ call_success_mixins_test(service, api, name, sig, transport, is_async) }} +{{ empty_call_mixins_test(service, api, name, sig, transport, is_async) }} {% endif %}{# if 'rest' in transport #} {% endfor %} {{ initialize_client_with_transport_test(service, transport, is_async) }} @@ -2254,6 +2292,35 @@ def test_initialize_client_w_{{transport_name}}(): {% endif %}{# if 'grpc' in transport #} {% endmacro %}{# call_success_mixins_test #} +{% macro empty_call_mixins_test(service, api, name, sig, transport, is_async=False) %} +{% set await_prefix = get_await_prefix(is_async) %} +{% set async_prefix = get_async_prefix(is_async) %} +{% set async_decorator = get_async_decorator(is_async) %} +{% set transport_name = get_transport_name(transport, is_async) %} +{% set method_name = name|snake_case %} +{{ async_decorator }} +{{ async_prefix }}def test_{{ method_name }}_empty_call_{{ transport_name }}(): + {% if transport_name == 'rest_asyncio' %} + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + {% endif %} + client = {{ get_client(service=service, is_async=is_async) }}( + credentials={{ get_credentials(is_async=is_async) }}, + transport="{{ transport_name }}", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.{{ method_name }}), "__call__" + ) as call: + {{ await_prefix }}client.{{ method_name }}(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == {{ sig.request_type }}() +{% endmacro %}{# empty_call_mixins_test #} + {% macro empty_call_test(service, api, transport, is_async) %} {% for method in service.methods.values() %}{# method #} {% if not method.client_streaming %} diff --git a/packages/gapic-generator/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/packages/gapic-generator/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index 17fc4c8a5c07..4564f4107117 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -16910,6 +16910,24 @@ def test_get_operation_rest(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.Operation) + +def test_get_operation_empty_call_rest(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_initialize_client_w_rest(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17519,6 +17537,16 @@ def test_asset_service_base_transport_with_adc(): transport = transports.AssetServiceTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.AssetServiceTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_asset_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py b/packages/gapic-generator/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py index f39f23ababfa..ea6021b298ab 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py @@ -3933,6 +3933,16 @@ def test_iam_credentials_base_transport_with_adc(): transport = transports.IAMCredentialsTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.IAMCredentialsTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_iam_credentials_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py b/packages/gapic-generator/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py index b5e055c25ec9..d34708bfb340 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py @@ -29568,6 +29568,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_list_locations_rest_bad_request(request_type=locations_pb2.ListLocationsRequest): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29621,6 +29639,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_iam_policy_rest_bad_request(request_type=iam_policy_pb2.GetIamPolicyRequest): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29674,6 +29710,24 @@ def test_get_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_get_iam_policy_empty_call_rest(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), "__call__" + ) as call: + client.get_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_set_iam_policy_rest_bad_request(request_type=iam_policy_pb2.SetIamPolicyRequest): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29727,6 +29781,24 @@ def test_set_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_set_iam_policy_empty_call_rest(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), "__call__" + ) as call: + client.set_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_test_iam_permissions_rest_bad_request(request_type=iam_policy_pb2.TestIamPermissionsRequest): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29780,6 +29852,24 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_test_iam_permissions_empty_call_rest(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + client.test_iam_permissions(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29833,6 +29923,24 @@ def test_cancel_operation_rest(request_type): assert response is None +def test_cancel_operation_empty_call_rest(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29886,6 +29994,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29939,6 +30065,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29991,6 +30135,24 @@ def test_list_operations_rest(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.ListOperationsResponse) + +def test_list_operations_empty_call_rest(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_initialize_client_w_rest(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30960,6 +31122,16 @@ def test_eventarc_base_transport_with_adc(): transport = transports.EventarcTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.EventarcTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_eventarc_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py b/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py index acea90dd0a47..fb85c77d42a4 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -12877,6 +12877,16 @@ def test_config_service_v2_base_transport_with_adc(): transport = transports.ConfigServiceV2Transport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.ConfigServiceV2Transport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_config_service_v2_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 433ff946bd8b..8e55890cd358 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -3469,6 +3469,16 @@ def test_logging_service_v2_base_transport_with_adc(): transport = transports.LoggingServiceV2Transport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.LoggingServiceV2Transport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_logging_service_v2_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index c3809e05816a..bbee725fad77 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -3269,6 +3269,16 @@ def test_metrics_service_v2_base_transport_with_adc(): transport = transports.MetricsServiceV2Transport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.MetricsServiceV2Transport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_metrics_service_v2_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_config_service_v2.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_config_service_v2.py index 5d7d971258ae..72bf740037fe 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -12877,6 +12877,16 @@ def test_config_service_v2_base_transport_with_adc(): transport = transports.ConfigServiceV2Transport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.ConfigServiceV2Transport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_config_service_v2_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 433ff946bd8b..8e55890cd358 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -3469,6 +3469,16 @@ def test_logging_service_v2_base_transport_with_adc(): transport = transports.LoggingServiceV2Transport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.LoggingServiceV2Transport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_logging_service_v2_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index 5fc12c22406b..99719a23adb6 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -3269,6 +3269,16 @@ def test_metrics_service_v2_base_transport_with_adc(): transport = transports.MetricsServiceV2Transport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.MetricsServiceV2Transport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_metrics_service_v2_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/packages/gapic-generator/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index e2215a295660..265f43b88acb 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -8781,6 +8781,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_list_locations_rest_bad_request(request_type=locations_pb2.ListLocationsRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8834,6 +8852,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8887,6 +8923,24 @@ def test_cancel_operation_rest(request_type): assert response is None +def test_cancel_operation_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8940,6 +8994,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8993,6 +9065,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9046,6 +9136,24 @@ def test_list_operations_rest(request_type): assert isinstance(response, operations_pb2.ListOperationsResponse) +def test_list_operations_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_wait_operation_rest_bad_request(request_type=operations_pb2.WaitOperationRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9098,6 +9206,24 @@ def test_wait_operation_rest(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.Operation) + +def test_wait_operation_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.wait_operation), "__call__" + ) as call: + client.wait_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() + def test_initialize_client_w_rest(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10803,6 +10929,26 @@ async def test_get_location_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, locations_pb2.Location) +@pytest.mark.asyncio +async def test_get_location_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + await client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + @pytest.mark.asyncio async def test_list_locations_rest_asyncio_bad_request(request_type=locations_pb2.ListLocationsRequest): if not HAS_ASYNC_REST_EXTRA: @@ -10859,6 +11005,26 @@ async def test_list_locations_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, locations_pb2.ListLocationsResponse) +@pytest.mark.asyncio +async def test_list_locations_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + await client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + @pytest.mark.asyncio async def test_cancel_operation_rest_asyncio_bad_request(request_type=operations_pb2.CancelOperationRequest): if not HAS_ASYNC_REST_EXTRA: @@ -10915,6 +11081,26 @@ async def test_cancel_operation_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_cancel_operation_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + await client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + @pytest.mark.asyncio async def test_delete_operation_rest_asyncio_bad_request(request_type=operations_pb2.DeleteOperationRequest): if not HAS_ASYNC_REST_EXTRA: @@ -10971,6 +11157,26 @@ async def test_delete_operation_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_operation_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + await client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + @pytest.mark.asyncio async def test_get_operation_rest_asyncio_bad_request(request_type=operations_pb2.GetOperationRequest): if not HAS_ASYNC_REST_EXTRA: @@ -11027,6 +11233,26 @@ async def test_get_operation_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.Operation) +@pytest.mark.asyncio +async def test_get_operation_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + await client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + @pytest.mark.asyncio async def test_list_operations_rest_asyncio_bad_request(request_type=operations_pb2.ListOperationsRequest): if not HAS_ASYNC_REST_EXTRA: @@ -11083,6 +11309,26 @@ async def test_list_operations_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.ListOperationsResponse) +@pytest.mark.asyncio +async def test_list_operations_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + await client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + @pytest.mark.asyncio async def test_wait_operation_rest_asyncio_bad_request(request_type=operations_pb2.WaitOperationRequest): if not HAS_ASYNC_REST_EXTRA: @@ -11139,6 +11385,26 @@ async def test_wait_operation_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.Operation) +@pytest.mark.asyncio +async def test_wait_operation_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.wait_operation), "__call__" + ) as call: + await client.wait_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() + def test_initialize_client_w_rest_asyncio(): if not HAS_ASYNC_REST_EXTRA: pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") @@ -11539,6 +11805,16 @@ def test_cloud_redis_base_transport_with_adc(): transport = transports.CloudRedisTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.CloudRedisTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_cloud_redis_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/tests/unit/gapic/redis_v1/test_cloud_redis.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/tests/unit/gapic/redis_v1/test_cloud_redis.py index 7b29386993ee..fa9b65df4528 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -4948,6 +4948,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_list_locations_rest_bad_request(request_type=locations_pb2.ListLocationsRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5001,6 +5019,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5054,6 +5090,24 @@ def test_cancel_operation_rest(request_type): assert response is None +def test_cancel_operation_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5107,6 +5161,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5160,6 +5232,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5213,6 +5303,24 @@ def test_list_operations_rest(request_type): assert isinstance(response, operations_pb2.ListOperationsResponse) +def test_list_operations_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_wait_operation_rest_bad_request(request_type=operations_pb2.WaitOperationRequest): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5265,6 +5373,24 @@ def test_wait_operation_rest(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.Operation) + +def test_wait_operation_empty_call_rest(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.wait_operation), "__call__" + ) as call: + client.wait_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() + def test_initialize_client_w_rest(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6191,6 +6317,26 @@ async def test_get_location_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, locations_pb2.Location) +@pytest.mark.asyncio +async def test_get_location_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + await client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + @pytest.mark.asyncio async def test_list_locations_rest_asyncio_bad_request(request_type=locations_pb2.ListLocationsRequest): if not HAS_ASYNC_REST_EXTRA: @@ -6247,6 +6393,26 @@ async def test_list_locations_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, locations_pb2.ListLocationsResponse) +@pytest.mark.asyncio +async def test_list_locations_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + await client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + @pytest.mark.asyncio async def test_cancel_operation_rest_asyncio_bad_request(request_type=operations_pb2.CancelOperationRequest): if not HAS_ASYNC_REST_EXTRA: @@ -6303,6 +6469,26 @@ async def test_cancel_operation_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_cancel_operation_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + await client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + @pytest.mark.asyncio async def test_delete_operation_rest_asyncio_bad_request(request_type=operations_pb2.DeleteOperationRequest): if not HAS_ASYNC_REST_EXTRA: @@ -6359,6 +6545,26 @@ async def test_delete_operation_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_operation_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + await client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + @pytest.mark.asyncio async def test_get_operation_rest_asyncio_bad_request(request_type=operations_pb2.GetOperationRequest): if not HAS_ASYNC_REST_EXTRA: @@ -6415,6 +6621,26 @@ async def test_get_operation_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.Operation) +@pytest.mark.asyncio +async def test_get_operation_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + await client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + @pytest.mark.asyncio async def test_list_operations_rest_asyncio_bad_request(request_type=operations_pb2.ListOperationsRequest): if not HAS_ASYNC_REST_EXTRA: @@ -6471,6 +6697,26 @@ async def test_list_operations_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.ListOperationsResponse) +@pytest.mark.asyncio +async def test_list_operations_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + await client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + @pytest.mark.asyncio async def test_wait_operation_rest_asyncio_bad_request(request_type=operations_pb2.WaitOperationRequest): if not HAS_ASYNC_REST_EXTRA: @@ -6527,6 +6773,26 @@ async def test_wait_operation_rest_asyncio(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.Operation) +@pytest.mark.asyncio +async def test_wait_operation_empty_call_rest_asyncio(): + if not HAS_ASYNC_REST_EXTRA: + pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + transport="rest_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.wait_operation), "__call__" + ) as call: + await client.wait_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() + def test_initialize_client_w_rest_asyncio(): if not HAS_ASYNC_REST_EXTRA: pytest.skip("the library must be installed with the `async_rest` extra to test this feature.") @@ -6777,6 +7043,16 @@ def test_cloud_redis_base_transport_with_adc(): transport = transports.CloudRedisTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.CloudRedisTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_cloud_redis_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_echo.py b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_echo.py index 526eb660d4ff..15a2b1acef57 100755 --- a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_echo.py +++ b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_echo.py @@ -3924,6 +3924,40 @@ def test_expand_rest_flattened_error(transport: str = 'rest'): ) +def test_collect_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.collect in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.collect] = mock_rpc + + request = [{}] + client.collect(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.collect(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_collect_rest_unimplemented(): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3935,6 +3969,40 @@ def test_collect_rest_unimplemented(): client.collect(requests) +def test_chat_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.chat in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.chat] = mock_rpc + + request = [{}] + client.chat(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.chat(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_chat_rest_no_http_options(): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6683,6 +6751,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationRequest): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6736,6 +6822,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy_rest_bad_request(request_type=iam_policy_pb2.SetIamPolicyRequest): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6789,6 +6893,24 @@ def test_set_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_set_iam_policy_empty_call_rest(): + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), "__call__" + ) as call: + client.set_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy_rest_bad_request(request_type=iam_policy_pb2.GetIamPolicyRequest): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6842,6 +6964,24 @@ def test_get_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_get_iam_policy_empty_call_rest(): + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), "__call__" + ) as call: + client.get_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions_rest_bad_request(request_type=iam_policy_pb2.TestIamPermissionsRequest): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6895,6 +7035,24 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_test_iam_permissions_empty_call_rest(): + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + client.test_iam_permissions(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6948,6 +7106,24 @@ def test_list_operations_rest(request_type): assert isinstance(response, operations_pb2.ListOperationsResponse) +def test_list_operations_empty_call_rest(): + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7001,6 +7177,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7054,6 +7248,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7106,6 +7318,24 @@ def test_cancel_operation_rest(request_type): # Establish that the response is the type that we expect. assert response is None + +def test_cancel_operation_empty_call_rest(): + client = EchoClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_initialize_client_w_rest(): client = EchoClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7639,6 +7869,16 @@ def test_echo_base_transport_with_adc(): transport = transports.EchoTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.EchoTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_echo_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_identity.py b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_identity.py index 28a7dd420d23..87c90a1327c2 100755 --- a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_identity.py +++ b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_identity.py @@ -4159,6 +4159,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = IdentityClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationRequest): client = IdentityClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4212,6 +4230,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = IdentityClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy_rest_bad_request(request_type=iam_policy_pb2.SetIamPolicyRequest): client = IdentityClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4265,6 +4301,24 @@ def test_set_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_set_iam_policy_empty_call_rest(): + client = IdentityClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), "__call__" + ) as call: + client.set_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy_rest_bad_request(request_type=iam_policy_pb2.GetIamPolicyRequest): client = IdentityClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4318,6 +4372,24 @@ def test_get_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_get_iam_policy_empty_call_rest(): + client = IdentityClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), "__call__" + ) as call: + client.get_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions_rest_bad_request(request_type=iam_policy_pb2.TestIamPermissionsRequest): client = IdentityClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4371,6 +4443,24 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_test_iam_permissions_empty_call_rest(): + client = IdentityClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + client.test_iam_permissions(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = IdentityClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4424,6 +4514,24 @@ def test_list_operations_rest(request_type): assert isinstance(response, operations_pb2.ListOperationsResponse) +def test_list_operations_empty_call_rest(): + client = IdentityClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = IdentityClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4477,6 +4585,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = IdentityClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = IdentityClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4530,6 +4656,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = IdentityClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = IdentityClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4582,6 +4726,24 @@ def test_cancel_operation_rest(request_type): # Establish that the response is the type that we expect. assert response is None + +def test_cancel_operation_empty_call_rest(): + client = IdentityClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_initialize_client_w_rest(): client = IdentityClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4781,6 +4943,16 @@ def test_identity_base_transport_with_adc(): transport = transports.IdentityTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.IdentityTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_identity_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_messaging.py b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_messaging.py index 84906c414aa2..46989362ba07 100755 --- a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_messaging.py +++ b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_messaging.py @@ -5690,6 +5690,23 @@ def test_create_blurb_rest_flattened(): _, args, _ = req.mock_calls[0] assert path_template.validate("%s/v1beta1/{parent=rooms/*}/blurbs" % client.transport._host, args[1]) + # Verify flattened oneof fields on the constructed request without + # conflicting with HTTP path template transcoding. + with mock.patch.object( + type(client.transport.create_blurb), + "__call__", + ) as call: + call.return_value = messaging.Blurb() + client.create_blurb( + parent='parent_value', + user='user_value', + text='text_value', + image=b'image_blob', + ) + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].blurb.image == b'image_blob' + def test_create_blurb_rest_flattened_error(transport: str = 'rest'): client = MessagingClient( @@ -6456,6 +6473,11 @@ def test_search_blurbs_rest_flattened_error(transport: str = 'rest'): ) +def test_search_blurbs_rest_raw_page_lro(): + response = messaging.SearchBlurbsResponse() + assert response.raw_page is response + + def test_stream_blurbs_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call @@ -6568,6 +6590,40 @@ def test_stream_blurbs_rest_required_fields(request_type=messaging.StreamBlurbsR assert sorted(expected_params) == sorted(actual_params) +def test_send_blurbs_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.send_blurbs in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.send_blurbs] = mock_rpc + + request = [{}] + client.send_blurbs(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.send_blurbs(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_send_blurbs_rest_unimplemented(): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6579,6 +6635,40 @@ def test_send_blurbs_rest_unimplemented(): client.send_blurbs(requests) +def test_connect_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.connect in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.connect] = mock_rpc + + request = [{}] + client.connect(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.connect(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_connect_rest_no_http_options(): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8783,6 +8873,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationRequest): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8836,6 +8944,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy_rest_bad_request(request_type=iam_policy_pb2.SetIamPolicyRequest): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8889,6 +9015,24 @@ def test_set_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_set_iam_policy_empty_call_rest(): + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), "__call__" + ) as call: + client.set_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy_rest_bad_request(request_type=iam_policy_pb2.GetIamPolicyRequest): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8942,6 +9086,24 @@ def test_get_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_get_iam_policy_empty_call_rest(): + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), "__call__" + ) as call: + client.get_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions_rest_bad_request(request_type=iam_policy_pb2.TestIamPermissionsRequest): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8995,6 +9157,24 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_test_iam_permissions_empty_call_rest(): + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + client.test_iam_permissions(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9048,6 +9228,24 @@ def test_list_operations_rest(request_type): assert isinstance(response, operations_pb2.ListOperationsResponse) +def test_list_operations_empty_call_rest(): + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9101,6 +9299,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9154,6 +9370,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9206,6 +9440,24 @@ def test_cancel_operation_rest(request_type): # Establish that the response is the type that we expect. assert response is None + +def test_cancel_operation_empty_call_rest(): + client = MessagingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_initialize_client_w_rest(): client = MessagingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9582,6 +9834,16 @@ def test_messaging_base_transport_with_adc(): transport = transports.MessagingTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.MessagingTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_messaging_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_resumable_upload_service.py b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_resumable_upload_service.py index 3d2f99ea1ef7..f25196c0e8c7 100755 --- a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_resumable_upload_service.py +++ b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_resumable_upload_service.py @@ -1532,6 +1532,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = ResumableUploadServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationRequest): client = ResumableUploadServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1585,6 +1603,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = ResumableUploadServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy_rest_bad_request(request_type=iam_policy_pb2.SetIamPolicyRequest): client = ResumableUploadServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1638,6 +1674,24 @@ def test_set_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_set_iam_policy_empty_call_rest(): + client = ResumableUploadServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), "__call__" + ) as call: + client.set_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy_rest_bad_request(request_type=iam_policy_pb2.GetIamPolicyRequest): client = ResumableUploadServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1691,6 +1745,24 @@ def test_get_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_get_iam_policy_empty_call_rest(): + client = ResumableUploadServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), "__call__" + ) as call: + client.get_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions_rest_bad_request(request_type=iam_policy_pb2.TestIamPermissionsRequest): client = ResumableUploadServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1744,6 +1816,24 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_test_iam_permissions_empty_call_rest(): + client = ResumableUploadServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + client.test_iam_permissions(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = ResumableUploadServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1797,6 +1887,24 @@ def test_list_operations_rest(request_type): assert isinstance(response, operations_pb2.ListOperationsResponse) +def test_list_operations_empty_call_rest(): + client = ResumableUploadServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = ResumableUploadServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1850,6 +1958,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = ResumableUploadServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = ResumableUploadServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1903,6 +2029,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = ResumableUploadServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = ResumableUploadServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1955,6 +2099,24 @@ def test_cancel_operation_rest(request_type): # Establish that the response is the type that we expect. assert response is None + +def test_cancel_operation_empty_call_rest(): + client = ResumableUploadServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_initialize_client_w_rest(): client = ResumableUploadServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2066,6 +2228,16 @@ def test_resumable_upload_service_base_transport_with_adc(): transport = transports.ResumableUploadServiceTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.ResumableUploadServiceTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_resumable_upload_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_sequence_service.py b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_sequence_service.py index 444a6f91969a..0eb568b8b388 100755 --- a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_sequence_service.py +++ b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_sequence_service.py @@ -4765,6 +4765,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = SequenceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationRequest): client = SequenceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4818,6 +4836,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = SequenceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy_rest_bad_request(request_type=iam_policy_pb2.SetIamPolicyRequest): client = SequenceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4871,6 +4907,24 @@ def test_set_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_set_iam_policy_empty_call_rest(): + client = SequenceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), "__call__" + ) as call: + client.set_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy_rest_bad_request(request_type=iam_policy_pb2.GetIamPolicyRequest): client = SequenceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4924,6 +4978,24 @@ def test_get_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_get_iam_policy_empty_call_rest(): + client = SequenceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), "__call__" + ) as call: + client.get_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions_rest_bad_request(request_type=iam_policy_pb2.TestIamPermissionsRequest): client = SequenceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4977,6 +5049,24 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_test_iam_permissions_empty_call_rest(): + client = SequenceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + client.test_iam_permissions(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = SequenceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5030,6 +5120,24 @@ def test_list_operations_rest(request_type): assert isinstance(response, operations_pb2.ListOperationsResponse) +def test_list_operations_empty_call_rest(): + client = SequenceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = SequenceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5083,6 +5191,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = SequenceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = SequenceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5136,6 +5262,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = SequenceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = SequenceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5188,6 +5332,24 @@ def test_cancel_operation_rest(request_type): # Establish that the response is the type that we expect. assert response is None + +def test_cancel_operation_empty_call_rest(): + client = SequenceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_initialize_client_w_rest(): client = SequenceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5409,6 +5571,16 @@ def test_sequence_service_base_transport_with_adc(): transport = transports.SequenceServiceTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.SequenceServiceTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_sequence_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_testing.py b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_testing.py index dbda59a14f09..c0f3b8184325 100755 --- a/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_testing.py +++ b/packages/gapic-generator/tests/integration/goldens/showcase/tests/unit/gapic/showcase_v1beta1/test_testing.py @@ -4915,6 +4915,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = TestingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationRequest): client = TestingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4968,6 +4986,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = TestingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy_rest_bad_request(request_type=iam_policy_pb2.SetIamPolicyRequest): client = TestingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5021,6 +5057,24 @@ def test_set_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_set_iam_policy_empty_call_rest(): + client = TestingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), "__call__" + ) as call: + client.set_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy_rest_bad_request(request_type=iam_policy_pb2.GetIamPolicyRequest): client = TestingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5074,6 +5128,24 @@ def test_get_iam_policy_rest(request_type): assert isinstance(response, policy_pb2.Policy) +def test_get_iam_policy_empty_call_rest(): + client = TestingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), "__call__" + ) as call: + client.get_iam_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions_rest_bad_request(request_type=iam_policy_pb2.TestIamPermissionsRequest): client = TestingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5127,6 +5199,24 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_test_iam_permissions_empty_call_rest(): + client = TestingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + client.test_iam_permissions(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = TestingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5180,6 +5270,24 @@ def test_list_operations_rest(request_type): assert isinstance(response, operations_pb2.ListOperationsResponse) +def test_list_operations_empty_call_rest(): + client = TestingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = TestingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5233,6 +5341,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = TestingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = TestingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5286,6 +5412,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = TestingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = TestingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5338,6 +5482,24 @@ def test_cancel_operation_rest(request_type): # Establish that the response is the type that we expect. assert response is None + +def test_cancel_operation_empty_call_rest(): + client = TestingClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_initialize_client_w_rest(): client = TestingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5603,6 +5765,16 @@ def test_testing_base_transport_with_adc(): transport = transports.TestingTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.TestingTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_testing_auth_adc(): # If no credentials are provided, we should use ADC credentials. diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/tests/unit/gapic/storagebatchoperations_v1/test_storage_batch_operations.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/tests/unit/gapic/storagebatchoperations_v1/test_storage_batch_operations.py index c1f5ed51ac5c..6a3c3c661775 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/tests/unit/gapic/storagebatchoperations_v1/test_storage_batch_operations.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/tests/unit/gapic/storagebatchoperations_v1/test_storage_batch_operations.py @@ -6307,6 +6307,24 @@ def test_get_location_rest(request_type): assert isinstance(response, locations_pb2.Location) +def test_get_location_empty_call_rest(): + client = StorageBatchOperationsClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_location), "__call__" + ) as call: + client.get_location(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_list_locations_rest_bad_request(request_type=locations_pb2.ListLocationsRequest): client = StorageBatchOperationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6360,6 +6378,24 @@ def test_list_locations_rest(request_type): assert isinstance(response, locations_pb2.ListLocationsResponse) +def test_list_locations_empty_call_rest(): + client = StorageBatchOperationsClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_locations), "__call__" + ) as call: + client.list_locations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_cancel_operation_rest_bad_request(request_type=operations_pb2.CancelOperationRequest): client = StorageBatchOperationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6413,6 +6449,24 @@ def test_cancel_operation_rest(request_type): assert response is None +def test_cancel_operation_empty_call_rest(): + client = StorageBatchOperationsClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.cancel_operation), "__call__" + ) as call: + client.cancel_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_delete_operation_rest_bad_request(request_type=operations_pb2.DeleteOperationRequest): client = StorageBatchOperationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6466,6 +6520,24 @@ def test_delete_operation_rest(request_type): assert response is None +def test_delete_operation_empty_call_rest(): + client = StorageBatchOperationsClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_operation), "__call__" + ) as call: + client.delete_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_get_operation_rest_bad_request(request_type=operations_pb2.GetOperationRequest): client = StorageBatchOperationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6519,6 +6591,24 @@ def test_get_operation_rest(request_type): assert isinstance(response, operations_pb2.Operation) +def test_get_operation_empty_call_rest(): + client = StorageBatchOperationsClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_operation), "__call__" + ) as call: + client.get_operation(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations_rest_bad_request(request_type=operations_pb2.ListOperationsRequest): client = StorageBatchOperationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6571,6 +6661,24 @@ def test_list_operations_rest(request_type): # Establish that the response is the type that we expect. assert isinstance(response, operations_pb2.ListOperationsResponse) + +def test_list_operations_empty_call_rest(): + client = StorageBatchOperationsClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_operations), "__call__" + ) as call: + client.list_operations(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_initialize_client_w_rest(): client = StorageBatchOperationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6842,6 +6950,16 @@ def test_storage_batch_operations_base_transport_with_adc(): transport = transports.StorageBatchOperationsTransport() adc.assert_called_once() + # Test _ignore_credentials=True skips ADC and host without port defaults to :443. + class IgnoreCredsTransport(transports.StorageBatchOperationsTransport): + _ignore_credentials = True + + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + transport = IgnoreCredsTransport(host="squid.clam.whelk") + adc.assert_not_called() + assert transport._credentials is None + assert transport.host == "squid.clam.whelk:443" + def test_storage_batch_operations_auth_adc(): # If no credentials are provided, we should use ADC credentials.