From fd898249fd67c5af69d027f081389fb764a58f6f Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 26 Jul 2024 15:16:38 -0700 Subject: [PATCH 01/15] chore: allow custom routing header metadata --- .../%name_%version/%sub/services/%service/async_client.py.j2 | 5 +++-- .../%name_%version/%sub/services/%service/client.py.j2 | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) 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 b63cb1e99f..fd91125f71 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 @@ -368,8 +368,9 @@ class {{ service.async_client_name }}: {% 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(( + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in 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 }}), 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..85b217c9a0 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 @@ -698,8 +698,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # Certain fields should be provided within the metadata header; # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( + metadata = tuple(metadata) + if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): + metadata += gapic_v1.routing_header.to_grpc_metadata( (("resource", request.resource),)), ) From aa946fdf1d68975608c7d451f346b0342bf416e2 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 26 Jul 2024 17:40:00 -0700 Subject: [PATCH 02/15] fixed format --- .../%name_%version/%sub/services/%service/async_client.py.j2 | 3 +-- .../%name_%version/%sub/services/%service/client.py.j2 | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) 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 fd91125f71..a86fa0c670 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 @@ -376,8 +376,7 @@ class {{ service.async_client_name }}: ("{{ field_header.raw }}", request.{{ field_header.disambiguated }}), {% endif %} {% endfor %} - )), - ) + )) {% endif %} {{ shared_macros.add_api_version_header_to_metadata(service.version) }} 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 85b217c9a0..7fda3748ca 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 @@ -702,7 +702,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): metadata += gapic_v1.routing_header.to_grpc_metadata( (("resource", request.resource),)), - ) + ) # Validate the universe domain. self._validate_universe_domain() From cdf2508f0ecb929039208a196b4be60ab5847a3e Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 26 Jul 2024 17:56:59 -0700 Subject: [PATCH 03/15] fix tuple output --- .../%sub/services/%service/async_client.py.j2 | 17 ++++++++++------- .../%sub/services/%service/client.py.j2 | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-) 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 a86fa0c670..4971f8e5d9 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 @@ -370,13 +370,16 @@ class {{ service.async_client_name }}: # add these here. metadata = tuple(metadata) if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in 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 %} - )) + 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) }} 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 7fda3748ca..f34d86a757 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 @@ -700,8 +700,11 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # add these here. metadata = tuple(metadata) if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): - metadata += gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + metadata = ( + *metadata, + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request.resource),) + ) ) # Validate the universe domain. From b67603f305af4e4cbde7a83cd43ef900eb090539 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 26 Jul 2024 19:03:07 -0700 Subject: [PATCH 04/15] updated goldens --- .../services/asset_service/async_client.py | 299 ++++++++----- .../services/iam_credentials/async_client.py | 52 ++- .../services/eventarc/async_client.py | 234 ++++++---- .../config_service_v2/async_client.py | 403 +++++++++++------- .../logging_service_v2/async_client.py | 26 +- .../metrics_service_v2/async_client.py | 65 +-- .../services/cloud_redis/async_client.py | 143 ++++--- 7 files changed, 752 insertions(+), 470 deletions(-) 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..5da9300bdd 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 @@ -335,11 +335,14 @@ async def sample_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) + 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() @@ -455,11 +458,14 @@ async def sample_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) + 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() @@ -552,11 +558,14 @@ async def sample_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) + 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() @@ -674,11 +683,14 @@ async def sample_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) + 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() @@ -784,11 +796,14 @@ async def sample_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) + 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() @@ -889,11 +904,14 @@ async def sample_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) + 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() @@ -1003,11 +1021,14 @@ async def sample_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) + 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() @@ -1098,11 +1119,14 @@ async def sample_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) + 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() @@ -1314,11 +1338,14 @@ async def sample_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) + 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() @@ -1505,11 +1532,14 @@ async def sample_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) + 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() @@ -1603,11 +1633,14 @@ async def sample_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) + 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() @@ -1710,11 +1743,14 @@ async def sample_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) + 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() @@ -1808,11 +1844,14 @@ async def sample_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) + 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() @@ -1904,11 +1943,14 @@ async def sample_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) + 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() @@ -2041,11 +2083,14 @@ async def sample_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) + 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() @@ -2147,11 +2192,14 @@ async def sample_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) + 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() @@ -2259,11 +2307,14 @@ async def sample_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) + 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() @@ -2387,11 +2438,14 @@ async def sample_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) + 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() @@ -2484,11 +2538,14 @@ async def sample_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) + 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() @@ -2565,11 +2622,14 @@ async def sample_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) + 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() @@ -2706,11 +2766,14 @@ async def sample_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) + 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() @@ -2858,11 +2921,14 @@ async def sample_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) + 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() @@ -3039,11 +3105,14 @@ async def sample_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) + 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() 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..0624b30b19 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 @@ -374,11 +374,14 @@ async def sample_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) + 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() @@ -523,11 +526,14 @@ async def sample_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) + 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() @@ -658,11 +664,14 @@ async def sample_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) + 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() @@ -796,11 +805,14 @@ async def sample_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) + 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/async_client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py index cdf056c7a0..3323606af9 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 @@ -349,11 +349,14 @@ async def sample_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) + 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() @@ -455,11 +458,14 @@ async def sample_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) + 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() @@ -605,11 +611,14 @@ async def sample_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) + 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() @@ -744,11 +753,14 @@ async def sample_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) + 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() @@ -874,11 +886,14 @@ async def sample_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) + 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() @@ -991,11 +1006,14 @@ async def sample_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) + 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() @@ -1097,11 +1115,14 @@ async def sample_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) + 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() @@ -1247,11 +1268,14 @@ async def sample_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) + 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() @@ -1378,11 +1402,14 @@ async def sample_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) + 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() @@ -1500,11 +1527,14 @@ async def sample_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) + 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() @@ -1611,11 +1641,14 @@ async def sample_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) + 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() @@ -1717,11 +1750,14 @@ async def sample_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) + 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() @@ -1836,11 +1872,14 @@ async def sample_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) + 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() @@ -1943,11 +1982,14 @@ async def sample_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) + 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() @@ -2093,11 +2135,14 @@ async def sample_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) + 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() @@ -2213,11 +2258,14 @@ async def sample_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) + 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() @@ -2330,11 +2378,14 @@ async def sample_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) + 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() @@ -2452,11 +2503,14 @@ async def sample_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) + 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() 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..b6bc9b9a1b 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 @@ -340,11 +340,14 @@ async def sample_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) + 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() @@ -433,11 +436,14 @@ async def sample_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) + 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() @@ -526,11 +532,14 @@ async def sample_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) + 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() @@ -629,11 +638,14 @@ async def sample_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) + 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() @@ -722,11 +734,14 @@ async def sample_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) + 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() @@ -810,11 +825,14 @@ async def sample_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) + 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() @@ -888,11 +906,14 @@ async def sample_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) + 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() @@ -960,11 +981,14 @@ async def sample_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) + 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() @@ -1066,11 +1090,14 @@ async def sample_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) + 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() @@ -1159,11 +1186,14 @@ async def sample_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) + 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() @@ -1243,11 +1273,14 @@ async def sample_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) + 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() @@ -1329,11 +1362,14 @@ async def sample_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) + 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() @@ -1405,11 +1441,14 @@ async def sample_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) + 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() @@ -1514,11 +1553,14 @@ async def sample_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) + 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() @@ -1644,11 +1686,14 @@ async def sample_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) + 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() @@ -1782,11 +1827,14 @@ async def sample_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) + 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() @@ -1947,11 +1995,14 @@ async def sample_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) + 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() @@ -2052,11 +2103,14 @@ async def sample_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) + 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() @@ -2188,11 +2242,14 @@ async def sample_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) + 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() @@ -2317,11 +2374,14 @@ async def sample_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) + 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() @@ -2436,11 +2496,14 @@ async def sample_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) + 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() @@ -2553,11 +2616,14 @@ async def sample_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) + 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() @@ -2666,11 +2732,14 @@ async def sample_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) + 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() @@ -2794,11 +2863,14 @@ async def sample_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) + 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() @@ -2931,11 +3003,14 @@ async def sample_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) + 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() @@ -3082,11 +3157,14 @@ async def sample_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) + 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() @@ -3186,11 +3264,14 @@ async def sample_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) + 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() @@ -3289,11 +3370,14 @@ async def sample_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) + 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() @@ -3400,11 +3484,14 @@ async def sample_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) + 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() @@ -3535,11 +3622,14 @@ async def sample_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) + 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() @@ -3680,11 +3770,14 @@ async def sample_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) + 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/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py index 5695fcf328..d0ce6791e5 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 @@ -316,11 +316,14 @@ async def sample_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) + 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() @@ -862,11 +865,14 @@ async def sample_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) + 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() 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..9eb42fd545 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 @@ -319,11 +319,14 @@ async def sample_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) + 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() @@ -445,11 +448,14 @@ async def sample_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) + 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() @@ -579,11 +585,14 @@ async def sample_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) + 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() @@ -712,11 +721,14 @@ async def sample_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) + 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() @@ -808,11 +820,14 @@ async def sample_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) + 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() 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..472f3012da 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 @@ -354,11 +354,14 @@ async def sample_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) + 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() @@ -467,11 +470,14 @@ async def sample_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) + 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() @@ -572,11 +578,14 @@ async def sample_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) + 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() @@ -729,11 +738,14 @@ async def sample_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) + 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() @@ -875,11 +887,14 @@ async def sample_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) + 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() @@ -1006,11 +1021,14 @@ async def sample_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) + 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() @@ -1147,11 +1165,14 @@ async def sample_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) + 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() @@ -1285,11 +1306,14 @@ async def sample_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) + 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() @@ -1417,11 +1441,14 @@ async def sample_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) + 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() @@ -1544,11 +1571,14 @@ async def sample_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) + 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() @@ -1686,11 +1716,14 @@ async def sample_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) + 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() From b99f318145f6ca9577d9f02deb2bdbfbf722b947 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 26 Jul 2024 19:26:31 -0700 Subject: [PATCH 05/15] added test --- .../gapic/%name_%version/%sub/test_macros.j2 | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) 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..893043bb3e 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,44 @@ def test_{{ method.name|snake_case }}_routing_parameters(): {% endfor %} {% endif %} +{% if method.field_headers %} +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=overrride) + + # 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 +{% endif %} {% if method.field_headers and not method.client_streaming and not method.explicit_routing %} def test_{{ method_name }}_field_headers(): From 9d1229c843ea7b30cc1f622f1ce56bedc70b8934 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 26 Jul 2024 19:30:55 -0700 Subject: [PATCH 06/15] fixed typo --- .../tests/unit/gapic/%name_%version/%sub/test_macros.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 893043bb3e..0b2e08eec8 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 @@ -535,7 +535,7 @@ def test_{{ method.name|snake_case }}_routing_header_override(): {% endif %} custom_val = "key=custom" override = [('x-goog-request-params', custom_val)] - client.{{ method.safe_name|snake_case }}(request, metadata=overrride) + client.{{ method.safe_name|snake_case }}(request, metadata=override) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 From c95f9d1214ca9e979161bf07a340a79e33b74fd4 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 30 Jul 2024 15:11:23 -0700 Subject: [PATCH 07/15] update all instances --- .../services/%service/_async_mixins.py.j2 | 150 +++++++++++------- .../%sub/services/%service/_client_macros.j2 | 24 +-- .../%sub/services/%service/_mixins.py.j2 | 150 +++++++++++------- .../%sub/services/%service/async_client.py.j2 | 45 ++++-- .../%sub/services/%service/client.py.j2 | 36 +++-- 5 files changed, 242 insertions(+), 163 deletions(-) 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..70e05ee5f1 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 @@ -170,17 +170,19 @@ ) {% 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 %} - )), - ) + # 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 %} {# 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 55ca000600..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,8 +366,7 @@ 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. + # 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 = ( @@ -536,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() @@ -655,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() @@ -712,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 f34d86a757..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,8 +696,7 @@ 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. + # 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 = ( @@ -821,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() @@ -880,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() From f076d02f873bc3a6a7cb3e2b3ee835f6c30c3c75 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 30 Jul 2024 16:11:14 -0700 Subject: [PATCH 08/15] updated goldens --- .../services/asset_service/async_client.py | 84 +- .../asset_v1/services/asset_service/client.py | 383 ++++---- .../unit/gapic/asset_v1/test_asset_service.py | 667 +++++++++++++ .../services/iam_credentials/async_client.py | 12 +- .../services/iam_credentials/client.py | 64 +- .../credentials_v1/test_iam_credentials.py | 116 +++ .../services/eventarc/async_client.py | 189 ++-- .../eventarc_v1/services/eventarc/client.py | 423 ++++---- .../unit/gapic/eventarc_v1/test_eventarc.py | 522 ++++++++++ .../config_service_v2/async_client.py | 138 ++- .../services/config_service_v2/client.py | 541 ++++++----- .../logging_service_v2/async_client.py | 51 +- .../services/logging_service_v2/client.py | 77 +- .../metrics_service_v2/async_client.py | 60 +- .../services/metrics_service_v2/client.py | 125 +-- .../logging_v2/test_config_service_v2.py | 899 ++++++++++++++++++ .../logging_v2/test_logging_service_v2.py | 58 ++ .../logging_v2/test_metrics_service_v2.py | 145 +++ .../services/cloud_redis/async_client.py | 123 +-- .../redis_v1/services/cloud_redis/client.py | 266 +++--- .../unit/gapic/redis_v1/test_cloud_redis.py | 319 +++++++ 21 files changed, 4116 insertions(+), 1146 deletions(-) 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 5da9300bdd..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,8 +333,7 @@ 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. + # 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 = ( @@ -456,8 +455,7 @@ 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. + # 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 = ( @@ -556,8 +554,7 @@ 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. + # 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 = ( @@ -681,8 +678,7 @@ 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. + # 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 = ( @@ -794,8 +790,7 @@ 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. + # 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 = ( @@ -902,8 +897,7 @@ 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. + # 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 = ( @@ -1019,8 +1013,7 @@ 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. + # 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 = ( @@ -1117,8 +1110,7 @@ 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. + # 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 = ( @@ -1336,8 +1328,7 @@ 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. + # 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 = ( @@ -1530,8 +1521,7 @@ 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. + # 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 = ( @@ -1631,8 +1621,7 @@ 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. + # 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 = ( @@ -1741,8 +1730,7 @@ 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. + # 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 = ( @@ -1842,8 +1830,7 @@ 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. + # 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 = ( @@ -1941,8 +1928,7 @@ 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. + # 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 = ( @@ -2081,8 +2067,7 @@ 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. + # 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 = ( @@ -2190,8 +2175,7 @@ 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. + # 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 = ( @@ -2305,8 +2289,7 @@ 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. + # 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 = ( @@ -2436,8 +2419,7 @@ 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. + # 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 = ( @@ -2536,8 +2518,7 @@ 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. + # 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 = ( @@ -2620,8 +2601,7 @@ 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. + # 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 = ( @@ -2764,8 +2744,7 @@ 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. + # 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 = ( @@ -2919,8 +2898,7 @@ 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. + # 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 = ( @@ -3103,8 +3081,7 @@ 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. + # 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 = ( @@ -3176,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..82af1e5848 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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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..57d8d061b3 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,35 @@ 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 + def test_export_assets_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1249,6 +1278,35 @@ 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 + def test_list_assets_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1790,6 +1848,35 @@ 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 + def test_batch_get_assets_history_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2080,6 +2167,35 @@ 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 + def test_create_feed_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2450,6 +2566,35 @@ 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 + def test_get_feed_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2795,6 +2940,35 @@ 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 + def test_list_feeds_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3163,6 +3337,35 @@ async def test_update_feed_async_from_dict(): await test_update_feed_async(request_type=dict) +def test_update_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.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 = asset_service.Feed() + 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 + + _, _, 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 + def test_update_feed_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3505,6 +3708,35 @@ 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 + def test_delete_feed_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3861,6 +4093,35 @@ 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 + def test_search_all_resources_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4433,6 +4694,35 @@ 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 + def test_search_all_iam_policies_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4989,6 +5279,35 @@ 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 + def test_analyze_iam_policy_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5261,6 +5580,35 @@ 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 + def test_analyze_iam_policy_longrunning_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5526,6 +5874,35 @@ 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 + def test_analyze_move_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5805,6 +6182,35 @@ 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 + def test_query_assets_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6090,6 +6496,35 @@ 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 + def test_create_saved_query_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6475,6 +6910,35 @@ 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 + def test_get_saved_query_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6829,6 +7293,35 @@ 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 + def test_list_saved_queries_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7388,6 +7881,35 @@ 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 + def test_update_saved_query_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7740,6 +8262,35 @@ 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 + def test_delete_saved_query_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8085,6 +8636,35 @@ 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 + def test_batch_get_effective_iam_policies_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8359,6 +8939,35 @@ 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 + def test_analyze_org_policies_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8931,6 +9540,35 @@ 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 + def test_analyze_org_policy_governed_containers_field_headers(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9503,6 +10141,35 @@ 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 + 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 0624b30b19..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,8 +372,7 @@ 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. + # 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 = ( @@ -524,8 +523,7 @@ 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. + # 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 = ( @@ -662,8 +660,7 @@ 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. + # 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 = ( @@ -803,8 +800,7 @@ 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. + # 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 = ( 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..2e672125dd 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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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/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..e56f621120 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,35 @@ 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 + def test_generate_access_token_field_headers(): client = IAMCredentialsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1343,6 +1372,35 @@ 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 + def test_generate_id_token_field_headers(): client = IAMCredentialsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1728,6 +1786,35 @@ 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 + def test_sign_blob_field_headers(): client = IAMCredentialsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2105,6 +2192,35 @@ 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 + 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 3323606af9..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,8 +347,7 @@ 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. + # 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 = ( @@ -456,8 +455,7 @@ 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. + # 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 = ( @@ -609,8 +607,7 @@ 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. + # 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 = ( @@ -751,8 +748,7 @@ 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. + # 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 = ( @@ -884,8 +880,7 @@ 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. + # 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 = ( @@ -1004,8 +999,7 @@ 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. + # 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 = ( @@ -1113,8 +1107,7 @@ 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. + # 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 = ( @@ -1266,8 +1259,7 @@ 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. + # 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 = ( @@ -1400,8 +1392,7 @@ 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. + # 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 = ( @@ -1525,8 +1516,7 @@ 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. + # 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 = ( @@ -1639,8 +1629,7 @@ 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. + # 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 = ( @@ -1748,8 +1737,7 @@ 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. + # 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 = ( @@ -1870,8 +1858,7 @@ 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. + # 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 = ( @@ -1980,8 +1967,7 @@ 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. + # 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 = ( @@ -2133,8 +2119,7 @@ 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. + # 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 = ( @@ -2256,8 +2241,7 @@ 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. + # 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 = ( @@ -2376,8 +2360,7 @@ 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. + # 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 = ( @@ -2501,8 +2484,7 @@ 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. + # 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 = ( @@ -2563,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() @@ -2617,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() @@ -2675,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() @@ -2728,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() @@ -2844,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() @@ -2965,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() @@ -3024,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() @@ -3078,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() @@ -3132,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..304f8d206a 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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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..387cffaaf9 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,35 @@ 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 + def test_get_trigger_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1366,6 +1395,35 @@ 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 + def test_list_triggers_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1918,6 +1976,35 @@ 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 + def test_create_trigger_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2292,6 +2379,35 @@ 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 + def test_update_trigger_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2670,6 +2786,35 @@ 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 + def test_delete_trigger_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3058,6 +3203,35 @@ 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 + def test_get_channel_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3417,6 +3591,35 @@ 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 + def test_list_channels_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3969,6 +4172,35 @@ 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 + def test_create_channel_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4343,6 +4575,35 @@ 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 + def test_update_channel_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4709,6 +4970,35 @@ 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 + def test_delete_channel_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5066,6 +5356,35 @@ 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 + def test_get_provider_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5427,6 +5746,35 @@ 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 + def test_list_providers_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5988,6 +6336,35 @@ 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 + def test_get_channel_connection_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6345,6 +6722,35 @@ 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 + def test_list_channel_connections_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6897,6 +7303,35 @@ 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 + def test_create_channel_connection_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7273,6 +7708,35 @@ 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 + def test_delete_channel_connection_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7630,6 +8094,35 @@ 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 + def test_get_google_channel_config_field_headers(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7983,6 +8476,35 @@ 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 + 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 b6bc9b9a1b..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,8 +338,7 @@ 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. + # 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 = ( @@ -434,8 +433,7 @@ 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. + # 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 = ( @@ -530,8 +528,7 @@ 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. + # 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 = ( @@ -636,8 +633,7 @@ 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. + # 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 = ( @@ -732,8 +728,7 @@ 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. + # 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 = ( @@ -823,8 +818,7 @@ 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. + # 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 = ( @@ -904,8 +898,7 @@ 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. + # 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 = ( @@ -979,8 +972,7 @@ 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. + # 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 = ( @@ -1088,8 +1080,7 @@ 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. + # 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 = ( @@ -1184,8 +1175,7 @@ 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. + # 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 = ( @@ -1271,8 +1261,7 @@ 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. + # 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 = ( @@ -1360,8 +1349,7 @@ 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. + # 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 = ( @@ -1439,8 +1427,7 @@ 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. + # 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 = ( @@ -1551,8 +1538,7 @@ 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. + # 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 = ( @@ -1684,8 +1670,7 @@ 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. + # 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 = ( @@ -1825,8 +1810,7 @@ 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. + # 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 = ( @@ -1993,8 +1977,7 @@ 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. + # 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 = ( @@ -2101,8 +2084,7 @@ 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. + # 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 = ( @@ -2240,8 +2222,7 @@ 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. + # 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 = ( @@ -2372,8 +2353,7 @@ 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. + # 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 = ( @@ -2494,8 +2474,7 @@ 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. + # 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 = ( @@ -2614,8 +2593,7 @@ 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. + # 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 = ( @@ -2730,8 +2708,7 @@ 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. + # 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 = ( @@ -2861,8 +2838,7 @@ 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. + # 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 = ( @@ -3001,8 +2977,7 @@ 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. + # 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 = ( @@ -3155,8 +3130,7 @@ 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. + # 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 = ( @@ -3262,8 +3236,7 @@ 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. + # 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 = ( @@ -3368,8 +3341,7 @@ 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. + # 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 = ( @@ -3482,8 +3454,7 @@ 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. + # 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 = ( @@ -3620,8 +3591,7 @@ 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. + # 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 = ( @@ -3768,8 +3738,7 @@ 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. + # 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 = ( @@ -3922,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() @@ -3976,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() @@ -4033,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..6d2a87ff21 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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -4219,12 +4281,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 +4338,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 +4398,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 d0ce6791e5..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,8 +314,7 @@ 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. + # 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 = ( @@ -863,8 +862,7 @@ 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. + # 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 = ( @@ -1016,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() @@ -1070,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() @@ -1127,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..6868dd0273 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), - )), - ) + # 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._validate_universe_domain() @@ -1196,13 +1198,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), - )), - ) + # 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._validate_universe_domain() @@ -1359,12 +1363,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 +1420,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 +1480,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 9eb42fd545..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,8 +317,7 @@ 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. + # 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 = ( @@ -446,8 +445,7 @@ 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. + # 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 = ( @@ -583,8 +581,7 @@ 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. + # 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 = ( @@ -719,8 +716,7 @@ 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. + # 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 = ( @@ -818,8 +814,7 @@ 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. + # 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 = ( @@ -877,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() @@ -931,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() @@ -988,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..a7a791507b 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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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._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..f6fd7a734d 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,35 @@ 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 + def test_list_buckets_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1530,6 +1559,35 @@ 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 + def test_get_bucket_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1804,6 +1862,35 @@ 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 + def test_create_bucket_async_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2076,6 +2163,35 @@ 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 + def test_update_bucket_async_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2376,6 +2492,35 @@ 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 + def test_create_bucket_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2674,6 +2819,35 @@ 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 + def test_update_bucket_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2934,6 +3108,35 @@ async def test_delete_bucket_async_from_dict(): await test_delete_bucket_async(request_type=dict) +def test_delete_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.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 = None + 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 + + _, _, 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 + def test_delete_bucket_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -3194,6 +3397,35 @@ 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 + def test_undelete_bucket_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -3464,6 +3696,35 @@ 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 + def test_list_views_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4020,6 +4281,35 @@ 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 + def test_get_view_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4300,6 +4590,35 @@ 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 + def test_create_view_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4578,6 +4897,35 @@ 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 + def test_update_view_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4838,6 +5186,35 @@ 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 + def test_delete_view_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -5108,6 +5485,35 @@ 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 + def test_list_sinks_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -5689,6 +6095,35 @@ 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 + def test_get_sink_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -6074,6 +6509,35 @@ 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 + def test_create_sink_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -6469,6 +6933,35 @@ 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 + def test_update_sink_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -6831,6 +7324,35 @@ 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 + def test_delete_sink_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -7187,6 +7709,35 @@ 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 + def test_create_link_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -7563,6 +8114,35 @@ 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 + def test_delete_link_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -7917,6 +8497,35 @@ 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 + def test_list_links_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -8473,6 +9082,35 @@ 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 + def test_get_link_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -8825,6 +9463,35 @@ 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 + def test_list_exclusions_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -9386,6 +10053,35 @@ 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 + def test_get_exclusion_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -9751,6 +10447,35 @@ 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 + def test_create_exclusion_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -10126,6 +10851,35 @@ 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 + def test_update_exclusion_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -10488,6 +11242,35 @@ 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 + def test_delete_exclusion_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -10853,6 +11636,35 @@ 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 + def test_get_cmek_settings_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -11136,6 +11948,35 @@ 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 + def test_update_cmek_settings_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -11424,6 +12265,35 @@ 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 + def test_get_settings_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -11794,6 +12664,35 @@ 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 + def test_update_settings_field_headers(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), 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..7d163d49bd 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,35 @@ 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 + def test_delete_log_field_headers(): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2513,6 +2542,35 @@ 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 + def test_list_logs_field_headers(): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), 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..b186757973 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,35 @@ 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 + def test_list_log_metrics_field_headers(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1530,6 +1559,35 @@ 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 + def test_get_log_metric_field_headers(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1910,6 +1968,35 @@ 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 + def test_create_log_metric_field_headers(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2300,6 +2387,35 @@ 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 + def test_update_log_metric_field_headers(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2652,6 +2768,35 @@ 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 + 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 472f3012da..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,8 +352,7 @@ 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. + # 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 = ( @@ -468,8 +467,7 @@ 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. + # 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 = ( @@ -576,8 +574,7 @@ 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. + # 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 = ( @@ -736,8 +733,7 @@ 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. + # 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 = ( @@ -885,8 +881,7 @@ 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. + # 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 = ( @@ -1019,8 +1014,7 @@ 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. + # 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 = ( @@ -1163,8 +1157,7 @@ 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. + # 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 = ( @@ -1304,8 +1297,7 @@ 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. + # 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 = ( @@ -1439,8 +1431,7 @@ 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. + # 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 = ( @@ -1569,8 +1560,7 @@ 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. + # 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 = ( @@ -1714,8 +1704,7 @@ 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. + # 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 = ( @@ -1784,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() @@ -1838,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() @@ -1896,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() @@ -1949,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() @@ -1999,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() @@ -2053,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..136e05c9ad 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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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._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), - )), - ) + # 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._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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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), - )), - ) + # 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() @@ -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..4b26f57404 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,35 @@ 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 + def test_list_instances_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1659,6 +1688,35 @@ 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 + def test_get_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2009,6 +2067,35 @@ 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 + def test_get_instance_auth_string_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2365,6 +2452,35 @@ 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 + def test_create_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2739,6 +2855,35 @@ 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 + def test_update_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3107,6 +3252,35 @@ 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 + def test_upgrade_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3473,6 +3647,35 @@ 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 + def test_import_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3839,6 +4042,35 @@ 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 + def test_export_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4205,6 +4437,35 @@ 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 + def test_failover_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4571,6 +4832,35 @@ 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 + def test_delete_instance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4927,6 +5217,35 @@ 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 + def test_reschedule_maintenance_field_headers(): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), From 96870eff62aab87d52934d07d36449bfb3f2df76 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Wed, 31 Jul 2024 09:57:21 -0700 Subject: [PATCH 09/15] generate tests for all methods --- .../gapic/%name_%version/%sub/test_macros.j2 | 2 - .../logging_v2/test_config_service_v2.py | 30 +++++ .../logging_v2/test_logging_service_v2.py | 120 ++++++++++++++++++ 3 files changed, 150 insertions(+), 2 deletions(-) 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 0b2e08eec8..841240dfc3 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,7 +510,6 @@ def test_{{ method.name|snake_case }}_routing_parameters(): {% endfor %} {% endif %} -{% if method.field_headers %} def test_{{ method.name|snake_case }}_routing_header_override(): client = {{ service.client_name }}( credentials=ga_credentials.AnonymousCredentials(), @@ -547,7 +546,6 @@ def test_{{ method.name|snake_case }}_routing_header_override(): 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 %} {% 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/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 f6fd7a734d..1991445af7 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 @@ -13061,6 +13061,36 @@ 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 + + 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 7d163d49bd..7742ced2ae 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 @@ -1320,6 +1320,36 @@ 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 + + def test_write_log_entries_flattened(): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -1641,6 +1671,36 @@ 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 + + def test_list_log_entries_flattened(): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -2139,6 +2199,36 @@ 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 + + def test_list_monitored_resource_descriptors_pager(transport_name: str = "grpc"): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -3047,6 +3137,36 @@ 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 + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.LoggingServiceV2GrpcTransport( From 59b5545995150628257fb7f4c358afb217ac65be Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 1 Aug 2024 14:14:09 -0700 Subject: [PATCH 10/15] added conditional to explicit routing --- .../%sub/services/%service/_client_macros.j2 | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) 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 70e05ee5f1..29c3bb74a6 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,34 +144,37 @@ # 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 #} + {% 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), - ) + 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 - metadata = tuple(metadata) if all(m[0] != gapic_v1.routing_header.ROUTING_METADATA_KEY for m in metadata): metadata = ( *metadata, From 6c1252d40aaeb7b53a88b64c810c70c4b95e93a5 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 1 Aug 2024 15:31:19 -0700 Subject: [PATCH 11/15] added async routing header test --- .../gapic/%name_%version/%sub/test_macros.j2 | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) 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 841240dfc3..70c5fd0dc4 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 @@ -547,6 +547,45 @@ def test_{{ method.name|snake_case }}_routing_header_override(): # 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_{{ 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 + + _, _, 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 method.field_headers and not method.client_streaming and not method.explicit_routing %} def test_{{ method_name }}_field_headers(): client = {{ service.client_name }}( From f17458c8d259b909302f08c78ba3b21e1bbeed62 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 1 Aug 2024 15:38:02 -0700 Subject: [PATCH 12/15] gate async behind full_extended_lro --- .../tests/unit/gapic/%name_%version/%sub/test_macros.j2 | 3 +++ 1 file changed, 3 insertions(+) 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 70c5fd0dc4..8d41615779 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 @@ -547,6 +547,8 @@ def test_{{ method.name|snake_case }}_routing_header_override(): # 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 }}( @@ -585,6 +587,7 @@ async def test_{{ method_name }}_routing_header_override_async(): 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(): From 8ee23e39809122ad6975da9e2f494076e511028c Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 1 Aug 2024 16:25:06 -0700 Subject: [PATCH 13/15] removed unneeded line --- .../tests/unit/gapic/%name_%version/%sub/test_macros.j2 | 1 - 1 file changed, 1 deletion(-) 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 8d41615779..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 @@ -582,7 +582,6 @@ async def test_{{ method_name }}_routing_header_override_async(): args, kw = call.call_args 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 From 3a54caffd2238dc750d213eb72059bf3991164af Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 1 Aug 2024 16:35:39 -0700 Subject: [PATCH 14/15] removed space --- .../%name_%version/%sub/services/%service/_client_macros.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 29c3bb74a6..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 @@ -173,7 +173,7 @@ gapic_v1.routing_header.to_grpc_metadata(header_params), ) - {% elif method.field_headers %} {# implicit routing #} + {% 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 = ( From 09a0d01c1de6eac586dfdb74950c2fb23ff93954 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 2 Aug 2024 09:34:14 -0700 Subject: [PATCH 15/15] generated goldens --- .../asset_v1/services/asset_service/client.py | 46 +- .../unit/gapic/asset_v1/test_asset_service.py | 720 +++++++++++- .../services/iam_credentials/client.py | 8 +- .../credentials_v1/test_iam_credentials.py | 120 ++ .../eventarc_v1/services/eventarc/client.py | 36 +- .../unit/gapic/eventarc_v1/test_eventarc.py | 540 +++++++++ .../services/config_service_v2/client.py | 64 +- .../services/logging_service_v2/client.py | 12 +- .../services/metrics_service_v2/client.py | 10 +- .../logging_v2/test_config_service_v2.py | 1012 ++++++++++++++++- .../logging_v2/test_logging_service_v2.py | 181 +++ .../logging_v2/test_metrics_service_v2.py | 150 +++ .../redis_v1/services/cloud_redis/client.py | 22 +- .../unit/gapic/redis_v1/test_cloud_redis.py | 330 ++++++ 14 files changed, 3116 insertions(+), 135 deletions(-) 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 82af1e5848..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,8 +730,8 @@ def sample_export_assets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.export_assets] - # Attach routing header to metadata if not already present 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, @@ -851,8 +851,8 @@ def sample_list_assets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_assets] - # Attach routing header to metadata if not already present 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, @@ -950,8 +950,8 @@ def sample_batch_get_assets_history(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.batch_get_assets_history] - # Attach routing header to metadata if not already present 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, @@ -1073,8 +1073,8 @@ def sample_create_feed(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_feed] - # Attach routing header to metadata if not already present 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, @@ -1184,8 +1184,8 @@ def sample_get_feed(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_feed] - # Attach routing header to metadata if not already present 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, @@ -1290,8 +1290,8 @@ def sample_list_feeds(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_feeds] - # Attach routing header to metadata if not already present 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, @@ -1405,8 +1405,8 @@ def sample_update_feed(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_feed] - # Attach routing header to metadata if not already present 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, @@ -1501,8 +1501,8 @@ def sample_delete_feed(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_feed] - # Attach routing header to metadata if not already present 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, @@ -1718,8 +1718,8 @@ def sample_search_all_resources(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.search_all_resources] - # Attach routing header to metadata if not already present 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, @@ -1910,8 +1910,8 @@ def sample_search_all_iam_policies(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.search_all_iam_policies] - # Attach routing header to metadata if not already present 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, @@ -2010,8 +2010,8 @@ def sample_analyze_iam_policy(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_iam_policy] - # Attach routing header to metadata if not already present 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, @@ -2119,8 +2119,8 @@ def sample_analyze_iam_policy_longrunning(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_iam_policy_longrunning] - # Attach routing header to metadata if not already present 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, @@ -2219,8 +2219,8 @@ def sample_analyze_move(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_move] - # Attach routing header to metadata if not already present 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, @@ -2317,8 +2317,8 @@ def sample_query_assets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.query_assets] - # Attach routing header to metadata if not already present 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, @@ -2455,8 +2455,8 @@ def sample_create_saved_query(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_saved_query] - # Attach routing header to metadata if not already present 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, @@ -2562,8 +2562,8 @@ def sample_get_saved_query(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_saved_query] - # Attach routing header to metadata if not already present 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, @@ -2675,8 +2675,8 @@ def sample_list_saved_queries(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_saved_queries] - # Attach routing header to metadata if not already present 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, @@ -2804,8 +2804,8 @@ def sample_update_saved_query(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_saved_query] - # Attach routing header to metadata if not already present 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, @@ -2902,8 +2902,8 @@ def sample_delete_saved_query(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_saved_query] - # Attach routing header to metadata if not already present 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, @@ -2985,8 +2985,8 @@ def sample_batch_get_effective_iam_policies(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.batch_get_effective_iam_policies] - # Attach routing header to metadata if not already present 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, @@ -3127,8 +3127,8 @@ def sample_analyze_org_policies(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_org_policies] - # Attach routing header to metadata if not already present 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, @@ -3280,8 +3280,8 @@ def sample_analyze_org_policy_governed_containers(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_org_policy_governed_containers] - # Attach routing header to metadata if not already present 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, @@ -3462,8 +3462,8 @@ def sample_analyze_org_policy_governed_assets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.analyze_org_policy_governed_assets] - # Attach routing header to metadata if not already present 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, 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 57d8d061b3..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 @@ -1008,6 +1008,36 @@ def test_export_assets_routing_header_override(): # 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(), @@ -1307,6 +1337,36 @@ def test_list_assets_routing_header_override(): # 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(), @@ -1877,6 +1937,36 @@ def test_batch_get_assets_history_routing_header_override(): # 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(), @@ -2196,6 +2286,36 @@ def test_create_feed_routing_header_override(): # 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(), @@ -2595,6 +2715,36 @@ def test_get_feed_routing_header_override(): # 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(), @@ -2969,6 +3119,36 @@ def test_list_feeds_routing_header_override(): # 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(), @@ -3366,6 +3546,36 @@ def test_update_feed_routing_header_override(): # 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_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(), @@ -3737,6 +3947,36 @@ def test_delete_feed_routing_header_override(): # 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(), @@ -4122,6 +4362,36 @@ def test_search_all_resources_routing_header_override(): # 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(), @@ -4723,6 +4993,36 @@ def test_search_all_iam_policies_routing_header_override(): # 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(), @@ -5308,6 +5608,36 @@ def test_analyze_iam_policy_routing_header_override(): # 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(), @@ -5609,6 +5939,36 @@ def test_analyze_iam_policy_longrunning_routing_header_override(): # 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(), @@ -5903,6 +6263,36 @@ def test_analyze_move_routing_header_override(): # 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(), @@ -6171,19 +6561,50 @@ async def test_query_assets_async(transport: str = 'grpc_asyncio', request_type= request = asset_service.QueryAssetsRequest() assert args[0] == request - # Establish that the response is the type that we expect. - assert isinstance(response, asset_service.QueryAssetsResponse) - assert response.job_reference == 'job_reference_value' - assert response.done is True + # Establish that the response is the type that we expect. + assert isinstance(response, asset_service.QueryAssetsResponse) + assert response.job_reference == 'job_reference_value' + assert response.done is True + + +@pytest.mark.asyncio +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_async_from_dict(): - await test_query_assets_async(request_type=dict) - - -def test_query_assets_routing_header_override(): - client = AssetServiceClient( +async def test_query_assets_routing_header_override_async(): + client = AssetServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6195,17 +6616,16 @@ def test_query_assets_routing_header_override(): with mock.patch.object( type(client.transport.query_assets), '__call__') as call: - call.return_value = asset_service.QueryAssetsResponse() + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(asset_service.QueryAssetsResponse()) custom_val = "key=custom" override = [('x-goog-request-params', custom_val)] - client.query_assets(request, metadata=override) + await 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 call.call_count == 1 + args, kw = call.call_args 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 @@ -6525,6 +6945,36 @@ def test_create_saved_query_routing_header_override(): # 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(), @@ -6939,6 +7389,36 @@ def test_get_saved_query_routing_header_override(): # 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(), @@ -7322,6 +7802,36 @@ def test_list_saved_queries_routing_header_override(): # 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( credentials=ga_credentials.AnonymousCredentials(), @@ -7910,6 +8420,36 @@ def test_update_saved_query_routing_header_override(): # 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(), @@ -8291,6 +8831,36 @@ def test_delete_saved_query_routing_header_override(): # 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(), @@ -8665,6 +9235,36 @@ def test_batch_get_effective_iam_policies_routing_header_override(): # 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(), @@ -8968,6 +9568,36 @@ def test_analyze_org_policies_routing_header_override(): # 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(), @@ -9569,6 +10199,36 @@ def test_analyze_org_policy_governed_containers_routing_header_override(): # 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(), @@ -10170,6 +10830,36 @@ def test_analyze_org_policy_governed_assets_routing_header_override(): # 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/client.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py index 2e672125dd..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,8 +714,8 @@ def sample_generate_access_token(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.generate_access_token] - # Attach routing header to metadata if not already present 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, @@ -864,8 +864,8 @@ def sample_generate_id_token(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.generate_id_token] - # Attach routing header to metadata if not already present 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, @@ -1000,8 +1000,8 @@ def sample_sign_blob(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.sign_blob] - # Attach routing header to metadata if not already present 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, @@ -1139,8 +1139,8 @@ def sample_sign_jwt(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.sign_jwt] - # Attach routing header to metadata if not already present 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, 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 e56f621120..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 @@ -994,6 +994,36 @@ def test_generate_access_token_routing_header_override(): # 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(), @@ -1401,6 +1431,36 @@ def test_generate_id_token_routing_header_override(): # 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(), @@ -1815,6 +1875,36 @@ def test_sign_blob_routing_header_override(): # 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(), @@ -2221,6 +2311,36 @@ def test_sign_jwt_routing_header_override(): # 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/client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py index 304f8d206a..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,8 +770,8 @@ def sample_get_trigger(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_trigger] - # Attach routing header to metadata if not already present 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, @@ -877,8 +877,8 @@ def sample_list_triggers(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_triggers] - # Attach routing header to metadata if not already present 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, @@ -1028,8 +1028,8 @@ def sample_create_trigger(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_trigger] - # Attach routing header to metadata if not already present 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, @@ -1168,8 +1168,8 @@ def sample_update_trigger(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_trigger] - # Attach routing header to metadata if not already present 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, @@ -1299,8 +1299,8 @@ def sample_delete_trigger(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_trigger] - # Attach routing header to metadata if not already present 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, @@ -1417,8 +1417,8 @@ def sample_get_channel(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_channel] - # Attach routing header to metadata if not already present 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, @@ -1524,8 +1524,8 @@ def sample_list_channels(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_channels] - # Attach routing header to metadata if not already present 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, @@ -1675,8 +1675,8 @@ def sample_create_channel(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_channel_] - # Attach routing header to metadata if not already present 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, @@ -1807,8 +1807,8 @@ def sample_update_channel(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_channel] - # Attach routing header to metadata if not already present 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, @@ -1930,8 +1930,8 @@ def sample_delete_channel(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_channel] - # Attach routing header to metadata if not already present 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, @@ -2042,8 +2042,8 @@ def sample_get_provider(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_provider] - # Attach routing header to metadata if not already present 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, @@ -2149,8 +2149,8 @@ def sample_list_providers(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_providers] - # Attach routing header to metadata if not already present 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, @@ -2269,8 +2269,8 @@ def sample_get_channel_connection(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_channel_connection] - # Attach routing header to metadata if not already present 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, @@ -2377,8 +2377,8 @@ def sample_list_channel_connections(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_channel_connections] - # Attach routing header to metadata if not already present 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, @@ -2528,8 +2528,8 @@ def sample_create_channel_connection(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_channel_connection] - # Attach routing header to metadata if not already present 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, @@ -2649,8 +2649,8 @@ def sample_delete_channel_connection(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_channel_connection] - # Attach routing header to metadata if not already present 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, @@ -2767,8 +2767,8 @@ def sample_get_google_channel_config(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_google_channel_config] - # Attach routing header to metadata if not already present 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, @@ -2890,8 +2890,8 @@ def sample_update_google_channel_config(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_google_channel_config] - # Attach routing header to metadata if not already present 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, 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 387cffaaf9..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 @@ -1034,6 +1034,36 @@ def test_get_trigger_routing_header_override(): # 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(), @@ -1424,6 +1454,36 @@ def test_list_triggers_routing_header_override(): # 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(), @@ -2005,6 +2065,36 @@ def test_create_trigger_routing_header_override(): # 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(), @@ -2408,6 +2498,36 @@ def test_update_trigger_routing_header_override(): # 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(), @@ -2815,6 +2935,36 @@ def test_delete_trigger_routing_header_override(): # 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(), @@ -3232,6 +3382,36 @@ def test_get_channel_routing_header_override(): # 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(), @@ -3620,6 +3800,36 @@ def test_list_channels_routing_header_override(): # 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(), @@ -4201,6 +4411,36 @@ def test_create_channel_routing_header_override(): # 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(), @@ -4604,6 +4844,36 @@ def test_update_channel_routing_header_override(): # 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(), @@ -4999,6 +5269,36 @@ def test_delete_channel_routing_header_override(): # 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(), @@ -5385,6 +5685,36 @@ def test_get_provider_routing_header_override(): # 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(), @@ -5775,6 +6105,36 @@ def test_list_providers_routing_header_override(): # 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( credentials=ga_credentials.AnonymousCredentials(), @@ -6365,6 +6725,36 @@ def test_get_channel_connection_routing_header_override(): # 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(), @@ -6751,6 +7141,36 @@ def test_list_channel_connections_routing_header_override(): # 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(), @@ -7332,6 +7752,36 @@ def test_create_channel_connection_routing_header_override(): # 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(), @@ -7737,6 +8187,36 @@ def test_delete_channel_connection_routing_header_override(): # 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(), @@ -8123,6 +8603,36 @@ def test_get_google_channel_config_routing_header_override(): # 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(), @@ -8505,6 +9015,36 @@ def test_update_google_channel_config_routing_header_override(): # 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/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py index 6d2a87ff21..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,8 +732,8 @@ def sample_list_buckets(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_buckets] - # Attach routing header to metadata if not already present 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, @@ -827,8 +827,8 @@ def sample_get_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_bucket] - # Attach routing header to metadata if not already present 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, @@ -922,8 +922,8 @@ def sample_create_bucket_async(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_bucket_async] - # Attach routing header to metadata if not already present 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, @@ -1027,8 +1027,8 @@ def sample_update_bucket_async(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_bucket_async] - # Attach routing header to metadata if not already present 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, @@ -1122,8 +1122,8 @@ def sample_create_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_bucket] - # Attach routing header to metadata if not already present 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, @@ -1212,8 +1212,8 @@ def sample_update_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_bucket] - # Attach routing header to metadata if not already present 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, @@ -1292,8 +1292,8 @@ def sample_delete_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_bucket] - # Attach routing header to metadata if not already present 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, @@ -1366,8 +1366,8 @@ def sample_undelete_bucket(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.undelete_bucket] - # Attach routing header to metadata if not already present 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, @@ -1473,8 +1473,8 @@ def sample_list_views(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_views] - # Attach routing header to metadata if not already present 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, @@ -1568,8 +1568,8 @@ def sample_get_view(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_view] - # Attach routing header to metadata if not already present 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, @@ -1654,8 +1654,8 @@ def sample_create_view(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_view] - # Attach routing header to metadata if not already present 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, @@ -1742,8 +1742,8 @@ def sample_update_view(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_view] - # Attach routing header to metadata if not already present 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, @@ -1820,8 +1820,8 @@ def sample_delete_view(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_view] - # Attach routing header to metadata if not already present 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, @@ -1930,8 +1930,8 @@ def sample_list_sinks(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_sinks] - # Attach routing header to metadata if not already present 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, @@ -2061,8 +2061,8 @@ def sample_get_sink(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_sink] - # Attach routing header to metadata if not already present 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, @@ -2200,8 +2200,8 @@ def sample_create_sink(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_sink] - # Attach routing header to metadata if not already present 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, @@ -2366,8 +2366,8 @@ def sample_update_sink(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_sink] - # Attach routing header to metadata if not already present 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, @@ -2472,8 +2472,8 @@ def sample_delete_sink(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_sink] - # Attach routing header to metadata if not already present 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, @@ -2609,8 +2609,8 @@ def sample_create_link(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_link] - # Attach routing header to metadata if not already present 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, @@ -2739,8 +2739,8 @@ def sample_delete_link(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_link] - # Attach routing header to metadata if not already present 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, @@ -2859,8 +2859,8 @@ def sample_list_links(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_links] - # Attach routing header to metadata if not already present 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, @@ -2977,8 +2977,8 @@ def sample_get_link(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_link] - # Attach routing header to metadata if not already present 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, @@ -3091,8 +3091,8 @@ def sample_list_exclusions(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_exclusions] - # Attach routing header to metadata if not already present 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, @@ -3220,8 +3220,8 @@ def sample_get_exclusion(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_exclusion] - # Attach routing header to metadata if not already present 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, @@ -3358,8 +3358,8 @@ def sample_create_exclusion(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_exclusion] - # Attach routing header to metadata if not already present 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, @@ -3510,8 +3510,8 @@ def sample_update_exclusion(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_exclusion] - # Attach routing header to metadata if not already present 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, @@ -3615,8 +3615,8 @@ def sample_delete_exclusion(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_exclusion] - # Attach routing header to metadata if not already present 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, @@ -3720,8 +3720,8 @@ def sample_get_cmek_settings(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_cmek_settings] - # Attach routing header to metadata if not already present 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, @@ -3833,8 +3833,8 @@ def sample_update_cmek_settings(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_cmek_settings] - # Attach routing header to metadata if not already present 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, @@ -3969,8 +3969,8 @@ def sample_get_settings(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_settings] - # Attach routing header to metadata if not already present 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, @@ -4115,8 +4115,8 @@ def sample_update_settings(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_settings] - # Attach routing header to metadata if not already present 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, @@ -4209,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() 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 6868dd0273..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,8 +654,8 @@ def sample_delete_log(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_log] - # Attach routing header to metadata if not already present 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, @@ -849,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() @@ -994,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() @@ -1084,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() @@ -1198,8 +1204,8 @@ def sample_list_logs(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_logs] - # Attach routing header to metadata if not already present 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, @@ -1299,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() 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 a7a791507b..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,8 +657,8 @@ def sample_list_log_metrics(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_log_metrics] - # Attach routing header to metadata if not already present 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, @@ -784,8 +784,8 @@ def sample_get_log_metric(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_log_metric] - # Attach routing header to metadata if not already present 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, @@ -919,8 +919,8 @@ def sample_create_log_metric(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_log_metric] - # Attach routing header to metadata if not already present 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, @@ -1053,8 +1053,8 @@ def sample_update_log_metric(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_log_metric] - # Attach routing header to metadata if not already present 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, @@ -1150,8 +1150,8 @@ def sample_delete_log_metric(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_log_metric] - # Attach routing header to metadata if not already present 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, 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 1991445af7..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 @@ -983,6 +983,36 @@ def test_list_buckets_routing_header_override(): # 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(), @@ -1588,6 +1618,36 @@ def test_get_bucket_routing_header_override(): # 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(), @@ -1891,6 +1951,36 @@ def test_create_bucket_async_routing_header_override(): # 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(), @@ -2192,6 +2282,36 @@ def test_update_bucket_async_routing_header_override(): # 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(), @@ -2521,6 +2641,36 @@ def test_create_bucket_routing_header_override(): # 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(), @@ -2848,6 +2998,36 @@ def test_update_bucket_routing_header_override(): # 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(), @@ -3137,6 +3317,36 @@ def test_delete_bucket_routing_header_override(): # 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_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(), @@ -3426,6 +3636,36 @@ def test_undelete_bucket_routing_header_override(): # 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(), @@ -3725,6 +3965,36 @@ def test_list_views_routing_header_override(): # 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(), @@ -4310,6 +4580,36 @@ def test_get_view_routing_header_override(): # 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(), @@ -4619,6 +4919,36 @@ def test_create_view_routing_header_override(): # 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(), @@ -4926,6 +5256,36 @@ def test_update_view_routing_header_override(): # 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(), @@ -5215,6 +5575,36 @@ def test_delete_view_routing_header_override(): # 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(), @@ -5481,12 +5871,43 @@ async def test_list_sinks_async(transport: str = 'grpc_asyncio', request_type=lo @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( +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(), ) @@ -5498,17 +5919,16 @@ def test_list_sinks_routing_header_override(): with mock.patch.object( type(client.transport.list_sinks), '__call__') as call: - call.return_value = logging_config.ListSinksResponse() + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.ListSinksResponse()) custom_val = "key=custom" override = [('x-goog-request-params', custom_val)] - client.list_sinks(request, metadata=override) + await 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 call.call_count == 1 + args, kw = call.call_args 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 @@ -6124,6 +6544,36 @@ def test_get_sink_routing_header_override(): # 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(), @@ -6538,6 +6988,36 @@ def test_create_sink_routing_header_override(): # 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(), @@ -6962,6 +7442,36 @@ def test_update_sink_routing_header_override(): # 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(), @@ -7353,6 +7863,36 @@ def test_delete_sink_routing_header_override(): # 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(), @@ -7738,6 +8278,36 @@ def test_create_link_routing_header_override(): # 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(), @@ -8143,6 +8713,36 @@ def test_delete_link_routing_header_override(): # 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) + + # 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( credentials=ga_credentials.AnonymousCredentials(), @@ -8526,6 +9126,36 @@ def test_list_links_routing_header_override(): # 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(), @@ -9111,6 +9741,36 @@ def test_get_link_routing_header_override(): # 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(), @@ -9450,21 +10110,52 @@ async def test_list_exclusions_async(transport: str = 'grpc_asyncio', request_ty # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = logging_config.ListExclusionsRequest() + request = logging_config.ListExclusionsRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListExclusionsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +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 - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListExclusionsAsyncPager) - assert response.next_page_token == 'next_page_token_value' + _, _, 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_async_from_dict(): - await test_list_exclusions_async(request_type=dict) - - -def test_list_exclusions_routing_header_override(): - client = ConfigServiceV2Client( +async def test_list_exclusions_routing_header_override_async(): + client = ConfigServiceV2AsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -9476,17 +10167,16 @@ def test_list_exclusions_routing_header_override(): with mock.patch.object( type(client.transport.list_exclusions), '__call__') as call: - call.return_value = logging_config.ListExclusionsResponse() + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(logging_config.ListExclusionsResponse()) custom_val = "key=custom" override = [('x-goog-request-params', custom_val)] - client.list_exclusions(request, metadata=override) + await 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 call.call_count == 1 + args, kw = call.call_args 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 @@ -10082,6 +10772,36 @@ def test_get_exclusion_routing_header_override(): # 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(), @@ -10476,6 +11196,36 @@ def test_create_exclusion_routing_header_override(): # 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(), @@ -10880,6 +11630,36 @@ def test_update_exclusion_routing_header_override(): # 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( credentials=ga_credentials.AnonymousCredentials(), @@ -11271,6 +12051,36 @@ def test_delete_exclusion_routing_header_override(): # 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(), @@ -11665,6 +12475,36 @@ def test_get_cmek_settings_routing_header_override(): # 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(), @@ -11977,6 +12817,36 @@ def test_update_cmek_settings_routing_header_override(): # 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(), @@ -12294,6 +13164,36 @@ def test_get_settings_routing_header_override(): # 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(), @@ -12693,6 +13593,36 @@ def test_update_settings_routing_header_override(): # 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(), @@ -13091,6 +14021,36 @@ def test_copy_log_entries_routing_header_override(): 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 7742ced2ae..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 @@ -975,6 +975,36 @@ def test_delete_log_routing_header_override(): # 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(), @@ -1350,6 +1380,36 @@ def test_write_log_entries_routing_header_override(): 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(), @@ -1701,6 +1761,36 @@ def test_list_log_entries_routing_header_override(): 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(), @@ -2229,6 +2319,36 @@ def test_list_monitored_resource_descriptors_routing_header_override(): 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(), @@ -2661,6 +2781,36 @@ def test_list_logs_routing_header_override(): # 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(), @@ -3167,6 +3317,37 @@ def test_tail_log_entries_routing_header_override(): 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 b186757973..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 @@ -983,6 +983,36 @@ def test_list_log_metrics_routing_header_override(): # 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(), @@ -1588,6 +1618,36 @@ def test_get_log_metric_routing_header_override(): # 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(), @@ -1997,6 +2057,36 @@ def test_create_log_metric_routing_header_override(): # 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(), @@ -2416,6 +2506,36 @@ def test_update_log_metric_routing_header_override(): # 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(), @@ -2797,6 +2917,36 @@ def test_delete_log_metric_routing_header_override(): # 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/client.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py index 136e05c9ad..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,8 +694,8 @@ def sample_list_instances(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_instances] - # Attach routing header to metadata if not already present 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, @@ -808,8 +808,8 @@ def sample_get_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_instance] - # Attach routing header to metadata if not already present 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, @@ -914,8 +914,8 @@ def sample_get_instance_auth_string(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_instance_auth_string] - # Attach routing header to metadata if not already present 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, @@ -1072,8 +1072,8 @@ def sample_create_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_instance] - # Attach routing header to metadata if not already present 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, @@ -1219,8 +1219,8 @@ def sample_update_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_instance] - # Attach routing header to metadata if not already present 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, @@ -1351,8 +1351,8 @@ def sample_upgrade_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.upgrade_instance] - # Attach routing header to metadata if not already present 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, @@ -1493,8 +1493,8 @@ def sample_import_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.import_instance] - # Attach routing header to metadata if not already present 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, @@ -1632,8 +1632,8 @@ def sample_export_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.export_instance] - # Attach routing header to metadata if not already present 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, @@ -1765,8 +1765,8 @@ def sample_failover_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.failover_instance] - # Attach routing header to metadata if not already present 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, @@ -1893,8 +1893,8 @@ def sample_delete_instance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_instance] - # Attach routing header to metadata if not already present 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, @@ -2036,8 +2036,8 @@ def sample_reschedule_maintenance(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.reschedule_maintenance] - # Attach routing header to metadata if not already present 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, 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 4b26f57404..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 @@ -1012,6 +1012,36 @@ def test_list_instances_routing_header_override(): # 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(), @@ -1717,6 +1747,36 @@ def test_get_instance_routing_header_override(): # 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(), @@ -2096,6 +2156,36 @@ def test_get_instance_auth_string_routing_header_override(): # 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(), @@ -2481,6 +2571,36 @@ def test_create_instance_routing_header_override(): # 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(), @@ -2884,6 +3004,36 @@ def test_update_instance_routing_header_override(): # 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(), @@ -3281,6 +3431,36 @@ def test_upgrade_instance_routing_header_override(): # 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(), @@ -3676,6 +3856,36 @@ def test_import_instance_routing_header_override(): # 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(), @@ -4071,6 +4281,36 @@ def test_export_instance_routing_header_override(): # 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(), @@ -4466,6 +4706,36 @@ def test_failover_instance_routing_header_override(): # 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(), @@ -4861,6 +5131,36 @@ def test_delete_instance_routing_header_override(): # 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(), @@ -5246,6 +5546,36 @@ def test_reschedule_maintenance_routing_header_override(): # 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(),