From e44773577a733799104fd4ac7e80ec5fdac17639 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 27 Apr 2022 09:53:52 -0400 Subject: [PATCH] chore: use gapic-generator-python 0.65.2 (#101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: use gapic-generator-python 0.65.2 PiperOrigin-RevId: 444333013 Source-Link: https://github.com/googleapis/googleapis/commit/f91b6cf82e929280f6562f6110957c654bd9e2e6 Source-Link: https://github.com/googleapis/googleapis-gen/commit/16eb36095c294e712c74a1bf23550817b42174e5 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMTZlYjM2MDk1YzI5NGU3MTJjNzRhMWJmMjM1NTA4MTdiNDIxNzRlNSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../flex_templates_service/async_client.py | 17 +- .../services/flex_templates_service/client.py | 11 + .../services/jobs_v1_beta3/async_client.py | 108 ++++- .../services/jobs_v1_beta3/client.py | 66 +++ .../messages_v1_beta3/async_client.py | 18 +- .../services/messages_v1_beta3/client.py | 12 + .../services/metrics_v1_beta3/async_client.py | 55 ++- .../services/metrics_v1_beta3/client.py | 37 ++ .../snapshots_v1_beta3/async_client.py | 54 ++- .../services/snapshots_v1_beta3/client.py | 36 ++ .../templates_service/async_client.py | 51 ++- .../services/templates_service/client.py | 33 ++ .../test_flex_templates_service.py | 67 +++ .../dataflow_v1beta3/test_jobs_v1_beta3.py | 393 +++++++++++++++++- .../test_messages_v1_beta3.py | 80 +++- .../dataflow_v1beta3/test_metrics_v1_beta3.py | 226 +++++++++- .../test_snapshots_v1_beta3.py | 193 +++++++++ .../test_templates_service.py | 191 +++++++++ 18 files changed, 1589 insertions(+), 59 deletions(-) diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py index d54752f99193..9405f05e1338 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py @@ -217,16 +217,16 @@ async def launch_flex_template( from google.cloud import dataflow_v1beta3 - def sample_launch_flex_template(): + async def sample_launch_flex_template(): # Create a client - client = dataflow_v1beta3.FlexTemplatesServiceClient() + client = dataflow_v1beta3.FlexTemplatesServiceAsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.LaunchFlexTemplateRequest( ) # Make the request - response = client.launch_flex_template(request=request) + response = await client.launch_flex_template(request=request) # Handle the response print(response) @@ -258,6 +258,17 @@ def sample_launch_flex_template(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py index 1f190984bdd3..ed76d63b4aa9 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py @@ -462,6 +462,17 @@ def sample_launch_flex_template(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.launch_flex_template] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py index 6b6af0ea6fad..cdcd4fcdb738 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py @@ -223,16 +223,16 @@ async def create_job( from google.cloud import dataflow_v1beta3 - def sample_create_job(): + async def sample_create_job(): # Create a client - client = dataflow_v1beta3.JobsV1Beta3Client() + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.CreateJobRequest( ) # Make the request - response = client.create_job(request=request) + response = await client.create_job(request=request) # Handle the response print(response) @@ -264,6 +264,17 @@ def sample_create_job(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -295,16 +306,16 @@ async def get_job( from google.cloud import dataflow_v1beta3 - def sample_get_job(): + async def sample_get_job(): # Create a client - client = dataflow_v1beta3.JobsV1Beta3Client() + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.GetJobRequest( ) # Make the request - response = client.get_job(request=request) + response = await client.get_job(request=request) # Handle the response print(response) @@ -336,6 +347,18 @@ def sample_get_job(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -368,16 +391,16 @@ async def update_job( from google.cloud import dataflow_v1beta3 - def sample_update_job(): + async def sample_update_job(): # Create a client - client = dataflow_v1beta3.JobsV1Beta3Client() + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.UpdateJobRequest( ) # Make the request - response = client.update_job(request=request) + response = await client.update_job(request=request) # Handle the response print(response) @@ -409,6 +432,18 @@ def sample_update_job(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -442,9 +477,9 @@ async def list_jobs( from google.cloud import dataflow_v1beta3 - def sample_list_jobs(): + async def sample_list_jobs(): # Create a client - client = dataflow_v1beta3.JobsV1Beta3Client() + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.ListJobsRequest( @@ -454,7 +489,7 @@ def sample_list_jobs(): page_result = client.list_jobs(request=request) # Handle the response - for response in page_result: + async for response in page_result: print(response) Args: @@ -493,6 +528,17 @@ def sample_list_jobs(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -527,9 +573,9 @@ async def aggregated_list_jobs( from google.cloud import dataflow_v1beta3 - def sample_aggregated_list_jobs(): + async def sample_aggregated_list_jobs(): # Create a client - client = dataflow_v1beta3.JobsV1Beta3Client() + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.ListJobsRequest( @@ -539,7 +585,7 @@ def sample_aggregated_list_jobs(): page_result = client.aggregated_list_jobs(request=request) # Handle the response - for response in page_result: + async for response in page_result: print(response) Args: @@ -578,6 +624,14 @@ def sample_aggregated_list_jobs(): 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( + (("project_id", request.project_id),) + ), + ) + # Send the request. response = await rpc( request, @@ -613,16 +667,16 @@ async def check_active_jobs( from google.cloud import dataflow_v1beta3 - def sample_check_active_jobs(): + async def sample_check_active_jobs(): # Create a client - client = dataflow_v1beta3.JobsV1Beta3Client() + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.CheckActiveJobsRequest( ) # Make the request - response = client.check_active_jobs(request=request) + response = await client.check_active_jobs(request=request) # Handle the response print(response) @@ -677,16 +731,16 @@ async def snapshot_job( from google.cloud import dataflow_v1beta3 - def sample_snapshot_job(): + async def sample_snapshot_job(): # Create a client - client = dataflow_v1beta3.JobsV1Beta3Client() + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.SnapshotJobRequest( ) # Make the request - response = client.snapshot_job(request=request) + response = await client.snapshot_job(request=request) # Handle the response print(response) @@ -716,6 +770,18 @@ def sample_snapshot_job(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py index 780474349d00..50fd03e60081 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py @@ -471,6 +471,17 @@ def sample_create_job(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_job] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = rpc( request, @@ -544,6 +555,18 @@ def sample_get_job(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_job] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = rpc( request, @@ -618,6 +641,18 @@ def sample_update_job(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_job] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = rpc( request, @@ -703,6 +738,17 @@ def sample_list_jobs(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_jobs] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = rpc( request, @@ -789,6 +835,14 @@ def sample_aggregated_list_jobs(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.aggregated_list_jobs] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("project_id", request.project_id),) + ), + ) + # Send the request. response = rpc( request, @@ -929,6 +983,18 @@ def sample_snapshot_job(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.snapshot_job] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py index e136694b191d..642a9461b56d 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py @@ -225,9 +225,9 @@ async def list_job_messages( from google.cloud import dataflow_v1beta3 - def sample_list_job_messages(): + async def sample_list_job_messages(): # Create a client - client = dataflow_v1beta3.MessagesV1Beta3Client() + client = dataflow_v1beta3.MessagesV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.ListJobMessagesRequest( @@ -237,7 +237,7 @@ def sample_list_job_messages(): page_result = client.list_job_messages(request=request) # Handle the response - for response in page_result: + async for response in page_result: print(response) Args: @@ -273,6 +273,18 @@ def sample_list_job_messages(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py index f3e5c57b70d4..505f22b28fcb 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py @@ -478,6 +478,18 @@ def sample_list_job_messages(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_job_messages] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py index 6b1aad5817e3..cd1b4acc7881 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py @@ -227,16 +227,16 @@ async def get_job_metrics( from google.cloud import dataflow_v1beta3 - def sample_get_job_metrics(): + async def sample_get_job_metrics(): # Create a client - client = dataflow_v1beta3.MetricsV1Beta3Client() + client = dataflow_v1beta3.MetricsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.GetJobMetricsRequest( ) # Make the request - response = client.get_job_metrics(request=request) + response = await client.get_job_metrics(request=request) # Handle the response print(response) @@ -276,6 +276,18 @@ def sample_get_job_metrics(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -304,9 +316,9 @@ async def get_job_execution_details( from google.cloud import dataflow_v1beta3 - def sample_get_job_execution_details(): + async def sample_get_job_execution_details(): # Create a client - client = dataflow_v1beta3.MetricsV1Beta3Client() + client = dataflow_v1beta3.MetricsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.GetJobExecutionDetailsRequest( @@ -316,7 +328,7 @@ def sample_get_job_execution_details(): page_result = client.get_job_execution_details(request=request) # Handle the response - for response in page_result: + async for response in page_result: print(response) Args: @@ -349,6 +361,18 @@ def sample_get_job_execution_details(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -387,9 +411,9 @@ async def get_stage_execution_details( from google.cloud import dataflow_v1beta3 - def sample_get_stage_execution_details(): + async def sample_get_stage_execution_details(): # Create a client - client = dataflow_v1beta3.MetricsV1Beta3Client() + client = dataflow_v1beta3.MetricsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.GetStageExecutionDetailsRequest( @@ -399,7 +423,7 @@ def sample_get_stage_execution_details(): page_result = client.get_stage_execution_details(request=request) # Handle the response - for response in page_result: + async for response in page_result: print(response) Args: @@ -433,6 +457,19 @@ def sample_get_stage_execution_details(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ("stage_id", request.stage_id), + ) + ), + ) + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py index 02cf17a36752..52f1f8b007da 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py @@ -481,6 +481,18 @@ def sample_get_job_metrics(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_job_metrics] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = rpc( request, @@ -557,6 +569,18 @@ def sample_get_job_execution_details(): self._transport.get_job_execution_details ] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = rpc( request, @@ -644,6 +668,19 @@ def sample_get_stage_execution_details(): self._transport.get_stage_execution_details ] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ("stage_id", request.stage_id), + ) + ), + ) + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py index 627f1b42fdb7..7dee335e9f4f 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py @@ -219,16 +219,16 @@ async def get_snapshot( from google.cloud import dataflow_v1beta3 - def sample_get_snapshot(): + async def sample_get_snapshot(): # Create a client - client = dataflow_v1beta3.SnapshotsV1Beta3Client() + client = dataflow_v1beta3.SnapshotsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.GetSnapshotRequest( ) # Make the request - response = client.get_snapshot(request=request) + response = await client.get_snapshot(request=request) # Handle the response print(response) @@ -258,6 +258,18 @@ def sample_get_snapshot(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("snapshot_id", request.snapshot_id), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -283,16 +295,16 @@ async def delete_snapshot( from google.cloud import dataflow_v1beta3 - def sample_delete_snapshot(): + async def sample_delete_snapshot(): # Create a client - client = dataflow_v1beta3.SnapshotsV1Beta3Client() + client = dataflow_v1beta3.SnapshotsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.DeleteSnapshotRequest( ) # Make the request - response = client.delete_snapshot(request=request) + response = await client.delete_snapshot(request=request) # Handle the response print(response) @@ -321,6 +333,18 @@ def sample_delete_snapshot(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("snapshot_id", request.snapshot_id), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -346,16 +370,16 @@ async def list_snapshots( from google.cloud import dataflow_v1beta3 - def sample_list_snapshots(): + async def sample_list_snapshots(): # Create a client - client = dataflow_v1beta3.SnapshotsV1Beta3Client() + client = dataflow_v1beta3.SnapshotsV1Beta3AsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.ListSnapshotsRequest( ) # Make the request - response = client.list_snapshots(request=request) + response = await client.list_snapshots(request=request) # Handle the response print(response) @@ -384,6 +408,18 @@ def sample_list_snapshots(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py index 7fe750b40927..c0d9b995ddd6 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py @@ -463,6 +463,18 @@ def sample_get_snapshot(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_snapshot] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("snapshot_id", request.snapshot_id), + ) + ), + ) + # Send the request. response = rpc( request, @@ -527,6 +539,18 @@ def sample_delete_snapshot(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_snapshot] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("snapshot_id", request.snapshot_id), + ) + ), + ) + # Send the request. response = rpc( request, @@ -591,6 +615,18 @@ def sample_list_snapshots(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_snapshots] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ("job_id", request.job_id), + ) + ), + ) + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py index 96c2c57bd6cc..3b718bf5ac43 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py @@ -219,9 +219,9 @@ async def create_job_from_template( from google.cloud import dataflow_v1beta3 - def sample_create_job_from_template(): + async def sample_create_job_from_template(): # Create a client - client = dataflow_v1beta3.TemplatesServiceClient() + client = dataflow_v1beta3.TemplatesServiceAsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.CreateJobFromTemplateRequest( @@ -229,7 +229,7 @@ def sample_create_job_from_template(): ) # Make the request - response = client.create_job_from_template(request=request) + response = await client.create_job_from_template(request=request) # Handle the response print(response) @@ -261,6 +261,17 @@ def sample_create_job_from_template(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -286,9 +297,9 @@ async def launch_template( from google.cloud import dataflow_v1beta3 - def sample_launch_template(): + async def sample_launch_template(): # Create a client - client = dataflow_v1beta3.TemplatesServiceClient() + client = dataflow_v1beta3.TemplatesServiceAsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.LaunchTemplateRequest( @@ -296,7 +307,7 @@ def sample_launch_template(): ) # Make the request - response = client.launch_template(request=request) + response = await client.launch_template(request=request) # Handle the response print(response) @@ -327,6 +338,17 @@ def sample_launch_template(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = await rpc( request, @@ -352,9 +374,9 @@ async def get_template( from google.cloud import dataflow_v1beta3 - def sample_get_template(): + async def sample_get_template(): # Create a client - client = dataflow_v1beta3.TemplatesServiceClient() + client = dataflow_v1beta3.TemplatesServiceAsyncClient() # Initialize request argument(s) request = dataflow_v1beta3.GetTemplateRequest( @@ -362,7 +384,7 @@ def sample_get_template(): ) # Make the request - response = client.get_template(request=request) + response = await client.get_template(request=request) # Handle the response print(response) @@ -394,6 +416,17 @@ def sample_get_template(): 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( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/client.py index 9125ccdadda5..1e26fe62fec3 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/client.py @@ -466,6 +466,17 @@ def sample_create_job_from_template(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_job_from_template] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = rpc( request, @@ -533,6 +544,17 @@ def sample_launch_template(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.launch_template] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = rpc( request, @@ -601,6 +623,17 @@ def sample_get_template(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_template] + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", request.project_id), + ("location", request.location), + ) + ), + ) + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py index 6d6a20b161c7..220ac9d559fa 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py @@ -759,6 +759,73 @@ async def test_launch_flex_template_async_from_dict(): await test_launch_flex_template_async(request_type=dict) +def test_launch_flex_template_field_headers(): + client = FlexTemplatesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = templates.LaunchFlexTemplateRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.launch_flex_template), "__call__" + ) as call: + call.return_value = templates.LaunchFlexTemplateResponse() + client.launch_flex_template(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_launch_flex_template_field_headers_async(): + client = FlexTemplatesServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = templates.LaunchFlexTemplateRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.launch_flex_template), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + templates.LaunchFlexTemplateResponse() + ) + await client.launch_flex_template(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.FlexTemplatesServiceGrpcTransport( diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py index e0bb639c9a7d..1f06d788347b 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py @@ -770,6 +770,67 @@ async def test_create_job_async_from_dict(): await test_create_job_async(request_type=dict) +def test_create_job_field_headers(): + client = JobsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.CreateJobRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_job), "__call__") as call: + call.return_value = jobs.Job() + client.create_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_job_field_headers_async(): + client = JobsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.CreateJobRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_job), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(jobs.Job()) + await client.create_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + @pytest.mark.parametrize( "request_type", [ @@ -911,6 +972,69 @@ async def test_get_job_async_from_dict(): await test_get_job_async(request_type=dict) +def test_get_job_field_headers(): + client = JobsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.GetJobRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_job), "__call__") as call: + call.return_value = jobs.Job() + client.get_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_job_field_headers_async(): + client = JobsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.GetJobRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_job), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(jobs.Job()) + await client.get_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + @pytest.mark.parametrize( "request_type", [ @@ -1052,6 +1176,69 @@ async def test_update_job_async_from_dict(): await test_update_job_async(request_type=dict) +def test_update_job_field_headers(): + client = JobsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.UpdateJobRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_job), "__call__") as call: + call.return_value = jobs.Job() + client.update_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_job_field_headers_async(): + client = JobsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.UpdateJobRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_job), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(jobs.Job()) + await client.update_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + @pytest.mark.parametrize( "request_type", [ @@ -1141,6 +1328,69 @@ async def test_list_jobs_async_from_dict(): await test_list_jobs_async(request_type=dict) +def test_list_jobs_field_headers(): + client = JobsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.ListJobsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_jobs), "__call__") as call: + call.return_value = jobs.ListJobsResponse() + client.list_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_jobs_field_headers_async(): + client = JobsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.ListJobsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_jobs), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + jobs.ListJobsResponse() + ) + await client.list_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + def test_list_jobs_pager(transport_name: str = "grpc"): client = JobsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials, @@ -1179,11 +1429,19 @@ def test_list_jobs_pager(transport_name: str = "grpc"): ) metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", ""), + ("location", ""), + ) + ), + ) pager = client.list_jobs(request={}) assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, jobs.Job) for i in results) @@ -1421,6 +1679,71 @@ async def test_aggregated_list_jobs_async_from_dict(): await test_aggregated_list_jobs_async(request_type=dict) +def test_aggregated_list_jobs_field_headers(): + client = JobsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.ListJobsRequest() + + request.project_id = "project_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.aggregated_list_jobs), "__call__" + ) as call: + call.return_value = jobs.ListJobsResponse() + client.aggregated_list_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_aggregated_list_jobs_field_headers_async(): + client = JobsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.ListJobsRequest() + + request.project_id = "project_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.aggregated_list_jobs), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + jobs.ListJobsResponse() + ) + await client.aggregated_list_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value", + ) in kw["metadata"] + + def test_aggregated_list_jobs_pager(transport_name: str = "grpc"): client = JobsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials, @@ -1461,11 +1784,14 @@ def test_aggregated_list_jobs_pager(transport_name: str = "grpc"): ) metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("project_id", ""),)), + ) pager = client.aggregated_list_jobs(request={}) assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, jobs.Job) for i in results) @@ -1822,6 +2148,69 @@ async def test_snapshot_job_async_from_dict(): await test_snapshot_job_async(request_type=dict) +def test_snapshot_job_field_headers(): + client = JobsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.SnapshotJobRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.snapshot_job), "__call__") as call: + call.return_value = snapshots.Snapshot() + client.snapshot_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_snapshot_job_field_headers_async(): + client = JobsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = jobs.SnapshotJobRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.snapshot_job), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(snapshots.Snapshot()) + await client.snapshot_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.JobsV1Beta3GrpcTransport( diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py index d8e1023258e5..35c5396585e1 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py @@ -758,6 +758,75 @@ async def test_list_job_messages_async_from_dict(): await test_list_job_messages_async(request_type=dict) +def test_list_job_messages_field_headers(): + client = MessagesV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = messages.ListJobMessagesRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_job_messages), "__call__" + ) as call: + call.return_value = messages.ListJobMessagesResponse() + client.list_job_messages(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_job_messages_field_headers_async(): + client = MessagesV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = messages.ListJobMessagesRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_job_messages), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + messages.ListJobMessagesResponse() + ) + await client.list_job_messages(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + def test_list_job_messages_pager(transport_name: str = "grpc"): client = MessagesV1Beta3Client( credentials=ga_credentials.AnonymousCredentials, @@ -798,11 +867,20 @@ def test_list_job_messages_pager(transport_name: str = "grpc"): ) metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", ""), + ("location", ""), + ("job_id", ""), + ) + ), + ) pager = client.list_job_messages(request={}) assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, messages.JobMessage) for i in results) diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py index 2d03d8dbb336..f431d9118605 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py @@ -734,6 +734,69 @@ async def test_get_job_metrics_async_from_dict(): await test_get_job_metrics_async(request_type=dict) +def test_get_job_metrics_field_headers(): + client = MetricsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metrics.GetJobMetricsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_job_metrics), "__call__") as call: + call.return_value = metrics.JobMetrics() + client.get_job_metrics(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_job_metrics_field_headers_async(): + client = MetricsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metrics.GetJobMetricsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_job_metrics), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(metrics.JobMetrics()) + await client.get_job_metrics(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + @pytest.mark.parametrize( "request_type", [ @@ -829,6 +892,75 @@ async def test_get_job_execution_details_async_from_dict(): await test_get_job_execution_details_async(request_type=dict) +def test_get_job_execution_details_field_headers(): + client = MetricsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metrics.GetJobExecutionDetailsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_job_execution_details), "__call__" + ) as call: + call.return_value = metrics.JobExecutionDetails() + client.get_job_execution_details(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_job_execution_details_field_headers_async(): + client = MetricsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metrics.GetJobExecutionDetailsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_job_execution_details), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metrics.JobExecutionDetails() + ) + await client.get_job_execution_details(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + def test_get_job_execution_details_pager(transport_name: str = "grpc"): client = MetricsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials, @@ -869,11 +1001,20 @@ def test_get_job_execution_details_pager(transport_name: str = "grpc"): ) metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", ""), + ("location", ""), + ("job_id", ""), + ) + ), + ) pager = client.get_job_execution_details(request={}) assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, metrics.StageSummary) for i in results) @@ -1118,6 +1259,77 @@ async def test_get_stage_execution_details_async_from_dict(): await test_get_stage_execution_details_async(request_type=dict) +def test_get_stage_execution_details_field_headers(): + client = MetricsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metrics.GetStageExecutionDetailsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + request.stage_id = "stage_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_stage_execution_details), "__call__" + ) as call: + call.return_value = metrics.StageExecutionDetails() + client.get_stage_execution_details(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value&stage_id=stage_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_stage_execution_details_field_headers_async(): + client = MetricsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metrics.GetStageExecutionDetailsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + request.stage_id = "stage_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_stage_execution_details), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metrics.StageExecutionDetails() + ) + await client.get_stage_execution_details(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value&stage_id=stage_id_value", + ) in kw["metadata"] + + def test_get_stage_execution_details_pager(transport_name: str = "grpc"): client = MetricsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials, @@ -1158,11 +1370,21 @@ def test_get_stage_execution_details_pager(transport_name: str = "grpc"): ) metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ("project_id", ""), + ("location", ""), + ("job_id", ""), + ("stage_id", ""), + ) + ), + ) pager = client.get_stage_execution_details(request={}) assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, metrics.WorkerDetails) for i in results) diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py index a6add29e72e4..11ee5cd4783f 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py @@ -777,6 +777,69 @@ async def test_get_snapshot_async_from_dict(): await test_get_snapshot_async(request_type=dict) +def test_get_snapshot_field_headers(): + client = SnapshotsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = snapshots.GetSnapshotRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.snapshot_id = "snapshot_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: + call.return_value = snapshots.Snapshot() + client.get_snapshot(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&snapshot_id=snapshot_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_snapshot_field_headers_async(): + client = SnapshotsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = snapshots.GetSnapshotRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.snapshot_id = "snapshot_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(snapshots.Snapshot()) + await client.get_snapshot(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&snapshot_id=snapshot_id_value", + ) in kw["metadata"] + + @pytest.mark.parametrize( "request_type", [ @@ -860,6 +923,71 @@ async def test_delete_snapshot_async_from_dict(): await test_delete_snapshot_async(request_type=dict) +def test_delete_snapshot_field_headers(): + client = SnapshotsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = snapshots.DeleteSnapshotRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.snapshot_id = "snapshot_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: + call.return_value = snapshots.DeleteSnapshotResponse() + client.delete_snapshot(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&snapshot_id=snapshot_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_snapshot_field_headers_async(): + client = SnapshotsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = snapshots.DeleteSnapshotRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.snapshot_id = "snapshot_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + snapshots.DeleteSnapshotResponse() + ) + await client.delete_snapshot(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&snapshot_id=snapshot_id_value", + ) in kw["metadata"] + + @pytest.mark.parametrize( "request_type", [ @@ -943,6 +1071,71 @@ async def test_list_snapshots_async_from_dict(): await test_list_snapshots_async(request_type=dict) +def test_list_snapshots_field_headers(): + client = SnapshotsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = snapshots.ListSnapshotsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: + call.return_value = snapshots.ListSnapshotsResponse() + client.list_snapshots(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_snapshots_field_headers_async(): + client = SnapshotsV1Beta3AsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = snapshots.ListSnapshotsRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + request.job_id = "job_id_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + snapshots.ListSnapshotsResponse() + ) + await client.list_snapshots(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value&job_id=job_id_value", + ) in kw["metadata"] + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SnapshotsV1Beta3GrpcTransport( diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py index cfaf6f735c09..ba480bbfe8ba 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py @@ -811,6 +811,71 @@ async def test_create_job_from_template_async_from_dict(): await test_create_job_from_template_async(request_type=dict) +def test_create_job_from_template_field_headers(): + client = TemplatesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = templates.CreateJobFromTemplateRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_job_from_template), "__call__" + ) as call: + call.return_value = jobs.Job() + client.create_job_from_template(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_job_from_template_field_headers_async(): + client = TemplatesServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = templates.CreateJobFromTemplateRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_job_from_template), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(jobs.Job()) + await client.create_job_from_template(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + @pytest.mark.parametrize( "request_type", [ @@ -894,6 +959,69 @@ async def test_launch_template_async_from_dict(): await test_launch_template_async(request_type=dict) +def test_launch_template_field_headers(): + client = TemplatesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = templates.LaunchTemplateRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.launch_template), "__call__") as call: + call.return_value = templates.LaunchTemplateResponse() + client.launch_template(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_launch_template_field_headers_async(): + client = TemplatesServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = templates.LaunchTemplateRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.launch_template), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + templates.LaunchTemplateResponse() + ) + await client.launch_template(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + @pytest.mark.parametrize( "request_type", [ @@ -983,6 +1111,69 @@ async def test_get_template_async_from_dict(): await test_get_template_async(request_type=dict) +def test_get_template_field_headers(): + client = TemplatesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = templates.GetTemplateRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_template), "__call__") as call: + call.return_value = templates.GetTemplateResponse() + client.get_template(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_template_field_headers_async(): + client = TemplatesServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = templates.GetTemplateRequest() + + request.project_id = "project_id_value" + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_template), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + templates.GetTemplateResponse() + ) + await client.get_template(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "project_id=project_id_value&location=location_value", + ) in kw["metadata"] + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.TemplatesServiceGrpcTransport(