diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 index 750bd734ab..699aecb050 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 @@ -40,12 +40,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -97,12 +100,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -157,12 +163,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -212,12 +221,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -270,12 +282,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -397,12 +412,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -520,12 +538,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -581,12 +602,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -641,12 +665,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -697,12 +724,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_client_macros.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_client_macros.j2 index e741d6d047..f82faeef4d 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_client_macros.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_client_macros.j2 @@ -144,43 +144,48 @@ # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.{{ method.transport_safe_name|snake_case}}] + metadata = tuple(metadata) {% if method.explicit_routing %} - header_params = {} - {% if not method.client_streaming %} - {% for routing_param in method.routing_rule.routing_parameters %} - {% if routing_param.path_template %} {# Need to match. #} + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + header_params = {} + {% if not method.client_streaming %} + {% for routing_param in method.routing_rule.routing_parameters %} + {% if routing_param.path_template %} {# Need to match. #} - routing_param_regex = {{ routing_param.to_regex() }} - regex_match = routing_param_regex.match(request.{{ routing_param.field }}) - if regex_match and regex_match.group("{{ routing_param.key }}"): - header_params["{{ routing_param.key }}"] = regex_match.group("{{ routing_param.key }}") + routing_param_regex = {{ routing_param.to_regex() }} + regex_match = routing_param_regex.match(request.{{ routing_param.field }}) + if regex_match and regex_match.group("{{ routing_param.key }}"): + header_params["{{ routing_param.key }}"] = regex_match.group("{{ routing_param.key }}") - {% else %} + {% else %} - if request.{{ routing_param.field }}: - header_params["{{ routing_param.key }}"] = request.{{ routing_param.field }} + if request.{{ routing_param.field }}: + header_params["{{ routing_param.key }}"] = request.{{ routing_param.field }} - {% endif %} - {% endfor %} {# method.routing_rule.routing_parameters #} - {% endif %} {# if not method.client_streaming #} - - if header_params: - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(header_params), + {% endif %} + {% endfor %} {# method.routing_rule.routing_parameters #} + {% endif %} {# if not method.client_streaming #} + + if header_params: + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(header_params), + ) + + {% elif method.field_headers %}{# implicit routing #} + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + {% for field_header in method.field_headers %} + {% if not method.client_streaming %} + ("{{ field_header.raw }}", request.{{ field_header.disambiguated }}), + {% endif %} + {% endfor %} + )) ) - - {% elif method.field_headers %} {# implicit routing #} - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - {% for field_header in method.field_headers %} - {% if not method.client_streaming %} - ("{{ field_header.raw }}", request.{{ field_header.disambiguated }}), - {% endif %} - {% endfor %} - )), - ) {% endif %} {# method.explicit_routing #} {{ shared_macros.add_api_version_header_to_metadata(service.version) }} diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 index 3417068a9f..75dafa63a8 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 @@ -38,12 +38,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -95,12 +98,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -155,12 +161,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -210,12 +219,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -268,12 +280,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -395,12 +410,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._validate_universe_domain() @@ -518,12 +536,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._validate_universe_domain() @@ -579,12 +600,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._validate_universe_domain() @@ -639,12 +663,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -695,12 +722,15 @@ client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 index b001cea891..e1a894f62d 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 @@ -366,17 +366,19 @@ class {{ service.async_client_name }}: rpc = self._client._transport._wrapped_methods[self._client._transport.{{ method.transport_safe_name|snake_case }}] {% if method.field_headers %} - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - {% for field_header in method.field_headers %} - {% if not method.client_streaming %} - ("{{ field_header.raw }}", request.{{ field_header.disambiguated }}), - {% endif %} - {% endfor %} - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + {% for field_header in method.field_headers %} + {% if not method.client_streaming %} + ("{{ field_header.raw }}", request.{{ field_header.disambiguated }}), + {% endif %} + {% endfor %} + )) + ) {% endif %} {{ shared_macros.add_api_version_header_to_metadata(service.version) }} @@ -533,11 +535,15 @@ class {{ service.async_client_name }}: client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("resource", request.resource),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -652,11 +658,15 @@ class {{ service.async_client_name }}: client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("resource", request.resource),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -709,11 +719,15 @@ class {{ service.async_client_name }}: client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("resource", request.resource),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 index eaa572f6e3..8d663af7ad 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 @@ -696,12 +696,15 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request.resource),) + ) + ) # Validate the universe domain. self._validate_universe_domain() @@ -817,13 +820,16 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) - + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request.resource),) + ) + ) + # Validate the universe domain. self._validate_universe_domain() @@ -876,12 +882,16 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request.resource),) + ) + ) + # Validate the universe domain. self._validate_universe_domain() diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 index b53072887a..c0da26d2d0 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 @@ -510,6 +510,83 @@ def test_{{ method.name|snake_case }}_routing_parameters(): {% endfor %} {% endif %} +def test_{{ method.name|snake_case }}_routing_header_override(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = {{ method.input.ident }}() + + # Mock the actual call within the gRPC stub, and fake the request. + 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 }}()]) + {% else %} + call.return_value = {{ method.output.ident }}() + {% endif %} + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.{{ method.safe_name|snake_case }}(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +{% if not full_extended_lro %} +@pytest.mark.asyncio +async def test_{{ method_name }}_routing_header_override_async(): + client = {{ service.async_client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = {{ method.input.ident }}() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.{{ method.transport_safe_name|snake_case }}), + '__call__') as call: + {% if method.void %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + {% elif method.lro %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + {% elif method.server_streaming %} + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock(side_effect=[{{ method.output.ident }}()]) + {% else %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall({{ method.output.ident }}()) + {% endif %} + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.{{ method_name }}(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val +{% endif %}{# full_extended_lro #} {% if method.field_headers and not method.client_streaming and not method.explicit_routing %} def test_{{ method_name }}_field_headers(): diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py index 2fee2a05b8..ade900bc5b 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py @@ -333,13 +333,15 @@ async def sample_export_assets(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.export_assets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -453,13 +455,15 @@ async def sample_list_assets(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_assets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -550,13 +554,15 @@ async def sample_batch_get_assets_history(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.batch_get_assets_history] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -672,13 +678,15 @@ async def sample_create_feed(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_feed] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -782,13 +790,15 @@ async def sample_get_feed(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_feed] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -887,13 +897,15 @@ async def sample_list_feeds(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_feeds] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1001,13 +1013,15 @@ async def sample_update_feed(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_feed] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("feed.name", request.feed.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("feed.name", request.feed.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1096,13 +1110,15 @@ async def sample_delete_feed(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_feed] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1312,13 +1328,15 @@ async def sample_search_all_resources(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.search_all_resources] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1503,13 +1521,15 @@ async def sample_search_all_iam_policies(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.search_all_iam_policies] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1601,13 +1621,15 @@ async def sample_analyze_iam_policy(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.analyze_iam_policy] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("analysis_query.scope", request.analysis_query.scope), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("analysis_query.scope", request.analysis_query.scope), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1708,13 +1730,15 @@ async def sample_analyze_iam_policy_longrunning(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.analyze_iam_policy_longrunning] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("analysis_query.scope", request.analysis_query.scope), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("analysis_query.scope", request.analysis_query.scope), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1806,13 +1830,15 @@ async def sample_analyze_move(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.analyze_move] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1902,13 +1928,15 @@ async def sample_query_assets(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.query_assets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2039,13 +2067,15 @@ async def sample_create_saved_query(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_saved_query] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2145,13 +2175,15 @@ async def sample_get_saved_query(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_saved_query] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2257,13 +2289,15 @@ async def sample_list_saved_queries(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_saved_queries] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2385,13 +2419,15 @@ async def sample_update_saved_query(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_saved_query] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("saved_query.name", request.saved_query.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("saved_query.name", request.saved_query.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2482,13 +2518,15 @@ async def sample_delete_saved_query(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_saved_query] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2563,13 +2601,15 @@ async def sample_batch_get_effective_iam_policies(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.batch_get_effective_iam_policies] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2704,13 +2744,15 @@ async def sample_analyze_org_policies(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.analyze_org_policies] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2856,13 +2898,15 @@ async def sample_analyze_org_policy_governed_containers(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.analyze_org_policy_governed_containers] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3037,13 +3081,15 @@ async def sample_analyze_org_policy_governed_assets(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.analyze_org_policy_governed_assets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3107,12 +3153,15 @@ async def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py index 23c8a7c27d..771c5877f6 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py @@ -730,13 +730,15 @@ def sample_export_assets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.export_assets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -849,13 +851,15 @@ def sample_list_assets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_assets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -946,13 +950,15 @@ def sample_batch_get_assets_history(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.batch_get_assets_history] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1067,13 +1073,15 @@ def sample_create_feed(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_feed] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1176,13 +1184,15 @@ def sample_get_feed(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_feed] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1280,13 +1290,15 @@ def sample_list_feeds(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_feeds] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1393,13 +1405,15 @@ def sample_update_feed(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_feed] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("feed.name", request.feed.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("feed.name", request.feed.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1487,13 +1501,15 @@ def sample_delete_feed(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_feed] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1702,13 +1718,15 @@ def sample_search_all_resources(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.search_all_resources] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1892,13 +1910,15 @@ def sample_search_all_iam_policies(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.search_all_iam_policies] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1990,13 +2010,15 @@ def sample_analyze_iam_policy(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_iam_policy] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("analysis_query.scope", request.analysis_query.scope), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("analysis_query.scope", request.analysis_query.scope), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2097,13 +2119,15 @@ def sample_analyze_iam_policy_longrunning(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_iam_policy_longrunning] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("analysis_query.scope", request.analysis_query.scope), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("analysis_query.scope", request.analysis_query.scope), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2195,13 +2219,15 @@ def sample_analyze_move(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_move] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2291,13 +2317,15 @@ def sample_query_assets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.query_assets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2427,13 +2455,15 @@ def sample_create_saved_query(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_saved_query] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2532,13 +2562,15 @@ def sample_get_saved_query(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_saved_query] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2643,13 +2675,15 @@ def sample_list_saved_queries(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_saved_queries] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2770,13 +2804,15 @@ def sample_update_saved_query(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_saved_query] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("saved_query.name", request.saved_query.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("saved_query.name", request.saved_query.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2866,13 +2902,15 @@ def sample_delete_saved_query(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_saved_query] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2947,13 +2985,15 @@ def sample_batch_get_effective_iam_policies(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.batch_get_effective_iam_policies] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3087,13 +3127,15 @@ def sample_analyze_org_policies(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_org_policies] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3238,13 +3280,15 @@ def sample_analyze_org_policy_governed_containers(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_org_policy_governed_containers] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3418,13 +3462,15 @@ def sample_analyze_org_policy_governed_assets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_org_policy_governed_assets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("scope", request.scope), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("scope", request.scope), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3501,12 +3547,15 @@ def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() diff --git a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index 980beb35d2..6e793b84e5 100755 --- a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -979,6 +979,65 @@ async def test_export_assets_async_from_dict(): await test_export_assets_async(request_type=dict) +def test_export_assets_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.ExportAssetsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_assets), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.export_assets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_export_assets_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.ExportAssetsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_assets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.export_assets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_export_assets_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1249,6 +1308,65 @@ async def test_list_assets_async_from_dict(): await test_list_assets_async(request_type=dict) +def test_list_assets_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.ListAssetsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_assets), + '__call__') as call: + call.return_value = asset_service.ListAssetsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_assets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_assets_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.ListAssetsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_assets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.ListAssetsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_assets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_assets_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1790,6 +1908,65 @@ async def test_batch_get_assets_history_async_from_dict(): await test_batch_get_assets_history_async(request_type=dict) +def test_batch_get_assets_history_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.BatchGetAssetsHistoryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_get_assets_history), + '__call__') as call: + call.return_value = asset_service.BatchGetAssetsHistoryResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.batch_get_assets_history(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_batch_get_assets_history_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.BatchGetAssetsHistoryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_get_assets_history), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.BatchGetAssetsHistoryResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.batch_get_assets_history(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_batch_get_assets_history_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2080,6 +2257,65 @@ async def test_create_feed_async_from_dict(): await test_create_feed_async(request_type=dict) +def test_create_feed_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.CreateFeedRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_feed), + '__call__') as call: + call.return_value = asset_service.Feed() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_feed(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_feed_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.CreateFeedRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_feed), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.Feed()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_feed(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_feed_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2450,6 +2686,65 @@ async def test_get_feed_async_from_dict(): await test_get_feed_async(request_type=dict) +def test_get_feed_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.GetFeedRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_feed), + '__call__') as call: + call.return_value = asset_service.Feed() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_feed(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_feed_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.GetFeedRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_feed), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.Feed()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_feed(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_feed_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2795,6 +3090,65 @@ async def test_list_feeds_async_from_dict(): await test_list_feeds_async(request_type=dict) +def test_list_feeds_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.ListFeedsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_feeds), + '__call__') as call: + call.return_value = asset_service.ListFeedsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_feeds(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_feeds_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.ListFeedsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_feeds), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.ListFeedsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_feeds(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_feeds_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3163,7 +3517,7 @@ async def test_update_feed_async_from_dict(): await test_update_feed_async(request_type=dict) -def test_update_feed_field_headers(): +def test_update_feed_routing_header_override(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3172,30 +3526,89 @@ def test_update_feed_field_headers(): # a field header. Set these to a non-empty value. request = asset_service.UpdateFeedRequest() - request.feed.name = 'name_value' - # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.update_feed), '__call__') as call: call.return_value = asset_service.Feed() - client.update_feed(request) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_feed(request, metadata=override) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'feed.name=name_value', - ) in kw['metadata'] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val @pytest.mark.asyncio -async def test_update_feed_field_headers_async(): +async def test_update_feed_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.UpdateFeedRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_feed), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.Feed()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_feed(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + +def test_update_feed_field_headers(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.UpdateFeedRequest() + + request.feed.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_feed), + '__call__') as call: + call.return_value = asset_service.Feed() + client.update_feed(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'feed.name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_feed_field_headers_async(): client = AssetServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3505,6 +3918,65 @@ async def test_delete_feed_async_from_dict(): await test_delete_feed_async(request_type=dict) +def test_delete_feed_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.DeleteFeedRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_feed), + '__call__') as call: + call.return_value = None + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_feed(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_feed_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.DeleteFeedRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_feed), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_feed(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_feed_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3861,6 +4333,65 @@ async def test_search_all_resources_async_from_dict(): await test_search_all_resources_async(request_type=dict) +def test_search_all_resources_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.SearchAllResourcesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_all_resources), + '__call__') as call: + call.return_value = asset_service.SearchAllResourcesResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.search_all_resources(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_search_all_resources_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.SearchAllResourcesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_all_resources), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.SearchAllResourcesResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.search_all_resources(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_search_all_resources_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4433,6 +4964,65 @@ async def test_search_all_iam_policies_async_from_dict(): await test_search_all_iam_policies_async(request_type=dict) +def test_search_all_iam_policies_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.SearchAllIamPoliciesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_all_iam_policies), + '__call__') as call: + call.return_value = asset_service.SearchAllIamPoliciesResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.search_all_iam_policies(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_search_all_iam_policies_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.SearchAllIamPoliciesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_all_iam_policies), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.SearchAllIamPoliciesResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.search_all_iam_policies(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_search_all_iam_policies_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4989,6 +5579,65 @@ async def test_analyze_iam_policy_async_from_dict(): await test_analyze_iam_policy_async(request_type=dict) +def test_analyze_iam_policy_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_iam_policy), + '__call__') as call: + call.return_value = asset_service.AnalyzeIamPolicyResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.analyze_iam_policy(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_analyze_iam_policy_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_iam_policy), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.AnalyzeIamPolicyResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.analyze_iam_policy(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_analyze_iam_policy_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5261,6 +5910,65 @@ async def test_analyze_iam_policy_longrunning_async_from_dict(): await test_analyze_iam_policy_longrunning_async(request_type=dict) +def test_analyze_iam_policy_longrunning_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeIamPolicyLongrunningRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_iam_policy_longrunning), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.analyze_iam_policy_longrunning(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_analyze_iam_policy_longrunning_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeIamPolicyLongrunningRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_iam_policy_longrunning), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.analyze_iam_policy_longrunning(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_analyze_iam_policy_longrunning_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5526,6 +6234,65 @@ async def test_analyze_move_async_from_dict(): await test_analyze_move_async(request_type=dict) +def test_analyze_move_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeMoveRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_move), + '__call__') as call: + call.return_value = asset_service.AnalyzeMoveResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.analyze_move(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_analyze_move_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeMoveRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_move), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.AnalyzeMoveResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.analyze_move(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_analyze_move_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5805,6 +6572,65 @@ async def test_query_assets_async_from_dict(): await test_query_assets_async(request_type=dict) +def test_query_assets_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.QueryAssetsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_assets), + '__call__') as call: + call.return_value = asset_service.QueryAssetsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.query_assets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_query_assets_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.QueryAssetsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_assets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.QueryAssetsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.query_assets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_query_assets_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6090,6 +6916,65 @@ async def test_create_saved_query_async_from_dict(): await test_create_saved_query_async(request_type=dict) +def test_create_saved_query_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.CreateSavedQueryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_saved_query), + '__call__') as call: + call.return_value = asset_service.SavedQuery() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_saved_query(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_saved_query_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.CreateSavedQueryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_saved_query), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.SavedQuery()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_saved_query(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_saved_query_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6475,6 +7360,65 @@ async def test_get_saved_query_async_from_dict(): await test_get_saved_query_async(request_type=dict) +def test_get_saved_query_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.GetSavedQueryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_saved_query), + '__call__') as call: + call.return_value = asset_service.SavedQuery() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_saved_query(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_saved_query_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.GetSavedQueryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_saved_query), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.SavedQuery()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_saved_query(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_saved_query_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6824,10 +7768,69 @@ async def test_list_saved_queries_async(transport: str = 'grpc_asyncio', request assert response.next_page_token == 'next_page_token_value' -@pytest.mark.asyncio -async def test_list_saved_queries_async_from_dict(): - await test_list_saved_queries_async(request_type=dict) +@pytest.mark.asyncio +async def test_list_saved_queries_async_from_dict(): + await test_list_saved_queries_async(request_type=dict) + + +def test_list_saved_queries_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.ListSavedQueriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_saved_queries), + '__call__') as call: + call.return_value = asset_service.ListSavedQueriesResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_saved_queries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_saved_queries_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.ListSavedQueriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_saved_queries), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.ListSavedQueriesResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_saved_queries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val def test_list_saved_queries_field_headers(): client = AssetServiceClient( @@ -7388,6 +8391,65 @@ async def test_update_saved_query_async_from_dict(): await test_update_saved_query_async(request_type=dict) +def test_update_saved_query_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.UpdateSavedQueryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_saved_query), + '__call__') as call: + call.return_value = asset_service.SavedQuery() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_saved_query(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_saved_query_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.UpdateSavedQueryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_saved_query), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.SavedQuery()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_saved_query(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_saved_query_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7740,6 +8802,65 @@ async def test_delete_saved_query_async_from_dict(): await test_delete_saved_query_async(request_type=dict) +def test_delete_saved_query_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.DeleteSavedQueryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_saved_query), + '__call__') as call: + call.return_value = None + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_saved_query(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_saved_query_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.DeleteSavedQueryRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_saved_query), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_saved_query(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_saved_query_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8085,6 +9206,65 @@ async def test_batch_get_effective_iam_policies_async_from_dict(): await test_batch_get_effective_iam_policies_async(request_type=dict) +def test_batch_get_effective_iam_policies_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.BatchGetEffectiveIamPoliciesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_get_effective_iam_policies), + '__call__') as call: + call.return_value = asset_service.BatchGetEffectiveIamPoliciesResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.batch_get_effective_iam_policies(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_batch_get_effective_iam_policies_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.BatchGetEffectiveIamPoliciesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_get_effective_iam_policies), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.BatchGetEffectiveIamPoliciesResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.batch_get_effective_iam_policies(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_batch_get_effective_iam_policies_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8359,6 +9539,65 @@ async def test_analyze_org_policies_async_from_dict(): await test_analyze_org_policies_async(request_type=dict) +def test_analyze_org_policies_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeOrgPoliciesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_org_policies), + '__call__') as call: + call.return_value = asset_service.AnalyzeOrgPoliciesResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.analyze_org_policies(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_analyze_org_policies_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeOrgPoliciesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_org_policies), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.AnalyzeOrgPoliciesResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.analyze_org_policies(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_analyze_org_policies_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8931,6 +10170,65 @@ async def test_analyze_org_policy_governed_containers_async_from_dict(): await test_analyze_org_policy_governed_containers_async(request_type=dict) +def test_analyze_org_policy_governed_containers_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeOrgPolicyGovernedContainersRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_org_policy_governed_containers), + '__call__') as call: + call.return_value = asset_service.AnalyzeOrgPolicyGovernedContainersResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.analyze_org_policy_governed_containers(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_analyze_org_policy_governed_containers_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeOrgPolicyGovernedContainersRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_org_policy_governed_containers), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.AnalyzeOrgPolicyGovernedContainersResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.analyze_org_policy_governed_containers(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_analyze_org_policy_governed_containers_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9503,6 +10801,65 @@ async def test_analyze_org_policy_governed_assets_async_from_dict(): await test_analyze_org_policy_governed_assets_async(request_type=dict) +def test_analyze_org_policy_governed_assets_routing_header_override(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeOrgPolicyGovernedAssetsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_org_policy_governed_assets), + '__call__') as call: + call.return_value = asset_service.AnalyzeOrgPolicyGovernedAssetsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.analyze_org_policy_governed_assets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_analyze_org_policy_governed_assets_routing_header_override_async(): + client = AssetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = asset_service.AnalyzeOrgPolicyGovernedAssetsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.analyze_org_policy_governed_assets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.AnalyzeOrgPolicyGovernedAssetsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.analyze_org_policy_governed_assets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_analyze_org_policy_governed_assets_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py index d61293a8be..eeadd998a9 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py @@ -372,13 +372,15 @@ async def sample_generate_access_token(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.generate_access_token] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -521,13 +523,15 @@ async def sample_generate_id_token(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.generate_id_token] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -656,13 +660,15 @@ async def sample_sign_blob(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.sign_blob] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -794,13 +800,15 @@ async def sample_sign_jwt(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.sign_jwt] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py index 9126bd1da6..4804c62523 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py @@ -714,13 +714,15 @@ def sample_generate_access_token(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.generate_access_token] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -862,13 +864,15 @@ def sample_generate_id_token(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.generate_id_token] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -996,13 +1000,15 @@ def sample_sign_blob(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.sign_blob] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1133,13 +1139,15 @@ def sample_sign_jwt(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.sign_jwt] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() diff --git a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py index c07b6bdf38..2a5aa08f08 100755 --- a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py +++ b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py @@ -965,6 +965,65 @@ async def test_generate_access_token_async_from_dict(): await test_generate_access_token_async(request_type=dict) +def test_generate_access_token_routing_header_override(): + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = common.GenerateAccessTokenRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.generate_access_token), + '__call__') as call: + call.return_value = common.GenerateAccessTokenResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.generate_access_token(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_generate_access_token_routing_header_override_async(): + client = IAMCredentialsAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = common.GenerateAccessTokenRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.generate_access_token), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.GenerateAccessTokenResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.generate_access_token(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_generate_access_token_field_headers(): client = IAMCredentialsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1343,6 +1402,65 @@ async def test_generate_id_token_async_from_dict(): await test_generate_id_token_async(request_type=dict) +def test_generate_id_token_routing_header_override(): + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = common.GenerateIdTokenRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.generate_id_token), + '__call__') as call: + call.return_value = common.GenerateIdTokenResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.generate_id_token(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_generate_id_token_routing_header_override_async(): + client = IAMCredentialsAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = common.GenerateIdTokenRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.generate_id_token), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.GenerateIdTokenResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.generate_id_token(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_generate_id_token_field_headers(): client = IAMCredentialsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1728,6 +1846,65 @@ async def test_sign_blob_async_from_dict(): await test_sign_blob_async(request_type=dict) +def test_sign_blob_routing_header_override(): + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = common.SignBlobRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.sign_blob), + '__call__') as call: + call.return_value = common.SignBlobResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.sign_blob(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_sign_blob_routing_header_override_async(): + client = IAMCredentialsAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = common.SignBlobRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.sign_blob), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.SignBlobResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.sign_blob(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_sign_blob_field_headers(): client = IAMCredentialsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2105,6 +2282,65 @@ async def test_sign_jwt_async_from_dict(): await test_sign_jwt_async(request_type=dict) +def test_sign_jwt_routing_header_override(): + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = common.SignJwtRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.sign_jwt), + '__call__') as call: + call.return_value = common.SignJwtResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.sign_jwt(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_sign_jwt_routing_header_override_async(): + client = IAMCredentialsAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = common.SignJwtRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.sign_jwt), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.SignJwtResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.sign_jwt(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_sign_jwt_field_headers(): client = IAMCredentialsClient( credentials=ga_credentials.AnonymousCredentials(), diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py index cdf056c7a0..c9243ebc06 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py @@ -347,13 +347,15 @@ async def sample_get_trigger(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_trigger] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -453,13 +455,15 @@ async def sample_list_triggers(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_triggers] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -603,13 +607,15 @@ async def sample_create_trigger(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_trigger] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -742,13 +748,15 @@ async def sample_update_trigger(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_trigger] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("trigger.name", request.trigger.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("trigger.name", request.trigger.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -872,13 +880,15 @@ async def sample_delete_trigger(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_trigger] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -989,13 +999,15 @@ async def sample_get_channel(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_channel] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1095,13 +1107,15 @@ async def sample_list_channels(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_channels] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1245,13 +1259,15 @@ async def sample_create_channel(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_channel_] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1376,13 +1392,15 @@ async def sample_update_channel(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_channel] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("channel.name", request.channel.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("channel.name", request.channel.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1498,13 +1516,15 @@ async def sample_delete_channel(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_channel] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1609,13 +1629,15 @@ async def sample_get_provider(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_provider] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1715,13 +1737,15 @@ async def sample_list_providers(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_providers] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1834,13 +1858,15 @@ async def sample_get_channel_connection(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_channel_connection] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1941,13 +1967,15 @@ async def sample_list_channel_connections(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_channel_connections] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2091,13 +2119,15 @@ async def sample_create_channel_connection(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_channel_connection] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2211,13 +2241,15 @@ async def sample_delete_channel_connection(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_channel_connection] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2328,13 +2360,15 @@ async def sample_get_google_channel_config(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_google_channel_config] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2450,13 +2484,15 @@ async def sample_update_google_channel_config(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_google_channel_config] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("google_channel_config.name", request.google_channel_config.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("google_channel_config.name", request.google_channel_config.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2509,12 +2545,15 @@ async def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2563,12 +2602,15 @@ async def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2621,12 +2663,15 @@ async def delete_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2674,12 +2719,15 @@ async def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2790,12 +2838,15 @@ async def set_iam_policy( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2911,12 +2962,15 @@ async def get_iam_policy( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2970,12 +3024,15 @@ async def test_iam_permissions( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3024,12 +3081,15 @@ async def get_location( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3078,12 +3138,15 @@ async def list_locations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py index c82b0a80dc..4765bc2ccd 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py @@ -770,13 +770,15 @@ def sample_get_trigger(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_trigger] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -875,13 +877,15 @@ def sample_list_triggers(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_triggers] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1024,13 +1028,15 @@ def sample_create_trigger(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_trigger] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1162,13 +1168,15 @@ def sample_update_trigger(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_trigger] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("trigger.name", request.trigger.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("trigger.name", request.trigger.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1291,13 +1299,15 @@ def sample_delete_trigger(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_trigger] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1407,13 +1417,15 @@ def sample_get_channel(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_channel] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1512,13 +1524,15 @@ def sample_list_channels(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_channels] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1661,13 +1675,15 @@ def sample_create_channel(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_channel_] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1791,13 +1807,15 @@ def sample_update_channel(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_channel] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("channel.name", request.channel.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("channel.name", request.channel.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1912,13 +1930,15 @@ def sample_delete_channel(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_channel] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2022,13 +2042,15 @@ def sample_get_provider(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_provider] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2127,13 +2149,15 @@ def sample_list_providers(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_providers] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2245,13 +2269,15 @@ def sample_get_channel_connection(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_channel_connection] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2351,13 +2377,15 @@ def sample_list_channel_connections(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_channel_connections] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2500,13 +2528,15 @@ def sample_create_channel_connection(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_channel_connection] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2619,13 +2649,15 @@ def sample_delete_channel_connection(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_channel_connection] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2735,13 +2767,15 @@ def sample_get_google_channel_config(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_google_channel_config] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2856,13 +2890,15 @@ def sample_update_google_channel_config(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_google_channel_config] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("google_channel_config.name", request.google_channel_config.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("google_channel_config.name", request.google_channel_config.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2928,12 +2964,15 @@ def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2982,12 +3021,15 @@ def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3040,12 +3082,15 @@ def delete_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3093,12 +3138,15 @@ def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3209,12 +3257,15 @@ def set_iam_policy( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3330,12 +3381,15 @@ def get_iam_policy( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3389,12 +3443,15 @@ def test_iam_permissions( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource),) + ) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3443,12 +3500,15 @@ def get_location( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3497,12 +3557,15 @@ def list_locations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() diff --git a/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py b/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py index 49890323b4..5281bbe67f 100755 --- a/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py +++ b/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py @@ -1005,6 +1005,65 @@ async def test_get_trigger_async_from_dict(): await test_get_trigger_async(request_type=dict) +def test_get_trigger_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetTriggerRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_trigger), + '__call__') as call: + call.return_value = trigger.Trigger() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_trigger(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_trigger_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetTriggerRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_trigger), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(trigger.Trigger()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_trigger(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_trigger_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1366,6 +1425,65 @@ async def test_list_triggers_async_from_dict(): await test_list_triggers_async(request_type=dict) +def test_list_triggers_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.ListTriggersRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_triggers), + '__call__') as call: + call.return_value = eventarc.ListTriggersResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_triggers(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_triggers_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.ListTriggersRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_triggers), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(eventarc.ListTriggersResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_triggers(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_triggers_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1918,6 +2036,65 @@ async def test_create_trigger_async_from_dict(): await test_create_trigger_async(request_type=dict) +def test_create_trigger_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.CreateTriggerRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_trigger), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_trigger(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_trigger_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.CreateTriggerRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_trigger), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_trigger(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_trigger_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2292,6 +2469,65 @@ async def test_update_trigger_async_from_dict(): await test_update_trigger_async(request_type=dict) +def test_update_trigger_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.UpdateTriggerRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_trigger), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_trigger(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_trigger_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.UpdateTriggerRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_trigger), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_trigger(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_trigger_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2670,6 +2906,65 @@ async def test_delete_trigger_async_from_dict(): await test_delete_trigger_async(request_type=dict) +def test_delete_trigger_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.DeleteTriggerRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_trigger), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_trigger(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_trigger_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.DeleteTriggerRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_trigger), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_trigger(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_trigger_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3058,6 +3353,65 @@ async def test_get_channel_async_from_dict(): await test_get_channel_async(request_type=dict) +def test_get_channel_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetChannelRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_channel), + '__call__') as call: + call.return_value = channel.Channel() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_channel(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_channel_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetChannelRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_channel), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(channel.Channel()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_channel(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_channel_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3417,6 +3771,65 @@ async def test_list_channels_async_from_dict(): await test_list_channels_async(request_type=dict) +def test_list_channels_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.ListChannelsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_channels), + '__call__') as call: + call.return_value = eventarc.ListChannelsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_channels(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_channels_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.ListChannelsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_channels), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(eventarc.ListChannelsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_channels(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_channels_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3969,6 +4382,65 @@ async def test_create_channel_async_from_dict(): await test_create_channel_async(request_type=dict) +def test_create_channel_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.CreateChannelRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_channel_), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_channel(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_channel_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.CreateChannelRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_channel_), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_channel(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_channel_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4343,6 +4815,65 @@ async def test_update_channel_async_from_dict(): await test_update_channel_async(request_type=dict) +def test_update_channel_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.UpdateChannelRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_channel), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_channel(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_channel_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.UpdateChannelRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_channel), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_channel(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_channel_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4709,6 +5240,65 @@ async def test_delete_channel_async_from_dict(): await test_delete_channel_async(request_type=dict) +def test_delete_channel_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.DeleteChannelRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_channel), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_channel(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_channel_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.DeleteChannelRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_channel), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_channel(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_channel_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5066,6 +5656,65 @@ async def test_get_provider_async_from_dict(): await test_get_provider_async(request_type=dict) +def test_get_provider_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetProviderRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_provider), + '__call__') as call: + call.return_value = discovery.Provider() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_provider(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_provider_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetProviderRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_provider), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(discovery.Provider()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_provider(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_provider_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5422,10 +6071,69 @@ async def test_list_providers_async(transport: str = 'grpc_asyncio', request_typ assert response.unreachable == ['unreachable_value'] -@pytest.mark.asyncio -async def test_list_providers_async_from_dict(): - await test_list_providers_async(request_type=dict) +@pytest.mark.asyncio +async def test_list_providers_async_from_dict(): + await test_list_providers_async(request_type=dict) + + +def test_list_providers_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.ListProvidersRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_providers), + '__call__') as call: + call.return_value = eventarc.ListProvidersResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_providers(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_providers_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.ListProvidersRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_providers), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(eventarc.ListProvidersResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_providers(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val def test_list_providers_field_headers(): client = EventarcClient( @@ -5988,6 +6696,65 @@ async def test_get_channel_connection_async_from_dict(): await test_get_channel_connection_async(request_type=dict) +def test_get_channel_connection_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetChannelConnectionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_channel_connection), + '__call__') as call: + call.return_value = channel_connection.ChannelConnection() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_channel_connection(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_channel_connection_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetChannelConnectionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_channel_connection), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(channel_connection.ChannelConnection()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_channel_connection(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_channel_connection_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6345,6 +7112,65 @@ async def test_list_channel_connections_async_from_dict(): await test_list_channel_connections_async(request_type=dict) +def test_list_channel_connections_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.ListChannelConnectionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_channel_connections), + '__call__') as call: + call.return_value = eventarc.ListChannelConnectionsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_channel_connections(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_channel_connections_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.ListChannelConnectionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_channel_connections), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(eventarc.ListChannelConnectionsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_channel_connections(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_channel_connections_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6897,6 +7723,65 @@ async def test_create_channel_connection_async_from_dict(): await test_create_channel_connection_async(request_type=dict) +def test_create_channel_connection_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.CreateChannelConnectionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_channel_connection), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_channel_connection(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_channel_connection_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.CreateChannelConnectionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_channel_connection), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_channel_connection(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_channel_connection_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7273,6 +8158,65 @@ async def test_delete_channel_connection_async_from_dict(): await test_delete_channel_connection_async(request_type=dict) +def test_delete_channel_connection_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.DeleteChannelConnectionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_channel_connection), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_channel_connection(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_channel_connection_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.DeleteChannelConnectionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_channel_connection), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_channel_connection(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_channel_connection_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7630,6 +8574,65 @@ async def test_get_google_channel_config_async_from_dict(): await test_get_google_channel_config_async(request_type=dict) +def test_get_google_channel_config_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetGoogleChannelConfigRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_google_channel_config), + '__call__') as call: + call.return_value = google_channel_config.GoogleChannelConfig() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_google_channel_config(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_google_channel_config_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.GetGoogleChannelConfigRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_google_channel_config), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(google_channel_config.GoogleChannelConfig()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_google_channel_config(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_google_channel_config_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7983,6 +8986,65 @@ async def test_update_google_channel_config_async_from_dict(): await test_update_google_channel_config_async(request_type=dict) +def test_update_google_channel_config_routing_header_override(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.UpdateGoogleChannelConfigRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_google_channel_config), + '__call__') as call: + call.return_value = gce_google_channel_config.GoogleChannelConfig() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_google_channel_config(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_google_channel_config_routing_header_override_async(): + client = EventarcAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = eventarc.UpdateGoogleChannelConfigRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_google_channel_config), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gce_google_channel_config.GoogleChannelConfig()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_google_channel_config(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_google_channel_config_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py index f5ab658fe1..fa3b65c325 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py @@ -338,13 +338,15 @@ async def sample_list_buckets(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_buckets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -431,13 +433,15 @@ async def sample_get_bucket(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -524,13 +528,15 @@ async def sample_create_bucket_async(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_bucket_async] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -627,13 +633,15 @@ async def sample_update_bucket_async(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_bucket_async] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -720,13 +728,15 @@ async def sample_create_bucket(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -808,13 +818,15 @@ async def sample_update_bucket(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -886,13 +898,15 @@ async def sample_delete_bucket(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -958,13 +972,15 @@ async def sample_undelete_bucket(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.undelete_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1064,13 +1080,15 @@ async def sample_list_views(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_views] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1157,13 +1175,15 @@ async def sample_get_view(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_view] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1241,13 +1261,15 @@ async def sample_create_view(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_view] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1327,13 +1349,15 @@ async def sample_update_view(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_view] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1403,13 +1427,15 @@ async def sample_delete_view(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_view] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1512,13 +1538,15 @@ async def sample_list_sinks(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_sinks] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1642,13 +1670,15 @@ async def sample_get_sink(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_sink] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("sink_name", request.sink_name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("sink_name", request.sink_name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1780,13 +1810,15 @@ async def sample_create_sink(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_sink] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1945,13 +1977,15 @@ async def sample_update_sink(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_sink] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("sink_name", request.sink_name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("sink_name", request.sink_name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2050,13 +2084,15 @@ async def sample_delete_sink(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_sink] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("sink_name", request.sink_name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("sink_name", request.sink_name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2186,13 +2222,15 @@ async def sample_create_link(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_link] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2315,13 +2353,15 @@ async def sample_delete_link(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_link] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2434,13 +2474,15 @@ async def sample_list_links(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_links] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2551,13 +2593,15 @@ async def sample_get_link(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_link] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2664,13 +2708,15 @@ async def sample_list_exclusions(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_exclusions] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2792,13 +2838,15 @@ async def sample_get_exclusion(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_exclusion] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2929,13 +2977,15 @@ async def sample_create_exclusion(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_exclusion] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3080,13 +3130,15 @@ async def sample_update_exclusion(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_exclusion] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3184,13 +3236,15 @@ async def sample_delete_exclusion(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_exclusion] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3287,13 +3341,15 @@ async def sample_get_cmek_settings(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_cmek_settings] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3398,13 +3454,15 @@ async def sample_update_cmek_settings(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_cmek_settings] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3533,13 +3591,15 @@ async def sample_get_settings(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_settings] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3678,13 +3738,15 @@ async def sample_update_settings(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_settings] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3829,12 +3891,15 @@ async def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3883,12 +3948,15 @@ async def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -3940,12 +4008,15 @@ async def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py index 2593d1ce66..5b2b086858 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py @@ -732,13 +732,15 @@ def sample_list_buckets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_buckets] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -825,13 +827,15 @@ def sample_get_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -918,13 +922,15 @@ def sample_create_bucket_async(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_bucket_async] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1021,13 +1027,15 @@ def sample_update_bucket_async(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_bucket_async] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1114,13 +1122,15 @@ def sample_create_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1202,13 +1212,15 @@ def sample_update_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1280,13 +1292,15 @@ def sample_delete_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1352,13 +1366,15 @@ def sample_undelete_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.undelete_bucket] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1457,13 +1473,15 @@ def sample_list_views(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_views] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1550,13 +1568,15 @@ def sample_get_view(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_view] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1634,13 +1654,15 @@ def sample_create_view(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_view] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1720,13 +1742,15 @@ def sample_update_view(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_view] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1796,13 +1820,15 @@ def sample_delete_view(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_view] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1904,13 +1930,15 @@ def sample_list_sinks(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_sinks] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2033,13 +2061,15 @@ def sample_get_sink(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_sink] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("sink_name", request.sink_name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("sink_name", request.sink_name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2170,13 +2200,15 @@ def sample_create_sink(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_sink] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2334,13 +2366,15 @@ def sample_update_sink(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_sink] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("sink_name", request.sink_name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("sink_name", request.sink_name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2438,13 +2472,15 @@ def sample_delete_sink(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_sink] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("sink_name", request.sink_name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("sink_name", request.sink_name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2573,13 +2609,15 @@ def sample_create_link(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_link] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2701,13 +2739,15 @@ def sample_delete_link(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_link] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2819,13 +2859,15 @@ def sample_list_links(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_links] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2935,13 +2977,15 @@ def sample_get_link(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_link] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3047,13 +3091,15 @@ def sample_list_exclusions(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_exclusions] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3174,13 +3220,15 @@ def sample_get_exclusion(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_exclusion] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3310,13 +3358,15 @@ def sample_create_exclusion(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_exclusion] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3460,13 +3510,15 @@ def sample_update_exclusion(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_exclusion] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3563,13 +3615,15 @@ def sample_delete_exclusion(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_exclusion] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3666,13 +3720,15 @@ def sample_get_cmek_settings(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_cmek_settings] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3777,13 +3833,15 @@ def sample_update_cmek_settings(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_cmek_settings] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -3911,13 +3969,15 @@ def sample_get_settings(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_settings] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -4055,13 +4115,15 @@ def sample_update_settings(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_settings] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -4147,6 +4209,8 @@ def sample_copy_log_entries(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.copy_log_entries] + metadata = tuple(metadata) + # Validate the universe domain. self._validate_universe_domain() @@ -4219,12 +4283,15 @@ def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -4273,12 +4340,15 @@ def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -4330,12 +4400,15 @@ def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py index 5695fcf328..6d2910321a 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py @@ -314,13 +314,15 @@ async def sample_delete_log(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_log] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("log_name", request.log_name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("log_name", request.log_name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -860,13 +862,15 @@ async def sample_list_logs(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_logs] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1010,12 +1014,15 @@ async def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1064,12 +1071,15 @@ async def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1121,12 +1131,15 @@ async def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py index d53bce9464..e1cee0aa49 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py @@ -654,13 +654,15 @@ def sample_delete_log(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_log] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("log_name", request.log_name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("log_name", request.log_name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -847,6 +849,8 @@ def sample_write_log_entries(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.write_log_entries] + metadata = tuple(metadata) + # Validate the universe domain. self._validate_universe_domain() @@ -992,6 +996,8 @@ def sample_list_log_entries(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_log_entries] + metadata = tuple(metadata) + # Validate the universe domain. self._validate_universe_domain() @@ -1082,6 +1088,8 @@ def sample_list_monitored_resource_descriptors(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_monitored_resource_descriptors] + metadata = tuple(metadata) + # Validate the universe domain. self._validate_universe_domain() @@ -1196,13 +1204,15 @@ def sample_list_logs(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_logs] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1295,6 +1305,8 @@ def request_generator(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.tail_log_entries] + metadata = tuple(metadata) + # Validate the universe domain. self._validate_universe_domain() @@ -1359,12 +1371,15 @@ def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1413,12 +1428,15 @@ def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1470,12 +1488,15 @@ def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py index 0f8961a508..dd494d50e4 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py @@ -317,13 +317,15 @@ async def sample_list_log_metrics(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_log_metrics] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -443,13 +445,15 @@ async def sample_get_log_metric(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_log_metric] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("metric_name", request.metric_name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("metric_name", request.metric_name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -577,13 +581,15 @@ async def sample_create_log_metric(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_log_metric] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -710,13 +716,15 @@ async def sample_update_log_metric(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_log_metric] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("metric_name", request.metric_name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("metric_name", request.metric_name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -806,13 +814,15 @@ async def sample_delete_log_metric(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_log_metric] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("metric_name", request.metric_name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("metric_name", request.metric_name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -862,12 +872,15 @@ async def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -916,12 +929,15 @@ async def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -973,12 +989,15 @@ async def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py index 639b5b2397..fed5799371 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py @@ -657,13 +657,15 @@ def sample_list_log_metrics(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_log_metrics] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -782,13 +784,15 @@ def sample_get_log_metric(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_log_metric] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("metric_name", request.metric_name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("metric_name", request.metric_name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -915,13 +919,15 @@ def sample_create_log_metric(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_log_metric] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1047,13 +1053,15 @@ def sample_update_log_metric(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_log_metric] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("metric_name", request.metric_name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("metric_name", request.metric_name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1142,13 +1150,15 @@ def sample_delete_log_metric(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_log_metric] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("metric_name", request.metric_name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("metric_name", request.metric_name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1211,12 +1221,15 @@ def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1265,12 +1278,15 @@ def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1322,12 +1338,15 @@ def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py index f8cd2f5efc..f87c314574 100755 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -954,6 +954,65 @@ async def test_list_buckets_async_from_dict(): await test_list_buckets_async(request_type=dict) +def test_list_buckets_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListBucketsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_buckets), + '__call__') as call: + call.return_value = logging_config.ListBucketsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_buckets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_buckets_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListBucketsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_buckets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.ListBucketsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_buckets(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_buckets_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1530,6 +1589,65 @@ async def test_get_bucket_async_from_dict(): await test_get_bucket_async(request_type=dict) +def test_get_bucket_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_bucket), + '__call__') as call: + call.return_value = logging_config.LogBucket() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_bucket(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_bucket_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_bucket), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogBucket()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_bucket(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_bucket_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1804,6 +1922,65 @@ async def test_create_bucket_async_async_from_dict(): await test_create_bucket_async_async(request_type=dict) +def test_create_bucket_async_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_bucket_async), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_bucket_async(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_bucket_async_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_bucket_async), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_bucket_async(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_bucket_async_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2076,6 +2253,65 @@ async def test_update_bucket_async_async_from_dict(): await test_update_bucket_async_async(request_type=dict) +def test_update_bucket_async_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_bucket_async), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_bucket_async(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_bucket_async_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_bucket_async), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_bucket_async(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_bucket_async_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2376,6 +2612,65 @@ async def test_create_bucket_async_from_dict(): await test_create_bucket_async(request_type=dict) +def test_create_bucket_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_bucket), + '__call__') as call: + call.return_value = logging_config.LogBucket() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_bucket(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_bucket_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_bucket), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogBucket()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_bucket(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_bucket_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2674,6 +2969,65 @@ async def test_update_bucket_async_from_dict(): await test_update_bucket_async(request_type=dict) +def test_update_bucket_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_bucket), + '__call__') as call: + call.return_value = logging_config.LogBucket() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_bucket(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_bucket_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_bucket), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogBucket()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_bucket(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_bucket_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2934,7 +3288,7 @@ async def test_delete_bucket_async_from_dict(): await test_delete_bucket_async(request_type=dict) -def test_delete_bucket_field_headers(): +def test_delete_bucket_routing_header_override(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2943,30 +3297,89 @@ def test_delete_bucket_field_headers(): # a field header. Set these to a non-empty value. request = logging_config.DeleteBucketRequest() - request.name = 'name_value' - # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.delete_bucket), '__call__') as call: call.return_value = None - client.delete_bucket(request) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_bucket(request, metadata=override) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val @pytest.mark.asyncio -async def test_delete_bucket_field_headers_async(): +async def test_delete_bucket_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_bucket), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_bucket(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + +def test_delete_bucket_field_headers(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteBucketRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_bucket), + '__call__') as call: + call.return_value = None + client.delete_bucket(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_delete_bucket_field_headers_async(): client = ConfigServiceV2AsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3194,6 +3607,65 @@ async def test_undelete_bucket_async_from_dict(): await test_undelete_bucket_async(request_type=dict) +def test_undelete_bucket_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UndeleteBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.undelete_bucket), + '__call__') as call: + call.return_value = None + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.undelete_bucket(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_undelete_bucket_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UndeleteBucketRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.undelete_bucket), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.undelete_bucket(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_undelete_bucket_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -3464,6 +3936,65 @@ async def test_list_views_async_from_dict(): await test_list_views_async(request_type=dict) +def test_list_views_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListViewsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_views), + '__call__') as call: + call.return_value = logging_config.ListViewsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_views(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_views_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListViewsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_views), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.ListViewsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_views(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_views_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4020,6 +4551,65 @@ async def test_get_view_async_from_dict(): await test_get_view_async(request_type=dict) +def test_get_view_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetViewRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_view), + '__call__') as call: + call.return_value = logging_config.LogView() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_view(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_view_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetViewRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_view), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogView()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_view(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_view_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4300,6 +4890,65 @@ async def test_create_view_async_from_dict(): await test_create_view_async(request_type=dict) +def test_create_view_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateViewRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_view), + '__call__') as call: + call.return_value = logging_config.LogView() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_view(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_view_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateViewRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_view), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogView()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_view(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_view_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4578,6 +5227,65 @@ async def test_update_view_async_from_dict(): await test_update_view_async(request_type=dict) +def test_update_view_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateViewRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_view), + '__call__') as call: + call.return_value = logging_config.LogView() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_view(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_view_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateViewRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_view), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogView()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_view(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_view_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4838,6 +5546,65 @@ async def test_delete_view_async_from_dict(): await test_delete_view_async(request_type=dict) +def test_delete_view_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteViewRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_view), + '__call__') as call: + call.return_value = None + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_view(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_view_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteViewRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_view), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_view(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_view_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -5093,20 +5860,79 @@ async def test_list_sinks_async(transport: str = 'grpc_asyncio', request_type=lo response = await client.list_sinks(request) # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - request = logging_config.ListSinksRequest() + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = logging_config.ListSinksRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSinksAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_sinks_async_from_dict(): + await test_list_sinks_async(request_type=dict) + + +def test_list_sinks_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListSinksRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sinks), + '__call__') as call: + call.return_value = logging_config.ListSinksResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_sinks(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_sinks_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListSinksRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sinks), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.ListSinksResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_sinks(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args assert args[0] == request - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSinksAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_sinks_async_from_dict(): - await test_list_sinks_async(request_type=dict) - + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val def test_list_sinks_field_headers(): client = ConfigServiceV2Client( @@ -5689,6 +6515,65 @@ async def test_get_sink_async_from_dict(): await test_get_sink_async(request_type=dict) +def test_get_sink_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetSinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_sink), + '__call__') as call: + call.return_value = logging_config.LogSink() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_sink(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_sink_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetSinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_sink), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogSink()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_sink(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_sink_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -6074,6 +6959,65 @@ async def test_create_sink_async_from_dict(): await test_create_sink_async(request_type=dict) +def test_create_sink_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateSinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_sink), + '__call__') as call: + call.return_value = logging_config.LogSink() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_sink(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_sink_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateSinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_sink), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogSink()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_sink(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_sink_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -6469,6 +7413,65 @@ async def test_update_sink_async_from_dict(): await test_update_sink_async(request_type=dict) +def test_update_sink_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateSinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_sink), + '__call__') as call: + call.return_value = logging_config.LogSink() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_sink(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_sink_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateSinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_sink), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogSink()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_sink(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_sink_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -6831,6 +7834,65 @@ async def test_delete_sink_async_from_dict(): await test_delete_sink_async(request_type=dict) +def test_delete_sink_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteSinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_sink), + '__call__') as call: + call.return_value = None + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_sink(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_sink_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteSinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_sink), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_sink(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_sink_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -7187,6 +8249,65 @@ async def test_create_link_async_from_dict(): await test_create_link_async(request_type=dict) +def test_create_link_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateLinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_link), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_link(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_link_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateLinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_link), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_link(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_link_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -7554,14 +8675,73 @@ async def test_delete_link_async(transport: str = 'grpc_asyncio', request_type=l request = logging_config.DeleteLinkRequest() assert args[0] == request - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_link_async_from_dict(): + await test_delete_link_async(request_type=dict) + + +def test_delete_link_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteLinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_link), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_link(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_link_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteLinkRequest() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_link), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_link(request, metadata=override) -@pytest.mark.asyncio -async def test_delete_link_async_from_dict(): - await test_delete_link_async(request_type=dict) + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val def test_delete_link_field_headers(): client = ConfigServiceV2Client( @@ -7917,6 +9097,65 @@ async def test_list_links_async_from_dict(): await test_list_links_async(request_type=dict) +def test_list_links_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListLinksRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_links), + '__call__') as call: + call.return_value = logging_config.ListLinksResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_links(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_links_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListLinksRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_links), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.ListLinksResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_links(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_links_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -8473,6 +9712,65 @@ async def test_get_link_async_from_dict(): await test_get_link_async(request_type=dict) +def test_get_link_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetLinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_link), + '__call__') as call: + call.return_value = logging_config.Link() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_link(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_link_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetLinkRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_link), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.Link()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_link(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_link_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -8825,6 +10123,65 @@ async def test_list_exclusions_async_from_dict(): await test_list_exclusions_async(request_type=dict) +def test_list_exclusions_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListExclusionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_exclusions), + '__call__') as call: + call.return_value = logging_config.ListExclusionsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_exclusions(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_exclusions_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.ListExclusionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_exclusions), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.ListExclusionsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_exclusions(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_exclusions_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -9386,6 +10743,65 @@ async def test_get_exclusion_async_from_dict(): await test_get_exclusion_async(request_type=dict) +def test_get_exclusion_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetExclusionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_exclusion), + '__call__') as call: + call.return_value = logging_config.LogExclusion() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_exclusion(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_exclusion_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetExclusionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_exclusion), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogExclusion()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_exclusion(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_exclusion_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -9751,6 +11167,65 @@ async def test_create_exclusion_async_from_dict(): await test_create_exclusion_async(request_type=dict) +def test_create_exclusion_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateExclusionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_exclusion), + '__call__') as call: + call.return_value = logging_config.LogExclusion() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_exclusion(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_exclusion_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CreateExclusionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_exclusion), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogExclusion()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_exclusion(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_exclusion_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -10121,10 +11596,69 @@ async def test_update_exclusion_async(transport: str = 'grpc_asyncio', request_t assert response.disabled is True -@pytest.mark.asyncio -async def test_update_exclusion_async_from_dict(): - await test_update_exclusion_async(request_type=dict) +@pytest.mark.asyncio +async def test_update_exclusion_async_from_dict(): + await test_update_exclusion_async(request_type=dict) + + +def test_update_exclusion_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateExclusionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_exclusion), + '__call__') as call: + call.return_value = logging_config.LogExclusion() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_exclusion(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_exclusion_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateExclusionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_exclusion), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.LogExclusion()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_exclusion(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val def test_update_exclusion_field_headers(): client = ConfigServiceV2Client( @@ -10488,6 +12022,65 @@ async def test_delete_exclusion_async_from_dict(): await test_delete_exclusion_async(request_type=dict) +def test_delete_exclusion_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteExclusionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_exclusion), + '__call__') as call: + call.return_value = None + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_exclusion(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_exclusion_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.DeleteExclusionRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_exclusion), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_exclusion(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_exclusion_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -10853,6 +12446,65 @@ async def test_get_cmek_settings_async_from_dict(): await test_get_cmek_settings_async(request_type=dict) +def test_get_cmek_settings_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetCmekSettingsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_cmek_settings), + '__call__') as call: + call.return_value = logging_config.CmekSettings() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_cmek_settings(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_cmek_settings_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetCmekSettingsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_cmek_settings), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.CmekSettings()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_cmek_settings(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_cmek_settings_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -11136,6 +12788,65 @@ async def test_update_cmek_settings_async_from_dict(): await test_update_cmek_settings_async(request_type=dict) +def test_update_cmek_settings_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateCmekSettingsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_cmek_settings), + '__call__') as call: + call.return_value = logging_config.CmekSettings() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_cmek_settings(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_cmek_settings_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateCmekSettingsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_cmek_settings), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.CmekSettings()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_cmek_settings(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_cmek_settings_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -11424,6 +13135,65 @@ async def test_get_settings_async_from_dict(): await test_get_settings_async(request_type=dict) +def test_get_settings_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetSettingsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_settings), + '__call__') as call: + call.return_value = logging_config.Settings() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_settings(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_settings_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.GetSettingsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_settings), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.Settings()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_settings(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_settings_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -11794,6 +13564,65 @@ async def test_update_settings_async_from_dict(): await test_update_settings_async(request_type=dict) +def test_update_settings_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateSettingsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_settings), + '__call__') as call: + call.return_value = logging_config.Settings() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_settings(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_settings_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.UpdateSettingsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_settings), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.Settings()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_settings(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_settings_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -12162,6 +13991,66 @@ async def test_copy_log_entries_async_from_dict(): await test_copy_log_entries_async(request_type=dict) +def test_copy_log_entries_routing_header_override(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CopyLogEntriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.copy_log_entries), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.copy_log_entries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_copy_log_entries_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_config.CopyLogEntriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.copy_log_entries), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.copy_log_entries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConfigServiceV2GrpcTransport( diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 7f463657f7..63b261f7b8 100755 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -946,6 +946,65 @@ async def test_delete_log_async_from_dict(): await test_delete_log_async(request_type=dict) +def test_delete_log_routing_header_override(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.DeleteLogRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_log), + '__call__') as call: + call.return_value = None + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_log(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_log_routing_header_override_async(): + client = LoggingServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.DeleteLogRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_log), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_log(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_log_field_headers(): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1291,6 +1350,66 @@ async def test_write_log_entries_async_from_dict(): await test_write_log_entries_async(request_type=dict) +def test_write_log_entries_routing_header_override(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.WriteLogEntriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_log_entries), + '__call__') as call: + call.return_value = logging.WriteLogEntriesResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.write_log_entries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_write_log_entries_routing_header_override_async(): + client = LoggingServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.WriteLogEntriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_log_entries), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging.WriteLogEntriesResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.write_log_entries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + def test_write_log_entries_flattened(): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1612,6 +1731,66 @@ async def test_list_log_entries_async_from_dict(): await test_list_log_entries_async(request_type=dict) +def test_list_log_entries_routing_header_override(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.ListLogEntriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_log_entries), + '__call__') as call: + call.return_value = logging.ListLogEntriesResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_log_entries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_log_entries_routing_header_override_async(): + client = LoggingServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.ListLogEntriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_log_entries), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging.ListLogEntriesResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_log_entries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + def test_list_log_entries_flattened(): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2110,6 +2289,66 @@ async def test_list_monitored_resource_descriptors_async_from_dict(): await test_list_monitored_resource_descriptors_async(request_type=dict) +def test_list_monitored_resource_descriptors_routing_header_override(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.ListMonitoredResourceDescriptorsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_monitored_resource_descriptors), + '__call__') as call: + call.return_value = logging.ListMonitoredResourceDescriptorsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_monitored_resource_descriptors(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_monitored_resource_descriptors_routing_header_override_async(): + client = LoggingServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.ListMonitoredResourceDescriptorsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_monitored_resource_descriptors), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging.ListMonitoredResourceDescriptorsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_monitored_resource_descriptors(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + def test_list_monitored_resource_descriptors_pager(transport_name: str = "grpc"): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2513,6 +2752,65 @@ async def test_list_logs_async_from_dict(): await test_list_logs_async(request_type=dict) +def test_list_logs_routing_header_override(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.ListLogsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_logs), + '__call__') as call: + call.return_value = logging.ListLogsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_logs(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_logs_routing_header_override_async(): + client = LoggingServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.ListLogsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_logs), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging.ListLogsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_logs(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_logs_field_headers(): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2989,6 +3287,67 @@ async def test_tail_log_entries_async_from_dict(): await test_tail_log_entries_async(request_type=dict) +def test_tail_log_entries_routing_header_override(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.TailLogEntriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.tail_log_entries), + '__call__') as call: + call.return_value = iter([logging.TailLogEntriesResponse()]) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.tail_log_entries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_tail_log_entries_routing_header_override_async(): + client = LoggingServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging.TailLogEntriesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.tail_log_entries), + '__call__') as call: + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock(side_effect=[logging.TailLogEntriesResponse()]) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.tail_log_entries(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.LoggingServiceV2GrpcTransport( diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index f144f87294..46f8e8d1cc 100755 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -954,6 +954,65 @@ async def test_list_log_metrics_async_from_dict(): await test_list_log_metrics_async(request_type=dict) +def test_list_log_metrics_routing_header_override(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.ListLogMetricsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_log_metrics), + '__call__') as call: + call.return_value = logging_metrics.ListLogMetricsResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_log_metrics(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_log_metrics_routing_header_override_async(): + client = MetricsServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.ListLogMetricsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_log_metrics), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_metrics.ListLogMetricsResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_log_metrics(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_log_metrics_field_headers(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1530,6 +1589,65 @@ async def test_get_log_metric_async_from_dict(): await test_get_log_metric_async(request_type=dict) +def test_get_log_metric_routing_header_override(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.GetLogMetricRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_log_metric), + '__call__') as call: + call.return_value = logging_metrics.LogMetric() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_log_metric(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_log_metric_routing_header_override_async(): + client = MetricsServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.GetLogMetricRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_log_metric), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_metrics.LogMetric()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_log_metric(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_log_metric_field_headers(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1910,6 +2028,65 @@ async def test_create_log_metric_async_from_dict(): await test_create_log_metric_async(request_type=dict) +def test_create_log_metric_routing_header_override(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.CreateLogMetricRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_log_metric), + '__call__') as call: + call.return_value = logging_metrics.LogMetric() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_log_metric(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_log_metric_routing_header_override_async(): + client = MetricsServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.CreateLogMetricRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_log_metric), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_metrics.LogMetric()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_log_metric(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_log_metric_field_headers(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2300,6 +2477,65 @@ async def test_update_log_metric_async_from_dict(): await test_update_log_metric_async(request_type=dict) +def test_update_log_metric_routing_header_override(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.UpdateLogMetricRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_log_metric), + '__call__') as call: + call.return_value = logging_metrics.LogMetric() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_log_metric(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_log_metric_routing_header_override_async(): + client = MetricsServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.UpdateLogMetricRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_log_metric), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_metrics.LogMetric()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_log_metric(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_log_metric_field_headers(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2652,6 +2888,65 @@ async def test_delete_log_metric_async_from_dict(): await test_delete_log_metric_async(request_type=dict) +def test_delete_log_metric_routing_header_override(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.DeleteLogMetricRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_log_metric), + '__call__') as call: + call.return_value = None + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_log_metric(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_log_metric_routing_header_override_async(): + client = MetricsServiceV2AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = logging_metrics.DeleteLogMetricRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_log_metric), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_log_metric(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_log_metric_field_headers(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py index ae9eea6c54..5abdb4fb71 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -352,13 +352,15 @@ async def sample_list_instances(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.list_instances] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -465,13 +467,15 @@ async def sample_get_instance(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -570,13 +574,15 @@ async def sample_get_instance_auth_string(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.get_instance_auth_string] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -727,13 +733,15 @@ async def sample_create_instance(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.create_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -873,13 +881,15 @@ async def sample_update_instance(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.update_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("instance.name", request.instance.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("instance.name", request.instance.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1004,13 +1014,15 @@ async def sample_upgrade_instance(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.upgrade_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1145,13 +1157,15 @@ async def sample_import_instance(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.import_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1283,13 +1297,15 @@ async def sample_export_instance(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.export_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1415,13 +1431,15 @@ async def sample_failover_instance(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.failover_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1542,13 +1560,15 @@ async def sample_delete_instance(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.delete_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1684,13 +1704,15 @@ async def sample_reschedule_maintenance(): # and friendly error handling. rpc = self._client._transport._wrapped_methods[self._client._transport.reschedule_maintenance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1751,12 +1773,15 @@ async def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1805,12 +1830,15 @@ async def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1863,12 +1891,15 @@ async def delete_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1916,12 +1947,15 @@ async def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -1966,12 +2000,15 @@ async def get_location( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() @@ -2020,12 +2057,15 @@ async def list_locations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name),) + ) + ) # Validate the universe domain. self._client._validate_universe_domain() diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py index 31b300b5b3..2392a7e070 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py @@ -694,13 +694,15 @@ def sample_list_instances(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_instances] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -806,13 +808,15 @@ def sample_get_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -910,13 +914,15 @@ def sample_get_instance_auth_string(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_instance_auth_string] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1066,13 +1072,15 @@ def sample_create_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1211,13 +1219,15 @@ def sample_update_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("instance.name", request.instance.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("instance.name", request.instance.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1341,13 +1351,15 @@ def sample_upgrade_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.upgrade_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1481,13 +1493,15 @@ def sample_import_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.import_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1618,13 +1632,15 @@ def sample_export_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.export_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1749,13 +1765,15 @@ def sample_failover_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.failover_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -1875,13 +1893,15 @@ def sample_delete_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_instance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2016,13 +2036,15 @@ def sample_reschedule_maintenance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.reschedule_maintenance] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) + metadata = tuple(metadata) + # Attach routing header to metadata if not already present + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2096,12 +2118,15 @@ def list_operations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2150,12 +2175,15 @@ def get_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2208,12 +2236,15 @@ def delete_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2261,12 +2292,15 @@ def cancel_operation( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2311,12 +2345,15 @@ def get_location( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() @@ -2365,12 +2402,15 @@ def list_locations( client_info=DEFAULT_CLIENT_INFO, ) - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) + # Attach routing header to metadata if not already present + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata(( + (("name", request.name),) + )) + ) # Validate the universe domain. self._validate_universe_domain() diff --git a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index 224d961e43..bbdefd2f96 100755 --- a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -983,6 +983,65 @@ async def test_list_instances_async_from_dict(): await test_list_instances_async(request_type=dict) +def test_list_instances_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.ListInstancesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + call.return_value = cloud_redis.ListInstancesResponse() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.list_instances(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_list_instances_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.ListInstancesRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(cloud_redis.ListInstancesResponse()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.list_instances(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_list_instances_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1659,6 +1718,65 @@ async def test_get_instance_async_from_dict(): await test_get_instance_async(request_type=dict) +def test_get_instance_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.GetInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance), + '__call__') as call: + call.return_value = cloud_redis.Instance() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_instance_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.GetInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(cloud_redis.Instance()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2009,6 +2127,65 @@ async def test_get_instance_auth_string_async_from_dict(): await test_get_instance_auth_string_async(request_type=dict) +def test_get_instance_auth_string_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.GetInstanceAuthStringRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_auth_string), + '__call__') as call: + call.return_value = cloud_redis.InstanceAuthString() + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.get_instance_auth_string(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_get_instance_auth_string_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.GetInstanceAuthStringRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_auth_string), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(cloud_redis.InstanceAuthString()) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.get_instance_auth_string(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_get_instance_auth_string_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2365,6 +2542,65 @@ async def test_create_instance_async_from_dict(): await test_create_instance_async(request_type=dict) +def test_create_instance_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.CreateInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.create_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_create_instance_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.CreateInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.create_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_create_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2739,6 +2975,65 @@ async def test_update_instance_async_from_dict(): await test_update_instance_async(request_type=dict) +def test_update_instance_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.UpdateInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.update_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_update_instance_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.UpdateInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.update_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_update_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3107,6 +3402,65 @@ async def test_upgrade_instance_async_from_dict(): await test_upgrade_instance_async(request_type=dict) +def test_upgrade_instance_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.UpgradeInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.upgrade_instance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.upgrade_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_upgrade_instance_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.UpgradeInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.upgrade_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.upgrade_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_upgrade_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3473,6 +3827,65 @@ async def test_import_instance_async_from_dict(): await test_import_instance_async(request_type=dict) +def test_import_instance_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.ImportInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_instance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.import_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_import_instance_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.ImportInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.import_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_import_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3839,6 +4252,65 @@ async def test_export_instance_async_from_dict(): await test_export_instance_async(request_type=dict) +def test_export_instance_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.ExportInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_instance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.export_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_export_instance_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.ExportInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.export_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_export_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4205,6 +4677,65 @@ async def test_failover_instance_async_from_dict(): await test_failover_instance_async(request_type=dict) +def test_failover_instance_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.FailoverInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.failover_instance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.failover_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_failover_instance_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.FailoverInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.failover_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.failover_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_failover_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4571,6 +5102,65 @@ async def test_delete_instance_async_from_dict(): await test_delete_instance_async(request_type=dict) +def test_delete_instance_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.DeleteInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.delete_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_delete_instance_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.DeleteInstanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.delete_instance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_delete_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4927,6 +5517,65 @@ async def test_reschedule_maintenance_async_from_dict(): await test_reschedule_maintenance_async(request_type=dict) +def test_reschedule_maintenance_routing_header_override(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.RescheduleMaintenanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reschedule_maintenance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + client.reschedule_maintenance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + _, _, kw = call.mock_calls[0] + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + + +@pytest.mark.asyncio +async def test_reschedule_maintenance_routing_header_override_async(): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.RescheduleMaintenanceRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reschedule_maintenance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + custom_val = "key=custom" + override = [('x-goog-request-params', custom_val)] + await client.reschedule_maintenance(request, metadata=override) + + # Establish that the underlying gRPC stub method was called. + assert call.call_count == 1 + args, kw = call.call_args + assert args[0] == request + + # enure there is just one x-goog-request-params header + assert len([x for x in kw["metadata"] if x[0] == "x-goog-request-params"]) == 1 + # ensure that the custom header is the only one + assert [x for x in kw["metadata"] if x[0] == "x-goog-request-params"][0][1] == custom_val + def test_reschedule_maintenance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(),