From 97da647d0d7124f44ae581c7d847a1258db57839 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Thu, 11 Jun 2026 18:00:06 +0000 Subject: [PATCH] feat: update API sources and regenerate --- librarian.yaml | 4 +- .../iceberg_catalog_service/async_client.py | 79 +- .../iceberg_catalog_service/client.py | 116 +- .../transports/grpc.py | 40 +- .../transports/grpc_asyncio.py | 40 +- .../transports/rest.py | 37 +- .../biglake_v1/types/iceberg_rest_catalog.py | 482 +- ...og_service_create_iceberg_catalog_async.py | 2 +- ...log_service_create_iceberg_catalog_sync.py | 2 +- ...og_service_update_iceberg_catalog_async.py | 2 +- ...log_service_update_iceberg_catalog_sync.py | 2 +- ...ppet_metadata_google.cloud.biglake.v1.json | 8 + .../test_iceberg_catalog_service.py | 296 +- .../filters/filter_snippets_async_test.py | 4 +- .../samples/snippets/reads/read_snippets.py | 1 + .../samples/testdata/singer_pb2.py | 15 + .../google/cloud/network_services/__init__.py | 18 + .../cloud/network_services_v1/__init__.py | 18 + .../network_services_v1/gapic_metadata.json | 75 + .../services/dep_service/async_client.py | 10 - .../services/dep_service/client.py | 10 - .../services/network_services/async_client.py | 723 +- .../services/network_services/client.py | 744 +- .../services/network_services/pagers.py | 157 + .../network_services/transports/base.py | 75 + .../network_services/transports/grpc.py | 140 + .../transports/grpc_asyncio.py | 171 + .../network_services/transports/rest.py | 1421 +- .../network_services/transports/rest_base.py | 259 + .../network_services_v1/types/__init__.py | 18 + .../types/agent_gateway.py | 515 + .../cloud/network_services_v1/types/common.py | 6 +- .../cloud/network_services_v1/types/dep.py | 162 +- .../types/endpoint_policy.py | 12 +- .../types/extensibility.py | 143 +- .../network_services_v1/types/gateway.py | 19 +- .../network_services_v1/types/grpc_route.py | 14 +- .../network_services_v1/types/http_route.py | 27 +- .../cloud/network_services_v1/types/mesh.py | 10 +- .../network_services_v1/types/tcp_route.py | 14 +- .../network_services_v1/types/tls_route.py | 25 +- ...ep_service_create_authz_extension_async.py | 2 - ...dep_service_create_authz_extension_sync.py | 2 - ..._service_create_lb_edge_extension_async.py | 1 - ...p_service_create_lb_edge_extension_sync.py | 1 - ...service_create_lb_route_extension_async.py | 1 - ..._service_create_lb_route_extension_sync.py | 1 - ...rvice_create_lb_traffic_extension_async.py | 1 - ...ervice_create_lb_traffic_extension_sync.py | 1 - ...ep_service_update_authz_extension_async.py | 2 - ...dep_service_update_authz_extension_sync.py | 2 - ..._service_update_lb_edge_extension_async.py | 1 - ...p_service_update_lb_edge_extension_sync.py | 1 - ...service_update_lb_route_extension_async.py | 1 - ..._service_update_lb_route_extension_sync.py | 1 - ...rvice_update_lb_traffic_extension_async.py | 1 - ...ervice_update_lb_traffic_extension_sync.py | 1 - ...ork_services_create_agent_gateway_async.py | 58 + ...work_services_create_agent_gateway_sync.py | 58 + ...ork_services_delete_agent_gateway_async.py | 57 + ...work_services_delete_agent_gateway_sync.py | 57 + ...etwork_services_get_agent_gateway_async.py | 53 + ...network_services_get_agent_gateway_sync.py | 53 + ...work_services_list_agent_gateways_async.py | 54 + ...twork_services_list_agent_gateways_sync.py | 54 + ...ork_services_update_agent_gateway_async.py | 55 + ...work_services_update_agent_gateway_sync.py | 55 + ...adata_google.cloud.networkservices.v1.json | 1349 +- .../network_services_v1/test_dep_service.py | 57 + .../test_network_services.py | 20730 ++++++++++------ 70 files changed, 19654 insertions(+), 8972 deletions(-) create mode 100644 packages/google-cloud-network-services/google/cloud/network_services_v1/types/agent_gateway.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_create_agent_gateway_async.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_create_agent_gateway_sync.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_delete_agent_gateway_async.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_delete_agent_gateway_sync.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_get_agent_gateway_async.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_get_agent_gateway_sync.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_list_agent_gateways_async.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_list_agent_gateways_sync.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_update_agent_gateway_async.py create mode 100644 packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_update_agent_gateway_sync.py diff --git a/librarian.yaml b/librarian.yaml index 9d89020f6cbe..8a14680e872a 100644 --- a/librarian.yaml +++ b/librarian.yaml @@ -16,8 +16,8 @@ version: v0.19.0 repo: googleapis/google-cloud-python sources: googleapis: - commit: d8daa97972d091191898915589335cef66fcdc8a - sha256: 7dbdf2b1b667fe57128d41c77e530a2541767772cfe3487713f29b7b25d9f5ad + commit: f93e046328794785ad89869f00c0358dfcff2c35 + sha256: 415249f584d57e5a2298c36ae9ff71563403112dee04ac961023a1b0098404d2 default: output: packages tag_format: '{name}-v{version}' diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/async_client.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/async_client.py index 098c2af83bd2..eee3ae1e82ef 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/async_client.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/async_client.py @@ -65,34 +65,15 @@ class IcebergCatalogServiceAsyncClient: - """Iceberg Catalog Service API: this implements the open-source Iceberg - REST Catalog API. See the API definition here: - https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml - - The API is defined as OpenAPI 3.1.1 spec. - - Currently we only support the following methods: - - - GetConfig/GetIcebergCatalogConfig - - ListIcebergNamespaces - - CheckIcebergNamespaceExists - - GetIcebergNamespace - - CreateIcebergNamespace (only supports single level) - - DeleteIcebergNamespace - - UpdateIcebergNamespace properties - - ListTableIdentifiers - - CreateIcebergTable - - DeleteIcebergTable - - GetIcebergTable - - UpdateIcebergTable (CommitTable) - - LoadIcebergTableCredentials - - RegisterTable - - Users are required to provided the ``X-Goog-User-Project`` header - with the project id or number which can be different from the bucket - project id. That project will be charged for the API calls and the - calling user must have access to that project. The caller must have - ``serviceusage.services.use`` permission on the project. + """Lakehouse runtime catalog supports the following catalog + management methods: + + - GetIcebergCatalog + - ListIcebergCatalogs + - DeleteIcebergCatalog + - UpdateIcebergCatalog + - CreateIcebergCatalog + - FailoverIcebergCatalog """ _client: IcebergCatalogServiceClient @@ -106,6 +87,10 @@ class IcebergCatalogServiceAsyncClient: catalog_path = staticmethod(IcebergCatalogServiceClient.catalog_path) parse_catalog_path = staticmethod(IcebergCatalogServiceClient.parse_catalog_path) + secret_path = staticmethod(IcebergCatalogServiceClient.secret_path) + parse_secret_path = staticmethod(IcebergCatalogServiceClient.parse_secret_path) + service_path = staticmethod(IcebergCatalogServiceClient.service_path) + parse_service_path = staticmethod(IcebergCatalogServiceClient.parse_service_path) common_billing_account_path = staticmethod( IcebergCatalogServiceClient.common_billing_account_path ) @@ -599,7 +584,7 @@ async def sample_update_iceberg_catalog(): # Initialize request argument(s) iceberg_catalog = biglake_v1.IcebergCatalog() - iceberg_catalog.catalog_type = "CATALOG_TYPE_GCS_BUCKET" + iceberg_catalog.catalog_type = "CATALOG_TYPE_FEDERATED" request = biglake_v1.UpdateIcebergCatalogRequest( iceberg_catalog=iceberg_catalog, @@ -701,12 +686,12 @@ async def create_iceberg_catalog( parent: Optional[str] = None, iceberg_catalog: Optional[iceberg_rest_catalog.IcebergCatalog] = None, iceberg_catalog_id: Optional[str] = None, + primary_location: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iceberg_rest_catalog.IcebergCatalog: - r"""Creates the Iceberg REST Catalog. Currently only supports Google - Cloud Storage Bucket catalogs. Google Cloud Storage Bucket + r"""Creates the Iceberg REST Catalog. Google Cloud Storage Bucket catalog id is the bucket for which the catalog is created (e.g. ``my-catalog`` for ``gs://my-catalog``). @@ -730,7 +715,7 @@ async def sample_create_iceberg_catalog(): # Initialize request argument(s) iceberg_catalog = biglake_v1.IcebergCatalog() - iceberg_catalog.catalog_type = "CATALOG_TYPE_GCS_BUCKET" + iceberg_catalog.catalog_type = "CATALOG_TYPE_FEDERATED" request = biglake_v1.CreateIcebergCatalogRequest( parent="parent_value", @@ -770,6 +755,27 @@ async def sample_create_iceberg_catalog(): This corresponds to the ``iceberg_catalog_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + primary_location (:class:`str`): + Optional. The primary location where the catalog + metadata will be stored. + + For Google Cloud Storage bucket catalogs and BigLake + catalogs, if this is not specified, then the region is + inferred from the bucket's region (``default_location`` + bucket for BigLake catalogs). If specified, the region + must be in jurisdiction (near the ``default_location`` + bucket's region and the ``restricted_locations`` + buckets' regions for BigLake catalogs). + + For federated catalogs, this must be specified and be a + Lakehouse-supported location + (https://docs.cloud.google.com/lakehouse/docs/locations). + It should be close to the remote catalog's location for + the best performance and cost. + + This corresponds to the ``primary_location`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -785,7 +791,12 @@ async def sample_create_iceberg_catalog(): # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - flattened_params = [parent, iceberg_catalog, iceberg_catalog_id] + flattened_params = [ + parent, + iceberg_catalog, + iceberg_catalog_id, + primary_location, + ] has_flattened_params = ( len([param for param in flattened_params if param is not None]) > 0 ) @@ -808,6 +819,8 @@ async def sample_create_iceberg_catalog(): request.iceberg_catalog = iceberg_catalog if iceberg_catalog_id is not None: request.iceberg_catalog_id = iceberg_catalog_id + if primary_location is not None: + request.primary_location = primary_location # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/client.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/client.py index cd136f108736..a1ebe3212e7d 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/client.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/client.py @@ -109,34 +109,15 @@ def get_transport_class( class IcebergCatalogServiceClient(metaclass=IcebergCatalogServiceClientMeta): - """Iceberg Catalog Service API: this implements the open-source Iceberg - REST Catalog API. See the API definition here: - https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml - - The API is defined as OpenAPI 3.1.1 spec. - - Currently we only support the following methods: - - - GetConfig/GetIcebergCatalogConfig - - ListIcebergNamespaces - - CheckIcebergNamespaceExists - - GetIcebergNamespace - - CreateIcebergNamespace (only supports single level) - - DeleteIcebergNamespace - - UpdateIcebergNamespace properties - - ListTableIdentifiers - - CreateIcebergTable - - DeleteIcebergTable - - GetIcebergTable - - UpdateIcebergTable (CommitTable) - - LoadIcebergTableCredentials - - RegisterTable - - Users are required to provided the ``X-Goog-User-Project`` header - with the project id or number which can be different from the bucket - project id. That project will be charged for the API calls and the - calling user must have access to that project. The caller must have - ``serviceusage.services.use`` permission on the project. + """Lakehouse runtime catalog supports the following catalog + management methods: + + - GetIcebergCatalog + - ListIcebergCatalogs + - DeleteIcebergCatalog + - UpdateIcebergCatalog + - CreateIcebergCatalog + - FailoverIcebergCatalog """ @staticmethod @@ -274,6 +255,47 @@ def parse_catalog_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/catalogs/(?P.+?)$", path) return m.groupdict() if m else {} + @staticmethod + def secret_path( + project: str, + secret: str, + ) -> str: + """Returns a fully-qualified secret string.""" + return "projects/{project}/secrets/{secret}".format( + project=project, + secret=secret, + ) + + @staticmethod + def parse_secret_path(path: str) -> Dict[str, str]: + """Parses a secret path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/secrets/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def service_path( + project: str, + location: str, + namespace: str, + service: str, + ) -> str: + """Returns a fully-qualified service string.""" + return "projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}".format( + project=project, + location=location, + namespace=namespace, + service=service, + ) + + @staticmethod + def parse_service_path(path: str) -> Dict[str, str]: + """Parses a service path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/namespaces/(?P.+?)/services/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def common_billing_account_path( billing_account: str, @@ -1021,7 +1043,7 @@ def sample_update_iceberg_catalog(): # Initialize request argument(s) iceberg_catalog = biglake_v1.IcebergCatalog() - iceberg_catalog.catalog_type = "CATALOG_TYPE_GCS_BUCKET" + iceberg_catalog.catalog_type = "CATALOG_TYPE_FEDERATED" request = biglake_v1.UpdateIcebergCatalogRequest( iceberg_catalog=iceberg_catalog, @@ -1120,12 +1142,12 @@ def create_iceberg_catalog( parent: Optional[str] = None, iceberg_catalog: Optional[iceberg_rest_catalog.IcebergCatalog] = None, iceberg_catalog_id: Optional[str] = None, + primary_location: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iceberg_rest_catalog.IcebergCatalog: - r"""Creates the Iceberg REST Catalog. Currently only supports Google - Cloud Storage Bucket catalogs. Google Cloud Storage Bucket + r"""Creates the Iceberg REST Catalog. Google Cloud Storage Bucket catalog id is the bucket for which the catalog is created (e.g. ``my-catalog`` for ``gs://my-catalog``). @@ -1149,7 +1171,7 @@ def sample_create_iceberg_catalog(): # Initialize request argument(s) iceberg_catalog = biglake_v1.IcebergCatalog() - iceberg_catalog.catalog_type = "CATALOG_TYPE_GCS_BUCKET" + iceberg_catalog.catalog_type = "CATALOG_TYPE_FEDERATED" request = biglake_v1.CreateIcebergCatalogRequest( parent="parent_value", @@ -1189,6 +1211,27 @@ def sample_create_iceberg_catalog(): This corresponds to the ``iceberg_catalog_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + primary_location (str): + Optional. The primary location where the catalog + metadata will be stored. + + For Google Cloud Storage bucket catalogs and BigLake + catalogs, if this is not specified, then the region is + inferred from the bucket's region (``default_location`` + bucket for BigLake catalogs). If specified, the region + must be in jurisdiction (near the ``default_location`` + bucket's region and the ``restricted_locations`` + buckets' regions for BigLake catalogs). + + For federated catalogs, this must be specified and be a + Lakehouse-supported location + (https://docs.cloud.google.com/lakehouse/docs/locations). + It should be close to the remote catalog's location for + the best performance and cost. + + This corresponds to the ``primary_location`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1204,7 +1247,12 @@ def sample_create_iceberg_catalog(): # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - flattened_params = [parent, iceberg_catalog, iceberg_catalog_id] + flattened_params = [ + parent, + iceberg_catalog, + iceberg_catalog_id, + primary_location, + ] has_flattened_params = ( len([param for param in flattened_params if param is not None]) > 0 ) @@ -1226,6 +1274,8 @@ def sample_create_iceberg_catalog(): request.iceberg_catalog = iceberg_catalog if iceberg_catalog_id is not None: request.iceberg_catalog_id = iceberg_catalog_id + if primary_location is not None: + request.primary_location = primary_location # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc.py index 909305ed8c3e..bbae138cc8f0 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc.py @@ -110,34 +110,15 @@ def intercept_unary_unary(self, continuation, client_call_details, request): class IcebergCatalogServiceGrpcTransport(IcebergCatalogServiceTransport): """gRPC backend transport for IcebergCatalogService. - Iceberg Catalog Service API: this implements the open-source Iceberg - REST Catalog API. See the API definition here: - https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml - - The API is defined as OpenAPI 3.1.1 spec. - - Currently we only support the following methods: - - - GetConfig/GetIcebergCatalogConfig - - ListIcebergNamespaces - - CheckIcebergNamespaceExists - - GetIcebergNamespace - - CreateIcebergNamespace (only supports single level) - - DeleteIcebergNamespace - - UpdateIcebergNamespace properties - - ListTableIdentifiers - - CreateIcebergTable - - DeleteIcebergTable - - GetIcebergTable - - UpdateIcebergTable (CommitTable) - - LoadIcebergTableCredentials - - RegisterTable - - Users are required to provided the ``X-Goog-User-Project`` header - with the project id or number which can be different from the bucket - project id. That project will be charged for the API calls and the - calling user must have access to that project. The caller must have - ``serviceusage.services.use`` permission on the project. + Lakehouse runtime catalog supports the following catalog + management methods: + + - GetIcebergCatalog + - ListIcebergCatalogs + - DeleteIcebergCatalog + - UpdateIcebergCatalog + - CreateIcebergCatalog + - FailoverIcebergCatalog This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -450,8 +431,7 @@ def create_iceberg_catalog( ]: r"""Return a callable for the create iceberg catalog method over gRPC. - Creates the Iceberg REST Catalog. Currently only supports Google - Cloud Storage Bucket catalogs. Google Cloud Storage Bucket + Creates the Iceberg REST Catalog. Google Cloud Storage Bucket catalog id is the bucket for which the catalog is created (e.g. ``my-catalog`` for ``gs://my-catalog``). diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc_asyncio.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc_asyncio.py index cab40d9a33c7..87a1b81b8599 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc_asyncio.py @@ -116,34 +116,15 @@ async def intercept_unary_unary(self, continuation, client_call_details, request class IcebergCatalogServiceGrpcAsyncIOTransport(IcebergCatalogServiceTransport): """gRPC AsyncIO backend transport for IcebergCatalogService. - Iceberg Catalog Service API: this implements the open-source Iceberg - REST Catalog API. See the API definition here: - https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml - - The API is defined as OpenAPI 3.1.1 spec. - - Currently we only support the following methods: - - - GetConfig/GetIcebergCatalogConfig - - ListIcebergNamespaces - - CheckIcebergNamespaceExists - - GetIcebergNamespace - - CreateIcebergNamespace (only supports single level) - - DeleteIcebergNamespace - - UpdateIcebergNamespace properties - - ListTableIdentifiers - - CreateIcebergTable - - DeleteIcebergTable - - GetIcebergTable - - UpdateIcebergTable (CommitTable) - - LoadIcebergTableCredentials - - RegisterTable - - Users are required to provided the ``X-Goog-User-Project`` header - with the project id or number which can be different from the bucket - project id. That project will be charged for the API calls and the - calling user must have access to that project. The caller must have - ``serviceusage.services.use`` permission on the project. + Lakehouse runtime catalog supports the following catalog + management methods: + + - GetIcebergCatalog + - ListIcebergCatalogs + - DeleteIcebergCatalog + - UpdateIcebergCatalog + - CreateIcebergCatalog + - FailoverIcebergCatalog This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -458,8 +439,7 @@ def create_iceberg_catalog( ]: r"""Return a callable for the create iceberg catalog method over gRPC. - Creates the Iceberg REST Catalog. Currently only supports Google - Cloud Storage Bucket catalogs. Google Cloud Storage Bucket + Creates the Iceberg REST Catalog. Google Cloud Storage Bucket catalog id is the bucket for which the catalog is created (e.g. ``my-catalog`` for ``gs://my-catalog``). diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/rest.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/rest.py index 32c2ab3e7df9..b54f7873effc 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/rest.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/rest.py @@ -386,34 +386,15 @@ class IcebergCatalogServiceRestStub: class IcebergCatalogServiceRestTransport(_BaseIcebergCatalogServiceRestTransport): """REST backend synchronous transport for IcebergCatalogService. - Iceberg Catalog Service API: this implements the open-source Iceberg - REST Catalog API. See the API definition here: - https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml - - The API is defined as OpenAPI 3.1.1 spec. - - Currently we only support the following methods: - - - GetConfig/GetIcebergCatalogConfig - - ListIcebergNamespaces - - CheckIcebergNamespaceExists - - GetIcebergNamespace - - CreateIcebergNamespace (only supports single level) - - DeleteIcebergNamespace - - UpdateIcebergNamespace properties - - ListTableIdentifiers - - CreateIcebergTable - - DeleteIcebergTable - - GetIcebergTable - - UpdateIcebergTable (CommitTable) - - LoadIcebergTableCredentials - - RegisterTable - - Users are required to provided the ``X-Goog-User-Project`` header - with the project id or number which can be different from the bucket - project id. That project will be charged for the API calls and the - calling user must have access to that project. The caller must have - ``serviceusage.services.use`` permission on the project. + Lakehouse runtime catalog supports the following catalog + management methods: + + - GetIcebergCatalog + - ListIcebergCatalogs + - DeleteIcebergCatalog + - UpdateIcebergCatalog + - CreateIcebergCatalog + - FailoverIcebergCatalog This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/types/iceberg_rest_catalog.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/types/iceberg_rest_catalog.py index 0586927a4db2..662fe1644135 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/types/iceberg_rest_catalog.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/types/iceberg_rest_catalog.py @@ -17,8 +17,10 @@ from typing import MutableMapping, MutableSequence +import google.protobuf.duration_pb2 as duration_pb2 # type: ignore import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore +import google.rpc.status_pb2 as status_pb2 # type: ignore import proto # type: ignore __protobuf__ = proto.module( @@ -54,25 +56,64 @@ class IcebergCatalog(proto.Message): Output only. The service account used for credential vending, output only. Might be empty if Credential vending was never enabled for the - catalog. + catalog. For federated catalogs, the service + account will be always provisioned and will be + used to access the remote Iceberg REST Catalog + using access to Secret Manager secret or + identity federation. + biglake_service_account_unique_id (str): + Output only. The unique ID of the service + account. This is used for federation scenarios. catalog_type (google.cloud.biglake_v1.types.IcebergCatalog.CatalogType): Required. The catalog type. Required for CreateIcebergCatalog. default_location (str): - Optional. The default location for the - catalog. For the Google Cloud Storage Bucket - catalog this is output only. - catalog_regions (MutableSequence[str]): - Output only. The GCP region(s) where the - catalog metadata is stored. This will contain - one value for all locations, except for the - catalogs that are configured to use custom dual - region buckets. + Optional. The default storage location for the catalog, + e.g., ``gs://my-bucket``. For Google Cloud Storage bucket + catalogs, this is output only. + + For BigLake catalogs, this field must be provided and point + to a Google Cloud Storage bucket or a path within that + bucket. This path serves as the base directory for + constructing the full path to a table's data and metadata + directories when a location is not specified at the + namespace or table level. The full path is formed by + appending the namespace and table identifiers to the default + location. + storage_regions (MutableSequence[str]): + Output only. The GCP region(s) of the default location's + bucket, e.g. ``us-central1``, ``nam4`` or ``us``. This will + contain one value for all locations, except for the catalogs + that are configured to use custom dual region buckets, in + which case it will contain the two regions of the bucket. + The region(s) of this field should be in the jurisdiction of + or nearby the primary location of the catalog. create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. When the catalog was created. update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. When the catalog was last updated. + replicas (MutableSequence[google.cloud.biglake_v1.types.IcebergCatalog.Replica]): + Output only. The replicas for the catalog + metadata. + description (str): + Optional. A user-provided description of the + catalog. The description must be a UTF-8 string + with a maximum length of 1024 characters. + restricted_locations_config (google.cloud.biglake_v1.types.IcebergCatalog.RestrictedLocationsConfig): + Optional. Restricted locations configuration. This field is + currently only used for BigLake catalogs. + + If this field is unset, or if + ``restricted_locations_config.restricted_locations`` is + empty, all accessible locations are allowed. If + ``restricted_locations_config.restricted_locations`` is not + empty, only locations in ``default_location`` and + ``restricted_locations_config.restricted_locations`` are + allowed. + federated_catalog_options (google.cloud.biglake_v1.types.IcebergCatalog.FederatedCatalogOptions): + Optional. Configuration options for federated + catalogs. """ class CatalogType(proto.Enum): @@ -82,12 +123,17 @@ class CatalogType(proto.Enum): CATALOG_TYPE_UNSPECIFIED (0): Default value. This value is unused. CATALOG_TYPE_GCS_BUCKET (1): - Catalog type for Google Cloud Storage - Buckets. + Google Cloud Storage bucket catalog type. + CATALOG_TYPE_BIGLAKE (3): + BigLake catalog type. + CATALOG_TYPE_FEDERATED (4): + Federated catalog type. """ CATALOG_TYPE_UNSPECIFIED = 0 CATALOG_TYPE_GCS_BUCKET = 1 + CATALOG_TYPE_BIGLAKE = 3 + CATALOG_TYPE_FEDERATED = 4 class CredentialMode(proto.Enum): r"""The credential mode used for the catalog. @@ -119,6 +165,367 @@ class CredentialMode(proto.Enum): CREDENTIAL_MODE_END_USER = 1 CREDENTIAL_MODE_VENDED_CREDENTIALS = 2 + class Replica(proto.Message): + r"""The replica of the Catalog. + + Attributes: + region (str): + Output only. The region of the replica. For + example "us-east1". + state (google.cloud.biglake_v1.types.IcebergCatalog.Replica.State): + Output only. The current state of the + replica. + """ + + class State(proto.Enum): + r"""If the catalog is replicated to multiple regions, this enum + describes the current state of the replica. + + Values: + STATE_UNKNOWN (0): + The replica state is unknown. + STATE_PRIMARY (1): + The replica is the writable primary. + STATE_PRIMARY_IN_PROGRESS (2): + The replica has been recently assigned as the + primary, but not all namespaces are writeable + yet. + STATE_SECONDARY (3): + The replica is a read-only secondary replica. + """ + + STATE_UNKNOWN = 0 + STATE_PRIMARY = 1 + STATE_PRIMARY_IN_PROGRESS = 2 + STATE_SECONDARY = 3 + + region: str = proto.Field( + proto.STRING, + number=1, + ) + state: "IcebergCatalog.Replica.State" = proto.Field( + proto.ENUM, + number=2, + enum="IcebergCatalog.Replica.State", + ) + + class RestrictedLocationsConfig(proto.Message): + r"""Configuration of location restrictions. + + Attributes: + restricted_locations (MutableSequence[str]): + Optional. Additional Google Cloud Storage buckets and + locations (e.g., ``gs://my-other-bucket/...``) that are + permitted for use by resources within a catalog. This field + is currently only used for BigLake catalogs. + + If ``restricted_locations`` is empty and unrestricted + catalog creation is enabled, all accessible locations are + allowed. Otherwise, only ``default_location`` and locations + in this list are allowed. + """ + + restricted_locations: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=1, + ) + + class FederatedCatalogOptions(proto.Message): + r"""Configuration options for a federated catalog. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + unity_catalog_info (google.cloud.biglake_v1.types.IcebergCatalog.FederatedCatalogOptions.UnityCatalogInfo): + Optional. Info specific to a Unity Catalog by + Databricks. + + This field is a member of `oneof`_ ``remote_catalog_info``. + glue_catalog_info (google.cloud.biglake_v1.types.IcebergCatalog.FederatedCatalogOptions.GlueCatalogInfo): + Optional. Info specific to an AWS Glue + Catalog. + + This field is a member of `oneof`_ ``remote_catalog_info``. + secret_name (str): + Optional. The secret resource name in Secret Manager, in the + format + ``projects/{project_id}/locations/{location}/secrets/{secret_id}`` + or + ``projects/{project_id}/locations/{location}/secrets/{secret_id}/versions/{version_id}``. + + The project ID must match the catalog's project and location + must match the catalog's location. If the version is not + specified, the latest version will be used. + + This field is not used when + ``service_principal_application_id`` is set. + + This field is a member of `oneof`_ ``_secret_name``. + service_directory_name (str): + Optional. The service directory resource name for routing + traffic over a private network connection through + Cross-Cloud Interconnect, in the format + ``projects/{project_id}/locations/{location_id}/namespaces/{namespace_id}/services/{service_id}``. + + This field is a member of `oneof`_ ``_service_directory_name``. + refresh_options (google.cloud.biglake_v1.types.IcebergCatalog.FederatedCatalogOptions.RefreshOptions): + Optional. Refresh configuration. + refresh_status (google.cloud.biglake_v1.types.IcebergCatalog.FederatedCatalogOptions.RefreshStatus): + Output only. The status of the background + refresh operations. + """ + + class UnityCatalogInfo(proto.Message): + r"""Unity Catalog info. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + instance_name (str): + Required. The instance name is the first part + of the URL when logging into the Databricks + deployment. For example, for a Databricks on GCP + workspace URL https://1.1.gcp.databricks.com, + the instance name is 1.1.gcp.databricks.com. + + This field is a member of `oneof`_ ``_instance_name``. + catalog_name (str): + Required. The catalog name in Unity Catalog. + + This field is a member of `oneof`_ ``_catalog_name``. + service_principal_application_id (str): + Optional. The application ID of the Databricks service + principal that will be used to access the Unity Catalog in + the OIDC authentication flow. With OIDC, the secret_name + field is not used. + + This field is a member of `oneof`_ ``_service_principal_application_id``. + """ + + instance_name: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + catalog_name: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + service_principal_application_id: str = proto.Field( + proto.STRING, + number=3, + optional=True, + ) + + class GlueCatalogInfo(proto.Message): + r"""AWS Glue Catalog info. We support regional AWS Glue default + account catalog and S3 Table Buckets. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + warehouse (str): + Required. Immutable. The warehouse to connect to a regional + AWS Glue Iceberg REST Catalog. For top level access, use the + AWS account ID (e.g. 111222333444). For an S3 table bucket, + the warehouse is of the form: 111222333444:s3tablescatalog/. + The URL to access catalog will be + https://glue.{aws_region}.amazonaws.com/iceberg/v1?warehouse={warehouse}. + Must be non-empty and is immutable. + + This field is a member of `oneof`_ ``_warehouse``. + aws_region (str): + Required. Immutable. The AWS region of the + Glue catalog to connect to. The region should be + in the same geographical region and jurisdiction + as the federated catalog. + Must be non-empty and is immutable. + + This field is a member of `oneof`_ ``_aws_region``. + aws_role_arn (str): + Required. The AWS role ARN of the Glue + catalog that the federated catalog will assume + to access the catalog. Must be non-empty. Can be + updated. + + This field is a member of `oneof`_ ``_aws_role_arn``. + """ + + warehouse: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + aws_region: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + aws_role_arn: str = proto.Field( + proto.STRING, + number=3, + optional=True, + ) + + class RefreshSchedule(proto.Message): + r"""Schedule defines if and when metadata refresh should be + scheduled. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + refresh_interval (google.protobuf.duration_pb2.Duration): + Optional. The interval for refreshing + metadata from the remote catalog. If unset or if + the value is <= 0, the background refresh will + be disabled. If this field is updated for an + existing federated catalog, the previous + background refresh must complete before the new + refresh interval will take effect. + + This field is a member of `oneof`_ ``_refresh_interval``. + """ + + refresh_interval: duration_pb2.Duration = proto.Field( + proto.MESSAGE, + number=1, + optional=True, + message=duration_pb2.Duration, + ) + + class RefreshScope(proto.Message): + r"""The scope defines a subset of namespaces to be refreshed. + + Attributes: + namespace_filters (MutableSequence[str]): + Optional. Filters to determine which namespaces are included + in the refresh process. + + - empty list means include all namespaces. + - "[namespaces]" means include the specified namespaces. + ['ns1', 'ns2'] : Discover only namespaces 'ns1' and 'ns2'. + The maximum number of namespace filters allowed is 32. + """ + + namespace_filters: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=1, + ) + + class RefreshOptions(proto.Message): + r"""Refresh configuration. + + Attributes: + refresh_schedule (google.cloud.biglake_v1.types.IcebergCatalog.FederatedCatalogOptions.RefreshSchedule): + Optional. Schedule defines if and when + metadata refresh should be scheduled. + refresh_scope (google.cloud.biglake_v1.types.IcebergCatalog.FederatedCatalogOptions.RefreshScope): + Optional. Refresh scope configurations. + """ + + refresh_schedule: "IcebergCatalog.FederatedCatalogOptions.RefreshSchedule" = proto.Field( + proto.MESSAGE, + number=1, + message="IcebergCatalog.FederatedCatalogOptions.RefreshSchedule", + ) + refresh_scope: "IcebergCatalog.FederatedCatalogOptions.RefreshScope" = ( + proto.Field( + proto.MESSAGE, + number=2, + message="IcebergCatalog.FederatedCatalogOptions.RefreshScope", + ) + ) + + class RefreshStatus(proto.Message): + r"""Remote catalog background refresh status. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + start_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. When the catalog refresh has + started, including in-progress refreshes. + + This field is a member of `oneof`_ ``_start_time``. + end_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. When the catalog refresh has + ended, unset for in-progress refreshes. + + This field is a member of `oneof`_ ``_end_time``. + status (google.rpc.status_pb2.Status): + Output only. The status of the last + background refresh operation, unset for + in-progress refreshes. + + This field is a member of `oneof`_ ``_status``. + """ + + start_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=1, + optional=True, + message=timestamp_pb2.Timestamp, + ) + end_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=2, + optional=True, + message=timestamp_pb2.Timestamp, + ) + status: status_pb2.Status = proto.Field( + proto.MESSAGE, + number=3, + optional=True, + message=status_pb2.Status, + ) + + unity_catalog_info: "IcebergCatalog.FederatedCatalogOptions.UnityCatalogInfo" = proto.Field( + proto.MESSAGE, + number=2, + oneof="remote_catalog_info", + message="IcebergCatalog.FederatedCatalogOptions.UnityCatalogInfo", + ) + glue_catalog_info: "IcebergCatalog.FederatedCatalogOptions.GlueCatalogInfo" = ( + proto.Field( + proto.MESSAGE, + number=4, + oneof="remote_catalog_info", + message="IcebergCatalog.FederatedCatalogOptions.GlueCatalogInfo", + ) + ) + secret_name: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + service_directory_name: str = proto.Field( + proto.STRING, + number=5, + optional=True, + ) + refresh_options: "IcebergCatalog.FederatedCatalogOptions.RefreshOptions" = ( + proto.Field( + proto.MESSAGE, + number=3, + message="IcebergCatalog.FederatedCatalogOptions.RefreshOptions", + ) + ) + refresh_status: "IcebergCatalog.FederatedCatalogOptions.RefreshStatus" = ( + proto.Field( + proto.MESSAGE, + number=6, + message="IcebergCatalog.FederatedCatalogOptions.RefreshStatus", + ) + ) + name: str = proto.Field( proto.STRING, number=1, @@ -132,6 +539,10 @@ class CredentialMode(proto.Enum): proto.STRING, number=3, ) + biglake_service_account_unique_id: str = proto.Field( + proto.STRING, + number=14, + ) catalog_type: CatalogType = proto.Field( proto.ENUM, number=4, @@ -141,9 +552,9 @@ class CredentialMode(proto.Enum): proto.STRING, number=5, ) - catalog_regions: MutableSequence[str] = proto.RepeatedField( + storage_regions: MutableSequence[str] = proto.RepeatedField( proto.STRING, - number=6, + number=10, ) create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, @@ -155,6 +566,25 @@ class CredentialMode(proto.Enum): number=8, message=timestamp_pb2.Timestamp, ) + replicas: MutableSequence[Replica] = proto.RepeatedField( + proto.MESSAGE, + number=9, + message=Replica, + ) + description: str = proto.Field( + proto.STRING, + number=12, + ) + restricted_locations_config: RestrictedLocationsConfig = proto.Field( + proto.MESSAGE, + number=15, + message=RestrictedLocationsConfig, + ) + federated_catalog_options: FederatedCatalogOptions = proto.Field( + proto.MESSAGE, + number=13, + message=FederatedCatalogOptions, + ) class CreateIcebergCatalogRequest(proto.Message): @@ -172,6 +602,23 @@ class CreateIcebergCatalogRequest(proto.Message): - catalog_type. Optionally: credential_mode can be provided, if Credential Vending is desired. + primary_location (str): + Optional. The primary location where the catalog metadata + will be stored. + + For Google Cloud Storage bucket catalogs and BigLake + catalogs, if this is not specified, then the region is + inferred from the bucket's region (``default_location`` + bucket for BigLake catalogs). If specified, the region must + be in jurisdiction (near the ``default_location`` bucket's + region and the ``restricted_locations`` buckets' regions for + BigLake catalogs). + + For federated catalogs, this must be specified and be a + Lakehouse-supported location + (https://docs.cloud.google.com/lakehouse/docs/locations). It + should be close to the remote catalog's location for the + best performance and cost. """ parent: str = proto.Field( @@ -187,6 +634,10 @@ class CreateIcebergCatalogRequest(proto.Message): number=2, message="IcebergCatalog", ) + primary_location: str = proto.Field( + proto.STRING, + number=4, + ) class UpdateIcebergCatalogRequest(proto.Message): @@ -290,7 +741,8 @@ class ListIcebergCatalogsResponse(proto.Message): pagination. unreachable (MutableSequence[str]): Output only. The list of unreachable cloud - regions for router fanout. + regions. If non-empty, the result set might be + incomplete. """ @property diff --git a/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_create_iceberg_catalog_async.py b/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_create_iceberg_catalog_async.py index 8a751673904b..57e4bf36dfd8 100644 --- a/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_create_iceberg_catalog_async.py +++ b/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_create_iceberg_catalog_async.py @@ -40,7 +40,7 @@ async def sample_create_iceberg_catalog(): # Initialize request argument(s) iceberg_catalog = biglake_v1.IcebergCatalog() - iceberg_catalog.catalog_type = "CATALOG_TYPE_GCS_BUCKET" + iceberg_catalog.catalog_type = "CATALOG_TYPE_FEDERATED" request = biglake_v1.CreateIcebergCatalogRequest( parent="parent_value", diff --git a/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_create_iceberg_catalog_sync.py b/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_create_iceberg_catalog_sync.py index c32930d8200e..74e0b8e2077a 100644 --- a/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_create_iceberg_catalog_sync.py +++ b/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_create_iceberg_catalog_sync.py @@ -40,7 +40,7 @@ def sample_create_iceberg_catalog(): # Initialize request argument(s) iceberg_catalog = biglake_v1.IcebergCatalog() - iceberg_catalog.catalog_type = "CATALOG_TYPE_GCS_BUCKET" + iceberg_catalog.catalog_type = "CATALOG_TYPE_FEDERATED" request = biglake_v1.CreateIcebergCatalogRequest( parent="parent_value", diff --git a/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_update_iceberg_catalog_async.py b/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_update_iceberg_catalog_async.py index 3e587c3d94fc..7711224c12d0 100644 --- a/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_update_iceberg_catalog_async.py +++ b/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_update_iceberg_catalog_async.py @@ -40,7 +40,7 @@ async def sample_update_iceberg_catalog(): # Initialize request argument(s) iceberg_catalog = biglake_v1.IcebergCatalog() - iceberg_catalog.catalog_type = "CATALOG_TYPE_GCS_BUCKET" + iceberg_catalog.catalog_type = "CATALOG_TYPE_FEDERATED" request = biglake_v1.UpdateIcebergCatalogRequest( iceberg_catalog=iceberg_catalog, diff --git a/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_update_iceberg_catalog_sync.py b/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_update_iceberg_catalog_sync.py index 718966a119ce..63ec0400149a 100644 --- a/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_update_iceberg_catalog_sync.py +++ b/packages/google-cloud-biglake/samples/generated_samples/biglake_v1_generated_iceberg_catalog_service_update_iceberg_catalog_sync.py @@ -40,7 +40,7 @@ def sample_update_iceberg_catalog(): # Initialize request argument(s) iceberg_catalog = biglake_v1.IcebergCatalog() - iceberg_catalog.catalog_type = "CATALOG_TYPE_GCS_BUCKET" + iceberg_catalog.catalog_type = "CATALOG_TYPE_FEDERATED" request = biglake_v1.UpdateIcebergCatalogRequest( iceberg_catalog=iceberg_catalog, diff --git a/packages/google-cloud-biglake/samples/generated_samples/snippet_metadata_google.cloud.biglake.v1.json b/packages/google-cloud-biglake/samples/generated_samples/snippet_metadata_google.cloud.biglake.v1.json index 0320d2ab7629..df3623823115 100644 --- a/packages/google-cloud-biglake/samples/generated_samples/snippet_metadata_google.cloud.biglake.v1.json +++ b/packages/google-cloud-biglake/samples/generated_samples/snippet_metadata_google.cloud.biglake.v1.json @@ -45,6 +45,10 @@ "name": "iceberg_catalog_id", "type": "str" }, + { + "name": "primary_location", + "type": "str" + }, { "name": "retry", "type": "google.api_core.retry.Retry" @@ -133,6 +137,10 @@ "name": "iceberg_catalog_id", "type": "str" }, + { + "name": "primary_location", + "type": "str" + }, { "name": "retry", "type": "google.api_core.retry.Retry" diff --git a/packages/google-cloud-biglake/tests/unit/gapic/biglake_v1/test_iceberg_catalog_service.py b/packages/google-cloud-biglake/tests/unit/gapic/biglake_v1/test_iceberg_catalog_service.py index 71db32ccb04c..78612c605685 100644 --- a/packages/google-cloud-biglake/tests/unit/gapic/biglake_v1/test_iceberg_catalog_service.py +++ b/packages/google-cloud-biglake/tests/unit/gapic/biglake_v1/test_iceberg_catalog_service.py @@ -39,8 +39,11 @@ HAS_GOOGLE_AUTH_AIO = False import google.auth +import google.protobuf.any_pb2 as any_pb2 # type: ignore +import google.protobuf.duration_pb2 as duration_pb2 # type: ignore import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore +import google.rpc.status_pb2 as status_pb2 # type: ignore from google.api_core import ( client_options, gapic_v1, @@ -1416,9 +1419,11 @@ def test_get_iceberg_catalog(request_type, transport: str = "grpc"): name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) response = client.get_iceberg_catalog(request) @@ -1436,12 +1441,17 @@ def test_get_iceberg_catalog(request_type, transport: str = "grpc"): == iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER ) assert response.biglake_service_account == "biglake_service_account_value" + assert ( + response.biglake_service_account_unique_id + == "biglake_service_account_unique_id_value" + ) assert ( response.catalog_type == iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET ) assert response.default_location == "default_location_value" - assert response.catalog_regions == ["catalog_regions_value"] + assert response.storage_regions == ["storage_regions_value"] + assert response.description == "description_value" def test_get_iceberg_catalog_non_empty_request_with_auto_populated_field(): @@ -1584,9 +1594,11 @@ async def test_get_iceberg_catalog_async(request_type, transport: str = "grpc_as name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) ) response = await client.get_iceberg_catalog(request) @@ -1605,12 +1617,17 @@ async def test_get_iceberg_catalog_async(request_type, transport: str = "grpc_as == iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER ) assert response.biglake_service_account == "biglake_service_account_value" + assert ( + response.biglake_service_account_unique_id + == "biglake_service_account_unique_id_value" + ) assert ( response.catalog_type == iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET ) assert response.default_location == "default_location_value" - assert response.catalog_regions == ["catalog_regions_value"] + assert response.storage_regions == ["storage_regions_value"] + assert response.description == "description_value" def test_get_iceberg_catalog_field_headers(): @@ -2341,9 +2358,11 @@ def test_update_iceberg_catalog(request_type, transport: str = "grpc"): name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) response = client.update_iceberg_catalog(request) @@ -2361,12 +2380,17 @@ def test_update_iceberg_catalog(request_type, transport: str = "grpc"): == iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER ) assert response.biglake_service_account == "biglake_service_account_value" + assert ( + response.biglake_service_account_unique_id + == "biglake_service_account_unique_id_value" + ) assert ( response.catalog_type == iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET ) assert response.default_location == "default_location_value" - assert response.catalog_regions == ["catalog_regions_value"] + assert response.storage_regions == ["storage_regions_value"] + assert response.description == "description_value" def test_update_iceberg_catalog_non_empty_request_with_auto_populated_field(): @@ -2508,9 +2532,11 @@ async def test_update_iceberg_catalog_async( name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) ) response = await client.update_iceberg_catalog(request) @@ -2529,12 +2555,17 @@ async def test_update_iceberg_catalog_async( == iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER ) assert response.biglake_service_account == "biglake_service_account_value" + assert ( + response.biglake_service_account_unique_id + == "biglake_service_account_unique_id_value" + ) assert ( response.catalog_type == iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET ) assert response.default_location == "default_location_value" - assert response.catalog_regions == ["catalog_regions_value"] + assert response.storage_regions == ["storage_regions_value"] + assert response.description == "description_value" def test_update_iceberg_catalog_field_headers(): @@ -2724,9 +2755,11 @@ def test_create_iceberg_catalog(request_type, transport: str = "grpc"): name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) response = client.create_iceberg_catalog(request) @@ -2744,12 +2777,17 @@ def test_create_iceberg_catalog(request_type, transport: str = "grpc"): == iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER ) assert response.biglake_service_account == "biglake_service_account_value" + assert ( + response.biglake_service_account_unique_id + == "biglake_service_account_unique_id_value" + ) assert ( response.catalog_type == iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET ) assert response.default_location == "default_location_value" - assert response.catalog_regions == ["catalog_regions_value"] + assert response.storage_regions == ["storage_regions_value"] + assert response.description == "description_value" def test_create_iceberg_catalog_non_empty_request_with_auto_populated_field(): @@ -2766,6 +2804,7 @@ def test_create_iceberg_catalog_non_empty_request_with_auto_populated_field(): request = iceberg_rest_catalog.CreateIcebergCatalogRequest( parent="parent_value", iceberg_catalog_id="iceberg_catalog_id_value", + primary_location="primary_location_value", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2781,6 +2820,7 @@ def test_create_iceberg_catalog_non_empty_request_with_auto_populated_field(): request_msg = iceberg_rest_catalog.CreateIcebergCatalogRequest( parent="parent_value", iceberg_catalog_id="iceberg_catalog_id_value", + primary_location="primary_location_value", ) assert args[0] == request_msg @@ -2897,9 +2937,11 @@ async def test_create_iceberg_catalog_async( name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) ) response = await client.create_iceberg_catalog(request) @@ -2918,12 +2960,17 @@ async def test_create_iceberg_catalog_async( == iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER ) assert response.biglake_service_account == "biglake_service_account_value" + assert ( + response.biglake_service_account_unique_id + == "biglake_service_account_unique_id_value" + ) assert ( response.catalog_type == iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET ) assert response.default_location == "default_location_value" - assert response.catalog_regions == ["catalog_regions_value"] + assert response.storage_regions == ["storage_regions_value"] + assert response.description == "description_value" def test_create_iceberg_catalog_field_headers(): @@ -3008,6 +3055,7 @@ def test_create_iceberg_catalog_flattened(): parent="parent_value", iceberg_catalog=iceberg_rest_catalog.IcebergCatalog(name="name_value"), iceberg_catalog_id="iceberg_catalog_id_value", + primary_location="primary_location_value", ) # Establish that the underlying call was made with the expected @@ -3023,6 +3071,9 @@ def test_create_iceberg_catalog_flattened(): arg = args[0].iceberg_catalog_id mock_val = "iceberg_catalog_id_value" assert arg == mock_val + arg = args[0].primary_location + mock_val = "primary_location_value" + assert arg == mock_val def test_create_iceberg_catalog_flattened_error(): @@ -3038,6 +3089,7 @@ def test_create_iceberg_catalog_flattened_error(): parent="parent_value", iceberg_catalog=iceberg_rest_catalog.IcebergCatalog(name="name_value"), iceberg_catalog_id="iceberg_catalog_id_value", + primary_location="primary_location_value", ) @@ -3063,6 +3115,7 @@ async def test_create_iceberg_catalog_flattened_async(): parent="parent_value", iceberg_catalog=iceberg_rest_catalog.IcebergCatalog(name="name_value"), iceberg_catalog_id="iceberg_catalog_id_value", + primary_location="primary_location_value", ) # Establish that the underlying call was made with the expected @@ -3078,6 +3131,9 @@ async def test_create_iceberg_catalog_flattened_async(): arg = args[0].iceberg_catalog_id mock_val = "iceberg_catalog_id_value" assert arg == mock_val + arg = args[0].primary_location + mock_val = "primary_location_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3094,6 +3150,7 @@ async def test_create_iceberg_catalog_flattened_error_async(): parent="parent_value", iceberg_catalog=iceberg_rest_catalog.IcebergCatalog(name="name_value"), iceberg_catalog_id="iceberg_catalog_id_value", + primary_location="primary_location_value", ) @@ -4155,7 +4212,12 @@ def test_create_iceberg_catalog_rest_required_fields( credentials=ga_credentials.AnonymousCredentials() ).create_iceberg_catalog._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("iceberg_catalog_id",)) + assert not set(unset_fields) - set( + ( + "iceberg_catalog_id", + "primary_location", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -4220,7 +4282,12 @@ def test_create_iceberg_catalog_rest_unset_required_fields(): unset_fields = transport.create_iceberg_catalog._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("icebergCatalogId",)) + set( + ( + "icebergCatalogId", + "primaryLocation", + ) + ) & set( ( "parent", @@ -4250,6 +4317,7 @@ def test_create_iceberg_catalog_rest_flattened(): parent="parent_value", iceberg_catalog=iceberg_rest_catalog.IcebergCatalog(name="name_value"), iceberg_catalog_id="iceberg_catalog_id_value", + primary_location="primary_location_value", ) mock_args.update(sample_request) @@ -4290,6 +4358,7 @@ def test_create_iceberg_catalog_rest_flattened_error(transport: str = "rest"): parent="parent_value", iceberg_catalog=iceberg_rest_catalog.IcebergCatalog(name="name_value"), iceberg_catalog_id="iceberg_catalog_id_value", + primary_location="primary_location_value", ) @@ -4744,9 +4813,11 @@ async def test_get_iceberg_catalog_empty_call_grpc_asyncio(): name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) ) await client.get_iceberg_catalog(request=None) @@ -4806,9 +4877,11 @@ async def test_update_iceberg_catalog_empty_call_grpc_asyncio(): name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) ) await client.update_iceberg_catalog(request=None) @@ -4839,9 +4912,11 @@ async def test_create_iceberg_catalog_empty_call_grpc_asyncio(): name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) ) await client.create_iceberg_catalog(request=None) @@ -4935,9 +5010,11 @@ def test_get_iceberg_catalog_rest_call_success(request_type): name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) # Wrap the value into a proper Response obj @@ -4960,12 +5037,17 @@ def test_get_iceberg_catalog_rest_call_success(request_type): == iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER ) assert response.biglake_service_account == "biglake_service_account_value" + assert ( + response.biglake_service_account_unique_id + == "biglake_service_account_unique_id_value" + ) assert ( response.catalog_type == iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET ) assert response.default_location == "default_location_value" - assert response.catalog_regions == ["catalog_regions_value"] + assert response.storage_regions == ["storage_regions_value"] + assert response.description == "description_value" @pytest.mark.parametrize("null_interceptor", [True, False]) @@ -5221,11 +5303,59 @@ def test_update_iceberg_catalog_rest_call_success(request_type): "name": "projects/sample1/catalogs/sample2", "credential_mode": 1, "biglake_service_account": "biglake_service_account_value", + "biglake_service_account_unique_id": "biglake_service_account_unique_id_value", "catalog_type": 1, "default_location": "default_location_value", - "catalog_regions": ["catalog_regions_value1", "catalog_regions_value2"], + "storage_regions": ["storage_regions_value1", "storage_regions_value2"], "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, + "replicas": [{"region": "region_value", "state": 1}], + "description": "description_value", + "restricted_locations_config": { + "restricted_locations": [ + "restricted_locations_value1", + "restricted_locations_value2", + ] + }, + "federated_catalog_options": { + "unity_catalog_info": { + "instance_name": "instance_name_value", + "catalog_name": "catalog_name_value", + "service_principal_application_id": "service_principal_application_id_value", + }, + "glue_catalog_info": { + "warehouse": "warehouse_value", + "aws_region": "aws_region_value", + "aws_role_arn": "aws_role_arn_value", + }, + "secret_name": "secret_name_value", + "service_directory_name": "service_directory_name_value", + "refresh_options": { + "refresh_schedule": { + "refresh_interval": {"seconds": 751, "nanos": 543} + }, + "refresh_scope": { + "namespace_filters": [ + "namespace_filters_value1", + "namespace_filters_value2", + ] + }, + }, + "refresh_status": { + "start_time": {}, + "end_time": {}, + "status": { + "code": 411, + "message": "message_value", + "details": [ + { + "type_url": "type.googleapis.com/google.protobuf.Duration", + "value": b"\x08\x0c\x10\xdb\x07", + } + ], + }, + }, + }, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency @@ -5305,9 +5435,11 @@ def get_message_fields(field): name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) # Wrap the value into a proper Response obj @@ -5330,12 +5462,17 @@ def get_message_fields(field): == iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER ) assert response.biglake_service_account == "biglake_service_account_value" + assert ( + response.biglake_service_account_unique_id + == "biglake_service_account_unique_id_value" + ) assert ( response.catalog_type == iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET ) assert response.default_location == "default_location_value" - assert response.catalog_regions == ["catalog_regions_value"] + assert response.storage_regions == ["storage_regions_value"] + assert response.description == "description_value" @pytest.mark.parametrize("null_interceptor", [True, False]) @@ -5454,11 +5591,59 @@ def test_create_iceberg_catalog_rest_call_success(request_type): "name": "name_value", "credential_mode": 1, "biglake_service_account": "biglake_service_account_value", + "biglake_service_account_unique_id": "biglake_service_account_unique_id_value", "catalog_type": 1, "default_location": "default_location_value", - "catalog_regions": ["catalog_regions_value1", "catalog_regions_value2"], + "storage_regions": ["storage_regions_value1", "storage_regions_value2"], "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, + "replicas": [{"region": "region_value", "state": 1}], + "description": "description_value", + "restricted_locations_config": { + "restricted_locations": [ + "restricted_locations_value1", + "restricted_locations_value2", + ] + }, + "federated_catalog_options": { + "unity_catalog_info": { + "instance_name": "instance_name_value", + "catalog_name": "catalog_name_value", + "service_principal_application_id": "service_principal_application_id_value", + }, + "glue_catalog_info": { + "warehouse": "warehouse_value", + "aws_region": "aws_region_value", + "aws_role_arn": "aws_role_arn_value", + }, + "secret_name": "secret_name_value", + "service_directory_name": "service_directory_name_value", + "refresh_options": { + "refresh_schedule": { + "refresh_interval": {"seconds": 751, "nanos": 543} + }, + "refresh_scope": { + "namespace_filters": [ + "namespace_filters_value1", + "namespace_filters_value2", + ] + }, + }, + "refresh_status": { + "start_time": {}, + "end_time": {}, + "status": { + "code": 411, + "message": "message_value", + "details": [ + { + "type_url": "type.googleapis.com/google.protobuf.Duration", + "value": b"\x08\x0c\x10\xdb\x07", + } + ], + }, + }, + }, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency @@ -5538,9 +5723,11 @@ def get_message_fields(field): name="name_value", credential_mode=iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER, biglake_service_account="biglake_service_account_value", + biglake_service_account_unique_id="biglake_service_account_unique_id_value", catalog_type=iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET, default_location="default_location_value", - catalog_regions=["catalog_regions_value"], + storage_regions=["storage_regions_value"], + description="description_value", ) # Wrap the value into a proper Response obj @@ -5563,12 +5750,17 @@ def get_message_fields(field): == iceberg_rest_catalog.IcebergCatalog.CredentialMode.CREDENTIAL_MODE_END_USER ) assert response.biglake_service_account == "biglake_service_account_value" + assert ( + response.biglake_service_account_unique_id + == "biglake_service_account_unique_id_value" + ) assert ( response.catalog_type == iceberg_rest_catalog.IcebergCatalog.CatalogType.CATALOG_TYPE_GCS_BUCKET ) assert response.default_location == "default_location_value" - assert response.catalog_regions == ["catalog_regions_value"] + assert response.storage_regions == ["storage_regions_value"] + assert response.description == "description_value" @pytest.mark.parametrize("null_interceptor", [True, False]) @@ -6378,6 +6570,60 @@ def test_parse_catalog_path(): assert expected == actual +def test_secret_path(): + project = "oyster" + secret = "nudibranch" + expected = "projects/{project}/secrets/{secret}".format( + project=project, + secret=secret, + ) + actual = IcebergCatalogServiceClient.secret_path(project, secret) + assert expected == actual + + +def test_parse_secret_path(): + expected = { + "project": "cuttlefish", + "secret": "mussel", + } + path = IcebergCatalogServiceClient.secret_path(**expected) + + # Check that the path construction is reversible. + actual = IcebergCatalogServiceClient.parse_secret_path(path) + assert expected == actual + + +def test_service_path(): + project = "winkle" + location = "nautilus" + namespace = "scallop" + service = "abalone" + expected = "projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}".format( + project=project, + location=location, + namespace=namespace, + service=service, + ) + actual = IcebergCatalogServiceClient.service_path( + project, location, namespace, service + ) + assert expected == actual + + +def test_parse_service_path(): + expected = { + "project": "squid", + "location": "clam", + "namespace": "whelk", + "service": "octopus", + } + path = IcebergCatalogServiceClient.service_path(**expected) + + # Check that the path construction is reversible. + actual = IcebergCatalogServiceClient.parse_service_path(path) + assert expected == actual + + def test_common_billing_account_path(): billing_account = "oyster" expected = "billingAccounts/{billing_account}".format( diff --git a/packages/google-cloud-bigtable/samples/snippets/filters/filter_snippets_async_test.py b/packages/google-cloud-bigtable/samples/snippets/filters/filter_snippets_async_test.py index 3c961a27b752..b750564e2901 100644 --- a/packages/google-cloud-bigtable/samples/snippets/filters/filter_snippets_async_test.py +++ b/packages/google-cloud-bigtable/samples/snippets/filters/filter_snippets_async_test.py @@ -20,9 +20,7 @@ import pytest import pytest_asyncio -from google.cloud._helpers import ( - _microseconds_from_datetime, -) +from google.cloud._helpers import _microseconds_from_datetime from ...utils import create_table_cm from . import filter_snippets_async diff --git a/packages/google-cloud-bigtable/samples/snippets/reads/read_snippets.py b/packages/google-cloud-bigtable/samples/snippets/reads/read_snippets.py index 7bdf01c7c890..1d4ee3d8e650 100644 --- a/packages/google-cloud-bigtable/samples/snippets/reads/read_snippets.py +++ b/packages/google-cloud-bigtable/samples/snippets/reads/read_snippets.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + # [START bigtable_reads_row] def read_row(project_id, instance_id, table_id): from google.cloud import bigtable diff --git a/packages/google-cloud-bigtable/samples/testdata/singer_pb2.py b/packages/google-cloud-bigtable/samples/testdata/singer_pb2.py index f5da249d4811..2579349f0753 100644 --- a/packages/google-cloud-bigtable/samples/testdata/singer_pb2.py +++ b/packages/google-cloud-bigtable/samples/testdata/singer_pb2.py @@ -1,4 +1,19 @@ # -*- coding: utf-8 -*- + +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # Generated by the protocol buffer compiler. DO NOT EDIT! # source: singer.proto """Generated protocol buffer code.""" diff --git a/packages/google-cloud-network-services/google/cloud/network_services/__init__.py b/packages/google-cloud-network-services/google/cloud/network_services/__init__.py index 2415456ba13a..7bec0680d7e7 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services/__init__.py +++ b/packages/google-cloud-network-services/google/cloud/network_services/__init__.py @@ -30,6 +30,15 @@ from google.cloud.network_services_v1.services.network_services.client import ( NetworkServicesClient, ) +from google.cloud.network_services_v1.types.agent_gateway import ( + AgentGateway, + CreateAgentGatewayRequest, + DeleteAgentGatewayRequest, + GetAgentGatewayRequest, + ListAgentGatewaysRequest, + ListAgentGatewaysResponse, + UpdateAgentGatewayRequest, +) from google.cloud.network_services_v1.types.common import ( EndpointMatcher, EnvoyHeaders, @@ -38,6 +47,7 @@ ) from google.cloud.network_services_v1.types.dep import ( AuthzExtension, + BodySendMode, CreateAuthzExtensionRequest, CreateLbEdgeExtensionRequest, CreateLbRouteExtensionRequest, @@ -183,6 +193,13 @@ "DepServiceAsyncClient", "NetworkServicesClient", "NetworkServicesAsyncClient", + "AgentGateway", + "CreateAgentGatewayRequest", + "DeleteAgentGatewayRequest", + "GetAgentGatewayRequest", + "ListAgentGatewaysRequest", + "ListAgentGatewaysResponse", + "UpdateAgentGatewayRequest", "EndpointMatcher", "OperationMetadata", "TrafficPortSelector", @@ -216,6 +233,7 @@ "UpdateLbEdgeExtensionRequest", "UpdateLbRouteExtensionRequest", "UpdateLbTrafficExtensionRequest", + "BodySendMode", "EventType", "LoadBalancingScheme", "WireFormat", diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/__init__.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/__init__.py index 940453de77ee..ae423bbb90b7 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/__init__.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/__init__.py @@ -25,6 +25,15 @@ from .services.dep_service import DepServiceAsyncClient, DepServiceClient from .services.network_services import NetworkServicesAsyncClient, NetworkServicesClient +from .types.agent_gateway import ( + AgentGateway, + CreateAgentGatewayRequest, + DeleteAgentGatewayRequest, + GetAgentGatewayRequest, + ListAgentGatewaysRequest, + ListAgentGatewaysResponse, + UpdateAgentGatewayRequest, +) from .types.common import ( EndpointMatcher, EnvoyHeaders, @@ -33,6 +42,7 @@ ) from .types.dep import ( AuthzExtension, + BodySendMode, CreateAuthzExtensionRequest, CreateLbEdgeExtensionRequest, CreateLbRouteExtensionRequest, @@ -259,7 +269,10 @@ def _get_version(dependency_name): __all__ = ( "DepServiceAsyncClient", "NetworkServicesAsyncClient", + "AgentGateway", "AuthzExtension", + "BodySendMode", + "CreateAgentGatewayRequest", "CreateAuthzExtensionRequest", "CreateEndpointPolicyRequest", "CreateGatewayRequest", @@ -275,6 +288,7 @@ def _get_version(dependency_name): "CreateTlsRouteRequest", "CreateWasmPluginRequest", "CreateWasmPluginVersionRequest", + "DeleteAgentGatewayRequest", "DeleteAuthzExtensionRequest", "DeleteEndpointPolicyRequest", "DeleteGatewayRequest", @@ -298,6 +312,7 @@ def _get_version(dependency_name): "ExtensionChain", "Gateway", "GatewayRouteView", + "GetAgentGatewayRequest", "GetAuthzExtensionRequest", "GetEndpointPolicyRequest", "GetGatewayRequest", @@ -320,6 +335,8 @@ def _get_version(dependency_name): "LbEdgeExtension", "LbRouteExtension", "LbTrafficExtension", + "ListAgentGatewaysRequest", + "ListAgentGatewaysResponse", "ListAuthzExtensionsRequest", "ListAuthzExtensionsResponse", "ListEndpointPoliciesRequest", @@ -364,6 +381,7 @@ def _get_version(dependency_name): "TcpRoute", "TlsRoute", "TrafficPortSelector", + "UpdateAgentGatewayRequest", "UpdateAuthzExtensionRequest", "UpdateEndpointPolicyRequest", "UpdateGatewayRequest", diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/gapic_metadata.json b/packages/google-cloud-network-services/google/cloud/network_services_v1/gapic_metadata.json index 0a3314f7de1d..3598822b7781 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/gapic_metadata.json +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/gapic_metadata.json @@ -329,6 +329,11 @@ "grpc": { "libraryClient": "NetworkServicesClient", "rpcs": { + "CreateAgentGateway": { + "methods": [ + "create_agent_gateway" + ] + }, "CreateEndpointPolicy": { "methods": [ "create_endpoint_policy" @@ -384,6 +389,11 @@ "create_wasm_plugin_version" ] }, + "DeleteAgentGateway": { + "methods": [ + "delete_agent_gateway" + ] + }, "DeleteEndpointPolicy": { "methods": [ "delete_endpoint_policy" @@ -439,6 +449,11 @@ "delete_wasm_plugin_version" ] }, + "GetAgentGateway": { + "methods": [ + "get_agent_gateway" + ] + }, "GetEndpointPolicy": { "methods": [ "get_endpoint_policy" @@ -504,6 +519,11 @@ "get_wasm_plugin_version" ] }, + "ListAgentGateways": { + "methods": [ + "list_agent_gateways" + ] + }, "ListEndpointPolicies": { "methods": [ "list_endpoint_policies" @@ -569,6 +589,11 @@ "list_wasm_plugins" ] }, + "UpdateAgentGateway": { + "methods": [ + "update_agent_gateway" + ] + }, "UpdateEndpointPolicy": { "methods": [ "update_endpoint_policy" @@ -624,6 +649,11 @@ "grpc-async": { "libraryClient": "NetworkServicesAsyncClient", "rpcs": { + "CreateAgentGateway": { + "methods": [ + "create_agent_gateway" + ] + }, "CreateEndpointPolicy": { "methods": [ "create_endpoint_policy" @@ -679,6 +709,11 @@ "create_wasm_plugin_version" ] }, + "DeleteAgentGateway": { + "methods": [ + "delete_agent_gateway" + ] + }, "DeleteEndpointPolicy": { "methods": [ "delete_endpoint_policy" @@ -734,6 +769,11 @@ "delete_wasm_plugin_version" ] }, + "GetAgentGateway": { + "methods": [ + "get_agent_gateway" + ] + }, "GetEndpointPolicy": { "methods": [ "get_endpoint_policy" @@ -799,6 +839,11 @@ "get_wasm_plugin_version" ] }, + "ListAgentGateways": { + "methods": [ + "list_agent_gateways" + ] + }, "ListEndpointPolicies": { "methods": [ "list_endpoint_policies" @@ -864,6 +909,11 @@ "list_wasm_plugins" ] }, + "UpdateAgentGateway": { + "methods": [ + "update_agent_gateway" + ] + }, "UpdateEndpointPolicy": { "methods": [ "update_endpoint_policy" @@ -919,6 +969,11 @@ "rest": { "libraryClient": "NetworkServicesClient", "rpcs": { + "CreateAgentGateway": { + "methods": [ + "create_agent_gateway" + ] + }, "CreateEndpointPolicy": { "methods": [ "create_endpoint_policy" @@ -974,6 +1029,11 @@ "create_wasm_plugin_version" ] }, + "DeleteAgentGateway": { + "methods": [ + "delete_agent_gateway" + ] + }, "DeleteEndpointPolicy": { "methods": [ "delete_endpoint_policy" @@ -1029,6 +1089,11 @@ "delete_wasm_plugin_version" ] }, + "GetAgentGateway": { + "methods": [ + "get_agent_gateway" + ] + }, "GetEndpointPolicy": { "methods": [ "get_endpoint_policy" @@ -1094,6 +1159,11 @@ "get_wasm_plugin_version" ] }, + "ListAgentGateways": { + "methods": [ + "list_agent_gateways" + ] + }, "ListEndpointPolicies": { "methods": [ "list_endpoint_policies" @@ -1159,6 +1229,11 @@ "list_wasm_plugins" ] }, + "UpdateAgentGateway": { + "methods": [ + "update_agent_gateway" + ] + }, "UpdateEndpointPolicy": { "methods": [ "update_endpoint_policy" diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/dep_service/async_client.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/dep_service/async_client.py index 6abe445a7417..26494e7670b0 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/dep_service/async_client.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/dep_service/async_client.py @@ -592,7 +592,6 @@ async def sample_create_lb_traffic_extension(): lb_traffic_extension.name = "name_value" lb_traffic_extension.extension_chains.name = "name_value" lb_traffic_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_traffic_extension.extension_chains.extensions.name = "name_value" lb_traffic_extension.extension_chains.extensions.service = "service_value" lb_traffic_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -748,7 +747,6 @@ async def sample_update_lb_traffic_extension(): lb_traffic_extension.name = "name_value" lb_traffic_extension.extension_chains.name = "name_value" lb_traffic_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_traffic_extension.extension_chains.extensions.name = "name_value" lb_traffic_extension.extension_chains.extensions.service = "service_value" lb_traffic_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -1273,7 +1271,6 @@ async def sample_create_lb_route_extension(): lb_route_extension.forwarding_rules = ['forwarding_rules_value1', 'forwarding_rules_value2'] lb_route_extension.extension_chains.name = "name_value" lb_route_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_route_extension.extension_chains.extensions.name = "name_value" lb_route_extension.extension_chains.extensions.service = "service_value" lb_route_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -1427,7 +1424,6 @@ async def sample_update_lb_route_extension(): lb_route_extension.forwarding_rules = ['forwarding_rules_value1', 'forwarding_rules_value2'] lb_route_extension.extension_chains.name = "name_value" lb_route_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_route_extension.extension_chains.extensions.name = "name_value" lb_route_extension.extension_chains.extensions.service = "service_value" lb_route_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -1950,7 +1946,6 @@ async def sample_create_lb_edge_extension(): lb_edge_extension.forwarding_rules = ['forwarding_rules_value1', 'forwarding_rules_value2'] lb_edge_extension.extension_chains.name = "name_value" lb_edge_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_edge_extension.extension_chains.extensions.name = "name_value" lb_edge_extension.extension_chains.extensions.service = "service_value" lb_edge_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -2105,7 +2100,6 @@ async def sample_update_lb_edge_extension(): lb_edge_extension.forwarding_rules = ['forwarding_rules_value1', 'forwarding_rules_value2'] lb_edge_extension.extension_chains.name = "name_value" lb_edge_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_edge_extension.extension_chains.extensions.name = "name_value" lb_edge_extension.extension_chains.extensions.service = "service_value" lb_edge_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -2626,8 +2620,6 @@ async def sample_create_authz_extension(): # Initialize request argument(s) authz_extension = network_services_v1.AuthzExtension() authz_extension.name = "name_value" - authz_extension.load_balancing_scheme = "EXTERNAL_MANAGED" - authz_extension.authority = "authority_value" authz_extension.service = "service_value" request = network_services_v1.CreateAuthzExtensionRequest( @@ -2778,8 +2770,6 @@ async def sample_update_authz_extension(): # Initialize request argument(s) authz_extension = network_services_v1.AuthzExtension() authz_extension.name = "name_value" - authz_extension.load_balancing_scheme = "EXTERNAL_MANAGED" - authz_extension.authority = "authority_value" authz_extension.service = "service_value" request = network_services_v1.UpdateAuthzExtensionRequest( diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/dep_service/client.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/dep_service/client.py index 4afdfdb26c2b..79b465d8dcb0 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/dep_service/client.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/dep_service/client.py @@ -1077,7 +1077,6 @@ def sample_create_lb_traffic_extension(): lb_traffic_extension.name = "name_value" lb_traffic_extension.extension_chains.name = "name_value" lb_traffic_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_traffic_extension.extension_chains.extensions.name = "name_value" lb_traffic_extension.extension_chains.extensions.service = "service_value" lb_traffic_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -1232,7 +1231,6 @@ def sample_update_lb_traffic_extension(): lb_traffic_extension.name = "name_value" lb_traffic_extension.extension_chains.name = "name_value" lb_traffic_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_traffic_extension.extension_chains.extensions.name = "name_value" lb_traffic_extension.extension_chains.extensions.service = "service_value" lb_traffic_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -1749,7 +1747,6 @@ def sample_create_lb_route_extension(): lb_route_extension.forwarding_rules = ['forwarding_rules_value1', 'forwarding_rules_value2'] lb_route_extension.extension_chains.name = "name_value" lb_route_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_route_extension.extension_chains.extensions.name = "name_value" lb_route_extension.extension_chains.extensions.service = "service_value" lb_route_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -1902,7 +1899,6 @@ def sample_update_lb_route_extension(): lb_route_extension.forwarding_rules = ['forwarding_rules_value1', 'forwarding_rules_value2'] lb_route_extension.extension_chains.name = "name_value" lb_route_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_route_extension.extension_chains.extensions.name = "name_value" lb_route_extension.extension_chains.extensions.service = "service_value" lb_route_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -2417,7 +2413,6 @@ def sample_create_lb_edge_extension(): lb_edge_extension.forwarding_rules = ['forwarding_rules_value1', 'forwarding_rules_value2'] lb_edge_extension.extension_chains.name = "name_value" lb_edge_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_edge_extension.extension_chains.extensions.name = "name_value" lb_edge_extension.extension_chains.extensions.service = "service_value" lb_edge_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -2569,7 +2564,6 @@ def sample_update_lb_edge_extension(): lb_edge_extension.forwarding_rules = ['forwarding_rules_value1', 'forwarding_rules_value2'] lb_edge_extension.extension_chains.name = "name_value" lb_edge_extension.extension_chains.match_condition.cel_expression = "cel_expression_value" - lb_edge_extension.extension_chains.extensions.name = "name_value" lb_edge_extension.extension_chains.extensions.service = "service_value" lb_edge_extension.load_balancing_scheme = "EXTERNAL_MANAGED" @@ -3078,8 +3072,6 @@ def sample_create_authz_extension(): # Initialize request argument(s) authz_extension = network_services_v1.AuthzExtension() authz_extension.name = "name_value" - authz_extension.load_balancing_scheme = "EXTERNAL_MANAGED" - authz_extension.authority = "authority_value" authz_extension.service = "service_value" request = network_services_v1.CreateAuthzExtensionRequest( @@ -3227,8 +3219,6 @@ def sample_update_authz_extension(): # Initialize request argument(s) authz_extension = network_services_v1.AuthzExtension() authz_extension.name = "name_value" - authz_extension.load_balancing_scheme = "EXTERNAL_MANAGED" - authz_extension.authority = "authority_value" authz_extension.service = "service_value" request = network_services_v1.UpdateAuthzExtensionRequest( diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/async_client.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/async_client.py index 5e4f2cfec052..a55133f57f90 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/async_client.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/async_client.py @@ -58,6 +58,7 @@ from google.cloud.network_services_v1.services.network_services import pagers from google.cloud.network_services_v1.types import ( + agent_gateway, common, endpoint_policy, extensibility, @@ -71,6 +72,7 @@ tcp_route, tls_route, ) +from google.cloud.network_services_v1.types import agent_gateway as gcn_agent_gateway from google.cloud.network_services_v1.types import ( endpoint_policy as gcn_endpoint_policy, ) @@ -115,6 +117,10 @@ class NetworkServicesAsyncClient: address_path = staticmethod(NetworkServicesClient.address_path) parse_address_path = staticmethod(NetworkServicesClient.parse_address_path) + agent_gateway_path = staticmethod(NetworkServicesClient.agent_gateway_path) + parse_agent_gateway_path = staticmethod( + NetworkServicesClient.parse_agent_gateway_path + ) authorization_policy_path = staticmethod( NetworkServicesClient.authorization_policy_path ) @@ -177,6 +183,10 @@ class NetworkServicesAsyncClient: ) subnetwork_path = staticmethod(NetworkServicesClient.subnetwork_path) parse_subnetwork_path = staticmethod(NetworkServicesClient.parse_subnetwork_path) + target_tcp_proxy_path = staticmethod(NetworkServicesClient.target_tcp_proxy_path) + parse_target_tcp_proxy_path = staticmethod( + NetworkServicesClient.parse_target_tcp_proxy_path + ) tcp_route_path = staticmethod(NetworkServicesClient.tcp_route_path) parse_tcp_route_path = staticmethod(NetworkServicesClient.parse_tcp_route_path) tls_route_path = staticmethod(NetworkServicesClient.tls_route_path) @@ -457,7 +467,7 @@ async def sample_list_endpoint_policies(): parent (:class:`str`): Required. The project and location from which the EndpointPolicies should be listed, specified in the - format ``projects/*/locations/global``. + format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -583,7 +593,7 @@ async def sample_get_endpoint_policy(): name (:class:`str`): Required. A name of the EndpointPolicy to get. Must be in the format - ``projects/*/locations/global/endpointPolicies/*``. + ``projects/*/locations/*/endpointPolicies/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -712,7 +722,7 @@ async def sample_create_endpoint_policy(): CreateEndpointPolicy method. parent (:class:`str`): Required. The parent resource of the EndpointPolicy. - Must be in the format ``projects/*/locations/global``. + Must be in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1012,7 +1022,7 @@ async def sample_delete_endpoint_policy(): name (:class:`str`): Required. A name of the EndpointPolicy to delete. Must be in the format - ``projects/*/locations/global/endpointPolicies/*``. + ``projects/*/locations/*/endpointPolicies/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -3008,7 +3018,7 @@ async def sample_list_grpc_routes(): parent (:class:`str`): Required. The project and location from which the GrpcRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -3133,7 +3143,7 @@ async def sample_get_grpc_route(): method. name (:class:`str`): Required. A name of the GrpcRoute to get. Must be in the - format ``projects/*/locations/global/grpcRoutes/*``. + format ``projects/*/locations/*/grpcRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -3257,7 +3267,7 @@ async def sample_create_grpc_route(): method. parent (:class:`str`): Required. The parent resource of the GrpcRoute. Must be - in the format ``projects/*/locations/global``. + in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -3542,7 +3552,7 @@ async def sample_delete_grpc_route(): method. name (:class:`str`): Required. A name of the GrpcRoute to delete. Must be in - the format ``projects/*/locations/global/grpcRoutes/*``. + the format ``projects/*/locations/*/grpcRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -3673,7 +3683,7 @@ async def sample_list_http_routes(): parent (:class:`str`): Required. The project and location from which the HttpRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -3798,7 +3808,7 @@ async def sample_get_http_route(): method. name (:class:`str`): Required. A name of the HttpRoute to get. Must be in the - format ``projects/*/locations/global/httpRoutes/*``. + format ``projects/*/locations/*/httpRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -3921,7 +3931,7 @@ async def sample_create_http_route(): The request object. Request used by the HttpRoute method. parent (:class:`str`): Required. The parent resource of the HttpRoute. Must be - in the format ``projects/*/locations/global``. + in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -4206,7 +4216,7 @@ async def sample_delete_http_route(): method. name (:class:`str`): Required. A name of the HttpRoute to delete. Must be in - the format ``projects/*/locations/global/httpRoutes/*``. + the format ``projects/*/locations/*/httpRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -4337,7 +4347,7 @@ async def sample_list_tcp_routes(): parent (:class:`str`): Required. The project and location from which the TcpRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -4462,7 +4472,7 @@ async def sample_get_tcp_route(): method. name (:class:`str`): Required. A name of the TcpRoute to get. Must be in the - format ``projects/*/locations/global/tcpRoutes/*``. + format ``projects/*/locations/*/tcpRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -4581,7 +4591,7 @@ async def sample_create_tcp_route(): The request object. Request used by the TcpRoute method. parent (:class:`str`): Required. The parent resource of the TcpRoute. Must be - in the format ``projects/*/locations/global``. + in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -4862,7 +4872,7 @@ async def sample_delete_tcp_route(): method. name (:class:`str`): Required. A name of the TcpRoute to delete. Must be in - the format ``projects/*/locations/global/tcpRoutes/*``. + the format ``projects/*/locations/*/tcpRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -4993,7 +5003,7 @@ async def sample_list_tls_routes(): parent (:class:`str`): Required. The project and location from which the TlsRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -5118,7 +5128,7 @@ async def sample_get_tls_route(): method. name (:class:`str`): Required. A name of the TlsRoute to get. Must be in the - format ``projects/*/locations/global/tlsRoutes/*``. + format ``projects/*/locations/*/tlsRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -5241,7 +5251,7 @@ async def sample_create_tls_route(): The request object. Request used by the TlsRoute method. parent (:class:`str`): Required. The parent resource of the TlsRoute. Must be - in the format ``projects/*/locations/global``. + in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -5526,7 +5536,7 @@ async def sample_delete_tls_route(): method. name (:class:`str`): Required. A name of the TlsRoute to delete. Must be in - the format ``projects/*/locations/global/tlsRoutes/*``. + the format ``projects/*/locations/*/tlsRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -6350,7 +6360,7 @@ async def sample_list_meshes(): parent (:class:`str`): Required. The project and location from which the Meshes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -6474,7 +6484,7 @@ async def sample_get_mesh(): The request object. Request used by the GetMesh method. name (:class:`str`): Required. A name of the Mesh to get. Must be in the - format ``projects/*/locations/global/meshes/*``. + format ``projects/*/locations/*/meshes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -6594,7 +6604,7 @@ async def sample_create_mesh(): method. parent (:class:`str`): Required. The parent resource of the Mesh. Must be in - the format ``projects/*/locations/global``. + the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -6879,7 +6889,7 @@ async def sample_delete_mesh(): method. name (:class:`str`): Required. A name of the Mesh to delete. Must be in the - format ``projects/*/locations/global/meshes/*``. + format ``projects/*/locations/*/meshes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -8123,6 +8133,671 @@ async def sample_list_mesh_route_views(): # Done; return the response. return response + async def list_agent_gateways( + self, + request: Optional[Union[agent_gateway.ListAgentGatewaysRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> pagers.ListAgentGatewaysAsyncPager: + r"""Lists AgentGateways in a given project and location. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + async def sample_list_agent_gateways(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.ListAgentGatewaysRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_agent_gateways(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.network_services_v1.types.ListAgentGatewaysRequest, dict]]): + The request object. Request used with the + ListAgentGateways method. + parent (:class:`str`): + Required. The project and location from which the + AgentGateways should be listed, specified in the format + ``projects/*/locations/*``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.cloud.network_services_v1.services.network_services.pagers.ListAgentGatewaysAsyncPager: + Response returned by the + ListAgentGateways method. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, agent_gateway.ListAgentGatewaysRequest): + request = agent_gateway.ListAgentGatewaysRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.list_agent_gateways + ] + + # 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),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListAgentGatewaysAsyncPager( + method=rpc, + request=request, + response=response, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_agent_gateway( + self, + request: Optional[Union[agent_gateway.GetAgentGatewayRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> agent_gateway.AgentGateway: + r"""Gets details of a single AgentGateway. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + async def sample_get_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.GetAgentGatewayRequest( + name="name_value", + ) + + # Make the request + response = await client.get_agent_gateway(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.network_services_v1.types.GetAgentGatewayRequest, dict]]): + The request object. Request used by the GetAgentGateway + method. + name (:class:`str`): + Required. A name of the AgentGateway to get. Must be in + the format ``projects/*/locations/*/agentGateways/*``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.cloud.network_services_v1.types.AgentGateway: + AgentGateway represents the agent + gateway resource. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, agent_gateway.GetAgentGatewayRequest): + request = agent_gateway.GetAgentGatewayRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_agent_gateway + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_agent_gateway( + self, + request: Optional[ + Union[gcn_agent_gateway.CreateAgentGatewayRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + agent_gateway: Optional[gcn_agent_gateway.AgentGateway] = None, + agent_gateway_id: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates a new AgentGateway in a given project and + location. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + async def sample_create_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.CreateAgentGatewayRequest( + parent="parent_value", + agent_gateway_id="agent_gateway_id_value", + ) + + # Make the request + operation = await client.create_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.network_services_v1.types.CreateAgentGatewayRequest, dict]]): + The request object. Request used by the + CreateAgentGateway method. + parent (:class:`str`): + Required. The parent resource of the AgentGateway. Must + be in the format ``projects/*/locations/*``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + agent_gateway (:class:`google.cloud.network_services_v1.types.AgentGateway`): + Required. AgentGateway resource to be + created. + + This corresponds to the ``agent_gateway`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + agent_gateway_id (:class:`str`): + Required. Short name of the + AgentGateway resource to be created. + + This corresponds to the ``agent_gateway_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.network_services_v1.types.AgentGateway` + AgentGateway represents the agent gateway resource. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent, agent_gateway, agent_gateway_id] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, gcn_agent_gateway.CreateAgentGatewayRequest): + request = gcn_agent_gateway.CreateAgentGatewayRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if agent_gateway is not None: + request.agent_gateway = agent_gateway + if agent_gateway_id is not None: + request.agent_gateway_id = agent_gateway_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.create_agent_gateway + ] + + # 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),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gcn_agent_gateway.AgentGateway, + metadata_type=common.OperationMetadata, + ) + + # Done; return the response. + return response + + async def update_agent_gateway( + self, + request: Optional[ + Union[gcn_agent_gateway.UpdateAgentGatewayRequest, dict] + ] = None, + *, + agent_gateway: Optional[gcn_agent_gateway.AgentGateway] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates the parameters of a single AgentGateway. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + async def sample_update_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.UpdateAgentGatewayRequest( + ) + + # Make the request + operation = await client.update_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.network_services_v1.types.UpdateAgentGatewayRequest, dict]]): + The request object. Request used by the + UpdateAgentGateway method. + agent_gateway (:class:`google.cloud.network_services_v1.types.AgentGateway`): + Required. Updated AgentGateway + resource. + + This corresponds to the ``agent_gateway`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Optional. Field mask is used to specify the fields to be + overwritten in the AgentGateway resource by the update. + The fields specified in the update_mask are relative to + the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then all fields will be overwritten. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.network_services_v1.types.AgentGateway` + AgentGateway represents the agent gateway resource. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [agent_gateway, update_mask] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, gcn_agent_gateway.UpdateAgentGatewayRequest): + request = gcn_agent_gateway.UpdateAgentGatewayRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if agent_gateway is not None: + request.agent_gateway = agent_gateway + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.update_agent_gateway + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("agent_gateway.name", request.agent_gateway.name),) + ), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gcn_agent_gateway.AgentGateway, + metadata_type=common.OperationMetadata, + ) + + # Done; return the response. + return response + + async def delete_agent_gateway( + self, + request: Optional[Union[agent_gateway.DeleteAgentGatewayRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a single AgentGateway. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + async def sample_delete_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.DeleteAgentGatewayRequest( + name="name_value", + ) + + # Make the request + operation = await client.delete_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.network_services_v1.types.DeleteAgentGatewayRequest, dict]]): + The request object. Request used by the + DeleteAgentGateway method. + name (:class:`str`): + Required. A name of the AgentGateway to delete. Must be + in the format + ``projects/*/locations/*/agentGateways/*``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, agent_gateway.DeleteAgentGatewayRequest): + request = agent_gateway.DeleteAgentGatewayRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.delete_agent_gateway + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=common.OperationMetadata, + ) + + # Done; return the response. + return response + async def list_operations( self, request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/client.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/client.py index 2d673965f715..b8476bd428ee 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/client.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/client.py @@ -75,6 +75,7 @@ from google.cloud.network_services_v1.services.network_services import pagers from google.cloud.network_services_v1.types import ( + agent_gateway, common, endpoint_policy, extensibility, @@ -88,6 +89,7 @@ tcp_route, tls_route, ) +from google.cloud.network_services_v1.types import agent_gateway as gcn_agent_gateway from google.cloud.network_services_v1.types import ( endpoint_policy as gcn_endpoint_policy, ) @@ -288,6 +290,28 @@ def parse_address_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def agent_gateway_path( + project: str, + location: str, + agent_gateway: str, + ) -> str: + """Returns a fully-qualified agent_gateway string.""" + return "projects/{project}/locations/{location}/agentGateways/{agent_gateway}".format( + project=project, + location=location, + agent_gateway=agent_gateway, + ) + + @staticmethod + def parse_agent_gateway_path(path: str) -> Dict[str, str]: + """Parses a agent_gateway path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agentGateways/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def authorization_policy_path( project: str, @@ -689,6 +713,28 @@ def parse_subnetwork_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def target_tcp_proxy_path( + project: str, + location: str, + target_tcp_proxy: str, + ) -> str: + """Returns a fully-qualified target_tcp_proxy string.""" + return "projects/{project}/locations/{location}/targetTcpProxies/{target_tcp_proxy}".format( + project=project, + location=location, + target_tcp_proxy=target_tcp_proxy, + ) + + @staticmethod + def parse_target_tcp_proxy_path(path: str) -> Dict[str, str]: + """Parses a target_tcp_proxy path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/targetTcpProxies/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def tcp_route_path( project: str, @@ -1310,7 +1356,7 @@ def sample_list_endpoint_policies(): parent (str): Required. The project and location from which the EndpointPolicies should be listed, specified in the - format ``projects/*/locations/global``. + format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1433,7 +1479,7 @@ def sample_get_endpoint_policy(): name (str): Required. A name of the EndpointPolicy to get. Must be in the format - ``projects/*/locations/global/endpointPolicies/*``. + ``projects/*/locations/*/endpointPolicies/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1559,7 +1605,7 @@ def sample_create_endpoint_policy(): CreateEndpointPolicy method. parent (str): Required. The parent resource of the EndpointPolicy. - Must be in the format ``projects/*/locations/global``. + Must be in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1853,7 +1899,7 @@ def sample_delete_endpoint_policy(): name (str): Required. A name of the EndpointPolicy to delete. Must be in the format - ``projects/*/locations/global/endpointPolicies/*``. + ``projects/*/locations/*/endpointPolicies/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -3810,7 +3856,7 @@ def sample_list_grpc_routes(): parent (str): Required. The project and location from which the GrpcRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -3932,7 +3978,7 @@ def sample_get_grpc_route(): method. name (str): Required. A name of the GrpcRoute to get. Must be in the - format ``projects/*/locations/global/grpcRoutes/*``. + format ``projects/*/locations/*/grpcRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -4053,7 +4099,7 @@ def sample_create_grpc_route(): method. parent (str): Required. The parent resource of the GrpcRoute. Must be - in the format ``projects/*/locations/global``. + in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -4332,7 +4378,7 @@ def sample_delete_grpc_route(): method. name (str): Required. A name of the GrpcRoute to delete. Must be in - the format ``projects/*/locations/global/grpcRoutes/*``. + the format ``projects/*/locations/*/grpcRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -4460,7 +4506,7 @@ def sample_list_http_routes(): parent (str): Required. The project and location from which the HttpRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -4582,7 +4628,7 @@ def sample_get_http_route(): method. name (str): Required. A name of the HttpRoute to get. Must be in the - format ``projects/*/locations/global/httpRoutes/*``. + format ``projects/*/locations/*/httpRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -4702,7 +4748,7 @@ def sample_create_http_route(): The request object. Request used by the HttpRoute method. parent (str): Required. The parent resource of the HttpRoute. Must be - in the format ``projects/*/locations/global``. + in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -4981,7 +5027,7 @@ def sample_delete_http_route(): method. name (str): Required. A name of the HttpRoute to delete. Must be in - the format ``projects/*/locations/global/httpRoutes/*``. + the format ``projects/*/locations/*/httpRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -5109,7 +5155,7 @@ def sample_list_tcp_routes(): parent (str): Required. The project and location from which the TcpRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -5231,7 +5277,7 @@ def sample_get_tcp_route(): method. name (str): Required. A name of the TcpRoute to get. Must be in the - format ``projects/*/locations/global/tcpRoutes/*``. + format ``projects/*/locations/*/tcpRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -5347,7 +5393,7 @@ def sample_create_tcp_route(): The request object. Request used by the TcpRoute method. parent (str): Required. The parent resource of the TcpRoute. Must be - in the format ``projects/*/locations/global``. + in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -5622,7 +5668,7 @@ def sample_delete_tcp_route(): method. name (str): Required. A name of the TcpRoute to delete. Must be in - the format ``projects/*/locations/global/tcpRoutes/*``. + the format ``projects/*/locations/*/tcpRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -5750,7 +5796,7 @@ def sample_list_tls_routes(): parent (str): Required. The project and location from which the TlsRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -5872,7 +5918,7 @@ def sample_get_tls_route(): method. name (str): Required. A name of the TlsRoute to get. Must be in the - format ``projects/*/locations/global/tlsRoutes/*``. + format ``projects/*/locations/*/tlsRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -5992,7 +6038,7 @@ def sample_create_tls_route(): The request object. Request used by the TlsRoute method. parent (str): Required. The parent resource of the TlsRoute. Must be - in the format ``projects/*/locations/global``. + in the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -6271,7 +6317,7 @@ def sample_delete_tls_route(): method. name (str): Required. A name of the TlsRoute to delete. Must be in - the format ``projects/*/locations/global/tlsRoutes/*``. + the format ``projects/*/locations/*/tlsRoutes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -7077,7 +7123,7 @@ def sample_list_meshes(): parent (str): Required. The project and location from which the Meshes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -7198,7 +7244,7 @@ def sample_get_mesh(): The request object. Request used by the GetMesh method. name (str): Required. A name of the Mesh to get. Must be in the - format ``projects/*/locations/global/meshes/*``. + format ``projects/*/locations/*/meshes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -7317,7 +7363,7 @@ def sample_create_mesh(): method. parent (str): Required. The parent resource of the Mesh. Must be in - the format ``projects/*/locations/global``. + the format ``projects/*/locations/*``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -7596,7 +7642,7 @@ def sample_delete_mesh(): method. name (str): Required. A name of the Mesh to delete. Must be in the - format ``projects/*/locations/global/meshes/*``. + format ``projects/*/locations/*/meshes/*``. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -8810,6 +8856,656 @@ def sample_list_mesh_route_views(): # Done; return the response. return response + def list_agent_gateways( + self, + request: Optional[Union[agent_gateway.ListAgentGatewaysRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> pagers.ListAgentGatewaysPager: + r"""Lists AgentGateways in a given project and location. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + def sample_list_agent_gateways(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.ListAgentGatewaysRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_agent_gateways(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.network_services_v1.types.ListAgentGatewaysRequest, dict]): + The request object. Request used with the + ListAgentGateways method. + parent (str): + Required. The project and location from which the + AgentGateways should be listed, specified in the format + ``projects/*/locations/*``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.cloud.network_services_v1.services.network_services.pagers.ListAgentGatewaysPager: + Response returned by the + ListAgentGateways method. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, agent_gateway.ListAgentGatewaysRequest): + request = agent_gateway.ListAgentGatewaysRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_agent_gateways] + + # 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),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListAgentGatewaysPager( + method=rpc, + request=request, + response=response, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_agent_gateway( + self, + request: Optional[Union[agent_gateway.GetAgentGatewayRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> agent_gateway.AgentGateway: + r"""Gets details of a single AgentGateway. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + def sample_get_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.GetAgentGatewayRequest( + name="name_value", + ) + + # Make the request + response = client.get_agent_gateway(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.network_services_v1.types.GetAgentGatewayRequest, dict]): + The request object. Request used by the GetAgentGateway + method. + name (str): + Required. A name of the AgentGateway to get. Must be in + the format ``projects/*/locations/*/agentGateways/*``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.cloud.network_services_v1.types.AgentGateway: + AgentGateway represents the agent + gateway resource. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, agent_gateway.GetAgentGatewayRequest): + request = agent_gateway.GetAgentGatewayRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_agent_gateway] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def create_agent_gateway( + self, + request: Optional[ + Union[gcn_agent_gateway.CreateAgentGatewayRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + agent_gateway: Optional[gcn_agent_gateway.AgentGateway] = None, + agent_gateway_id: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation.Operation: + r"""Creates a new AgentGateway in a given project and + location. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + def sample_create_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.CreateAgentGatewayRequest( + parent="parent_value", + agent_gateway_id="agent_gateway_id_value", + ) + + # Make the request + operation = client.create_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.network_services_v1.types.CreateAgentGatewayRequest, dict]): + The request object. Request used by the + CreateAgentGateway method. + parent (str): + Required. The parent resource of the AgentGateway. Must + be in the format ``projects/*/locations/*``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + agent_gateway (google.cloud.network_services_v1.types.AgentGateway): + Required. AgentGateway resource to be + created. + + This corresponds to the ``agent_gateway`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + agent_gateway_id (str): + Required. Short name of the + AgentGateway resource to be created. + + This corresponds to the ``agent_gateway_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.network_services_v1.types.AgentGateway` + AgentGateway represents the agent gateway resource. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent, agent_gateway, agent_gateway_id] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, gcn_agent_gateway.CreateAgentGatewayRequest): + request = gcn_agent_gateway.CreateAgentGatewayRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if agent_gateway is not None: + request.agent_gateway = agent_gateway + if agent_gateway_id is not None: + request.agent_gateway_id = agent_gateway_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_agent_gateway] + + # 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),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + gcn_agent_gateway.AgentGateway, + metadata_type=common.OperationMetadata, + ) + + # Done; return the response. + return response + + def update_agent_gateway( + self, + request: Optional[ + Union[gcn_agent_gateway.UpdateAgentGatewayRequest, dict] + ] = None, + *, + agent_gateway: Optional[gcn_agent_gateway.AgentGateway] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation.Operation: + r"""Updates the parameters of a single AgentGateway. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + def sample_update_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.UpdateAgentGatewayRequest( + ) + + # Make the request + operation = client.update_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.network_services_v1.types.UpdateAgentGatewayRequest, dict]): + The request object. Request used by the + UpdateAgentGateway method. + agent_gateway (google.cloud.network_services_v1.types.AgentGateway): + Required. Updated AgentGateway + resource. + + This corresponds to the ``agent_gateway`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Field mask is used to specify the fields to be + overwritten in the AgentGateway resource by the update. + The fields specified in the update_mask are relative to + the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then all fields will be overwritten. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.network_services_v1.types.AgentGateway` + AgentGateway represents the agent gateway resource. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [agent_gateway, update_mask] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, gcn_agent_gateway.UpdateAgentGatewayRequest): + request = gcn_agent_gateway.UpdateAgentGatewayRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if agent_gateway is not None: + request.agent_gateway = agent_gateway + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_agent_gateway] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("agent_gateway.name", request.agent_gateway.name),) + ), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + gcn_agent_gateway.AgentGateway, + metadata_type=common.OperationMetadata, + ) + + # Done; return the response. + return response + + def delete_agent_gateway( + self, + request: Optional[Union[agent_gateway.DeleteAgentGatewayRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation.Operation: + r"""Deletes a single AgentGateway. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import network_services_v1 + + def sample_delete_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.DeleteAgentGatewayRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.network_services_v1.types.DeleteAgentGatewayRequest, dict]): + The request object. Request used by the + DeleteAgentGateway method. + name (str): + Required. A name of the AgentGateway to delete. Must be + in the format + ``projects/*/locations/*/agentGateways/*``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, agent_gateway.DeleteAgentGatewayRequest): + request = agent_gateway.DeleteAgentGatewayRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_agent_gateway] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=common.OperationMetadata, + ) + + # Done; return the response. + return response + def __enter__(self) -> "NetworkServicesClient": return self diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/pagers.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/pagers.py index 3af46ee8792f..1d3fa398d197 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/pagers.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/pagers.py @@ -39,6 +39,7 @@ OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore from google.cloud.network_services_v1.types import ( + agent_gateway, endpoint_policy, extensibility, gateway, @@ -2087,3 +2088,159 @@ async def async_generator(): def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListAgentGatewaysPager: + """A pager for iterating through ``list_agent_gateways`` requests. + + This class thinly wraps an initial + :class:`google.cloud.network_services_v1.types.ListAgentGatewaysResponse` object, and + provides an ``__iter__`` method to iterate through its + ``agent_gateways`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListAgentGateways`` requests and continue to iterate + through the ``agent_gateways`` field on the + corresponding responses. + + All the usual :class:`google.cloud.network_services_v1.types.ListAgentGatewaysResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., agent_gateway.ListAgentGatewaysResponse], + request: agent_gateway.ListAgentGatewaysRequest, + response: agent_gateway.ListAgentGatewaysResponse, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.network_services_v1.types.ListAgentGatewaysRequest): + The initial request object. + response (google.cloud.network_services_v1.types.ListAgentGatewaysResponse): + The initial response object. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + self._method = method + self._request = agent_gateway.ListAgentGatewaysRequest(request) + self._response = response + self._retry = retry + self._timeout = timeout + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[agent_gateway.ListAgentGatewaysResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method( + self._request, + retry=self._retry, + timeout=self._timeout, + metadata=self._metadata, + ) + yield self._response + + def __iter__(self) -> Iterator[agent_gateway.AgentGateway]: + for page in self.pages: + yield from page.agent_gateways + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListAgentGatewaysAsyncPager: + """A pager for iterating through ``list_agent_gateways`` requests. + + This class thinly wraps an initial + :class:`google.cloud.network_services_v1.types.ListAgentGatewaysResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``agent_gateways`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListAgentGateways`` requests and continue to iterate + through the ``agent_gateways`` field on the + corresponding responses. + + All the usual :class:`google.cloud.network_services_v1.types.ListAgentGatewaysResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[agent_gateway.ListAgentGatewaysResponse]], + request: agent_gateway.ListAgentGatewaysRequest, + response: agent_gateway.ListAgentGatewaysResponse, + *, + retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.network_services_v1.types.ListAgentGatewaysRequest): + The initial request object. + response (google.cloud.network_services_v1.types.ListAgentGatewaysResponse): + The initial response object. + retry (google.api_core.retry.AsyncRetry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + self._method = method + self._request = agent_gateway.ListAgentGatewaysRequest(request) + self._response = response + self._retry = retry + self._timeout = timeout + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[agent_gateway.ListAgentGatewaysResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method( + self._request, + retry=self._retry, + timeout=self._timeout, + metadata=self._metadata, + ) + yield self._response + + def __aiter__(self) -> AsyncIterator[agent_gateway.AgentGateway]: + async def async_generator(): + async for page in self.pages: + for response in page.agent_gateways: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/base.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/base.py index 816ed741c1dc..3fd452dfab0b 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/base.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/base.py @@ -33,6 +33,7 @@ from google.cloud.network_services_v1 import gapic_version as package_version from google.cloud.network_services_v1.types import ( + agent_gateway, endpoint_policy, extensibility, gateway, @@ -45,6 +46,7 @@ tcp_route, tls_route, ) +from google.cloud.network_services_v1.types import agent_gateway as gcn_agent_gateway from google.cloud.network_services_v1.types import ( endpoint_policy as gcn_endpoint_policy, ) @@ -465,6 +467,31 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.list_agent_gateways: gapic_v1.method.wrap_method( + self.list_agent_gateways, + default_timeout=None, + client_info=client_info, + ), + self.get_agent_gateway: gapic_v1.method.wrap_method( + self.get_agent_gateway, + default_timeout=None, + client_info=client_info, + ), + self.create_agent_gateway: gapic_v1.method.wrap_method( + self.create_agent_gateway, + default_timeout=None, + client_info=client_info, + ), + self.update_agent_gateway: gapic_v1.method.wrap_method( + self.update_agent_gateway, + default_timeout=None, + client_info=client_info, + ), + self.delete_agent_gateway: gapic_v1.method.wrap_method( + self.delete_agent_gateway, + default_timeout=None, + client_info=client_info, + ), self.get_location: gapic_v1.method.wrap_method( self.get_location, default_timeout=None, @@ -1084,6 +1111,54 @@ def list_mesh_route_views( ]: raise NotImplementedError() + @property + def list_agent_gateways( + self, + ) -> Callable[ + [agent_gateway.ListAgentGatewaysRequest], + Union[ + agent_gateway.ListAgentGatewaysResponse, + Awaitable[agent_gateway.ListAgentGatewaysResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_agent_gateway( + self, + ) -> Callable[ + [agent_gateway.GetAgentGatewayRequest], + Union[agent_gateway.AgentGateway, Awaitable[agent_gateway.AgentGateway]], + ]: + raise NotImplementedError() + + @property + def create_agent_gateway( + self, + ) -> Callable[ + [gcn_agent_gateway.CreateAgentGatewayRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def update_agent_gateway( + self, + ) -> Callable[ + [gcn_agent_gateway.UpdateAgentGatewayRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def delete_agent_gateway( + self, + ) -> Callable[ + [agent_gateway.DeleteAgentGatewayRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def list_operations( self, diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/grpc.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/grpc.py index 68120140d2f0..ba228dd6cf0a 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/grpc.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/grpc.py @@ -35,6 +35,7 @@ from google.protobuf.json_format import MessageToJson from google.cloud.network_services_v1.types import ( + agent_gateway, endpoint_policy, extensibility, gateway, @@ -47,6 +48,7 @@ tcp_route, tls_route, ) +from google.cloud.network_services_v1.types import agent_gateway as gcn_agent_gateway from google.cloud.network_services_v1.types import ( endpoint_policy as gcn_endpoint_policy, ) @@ -1949,6 +1951,144 @@ def list_mesh_route_views( ) return self._stubs["list_mesh_route_views"] + @property + def list_agent_gateways( + self, + ) -> Callable[ + [agent_gateway.ListAgentGatewaysRequest], + agent_gateway.ListAgentGatewaysResponse, + ]: + r"""Return a callable for the list agent gateways method over gRPC. + + Lists AgentGateways in a given project and location. + + Returns: + Callable[[~.ListAgentGatewaysRequest], + ~.ListAgentGatewaysResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_agent_gateways" not in self._stubs: + self._stubs["list_agent_gateways"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/ListAgentGateways", + request_serializer=agent_gateway.ListAgentGatewaysRequest.serialize, + response_deserializer=agent_gateway.ListAgentGatewaysResponse.deserialize, + ) + return self._stubs["list_agent_gateways"] + + @property + def get_agent_gateway( + self, + ) -> Callable[[agent_gateway.GetAgentGatewayRequest], agent_gateway.AgentGateway]: + r"""Return a callable for the get agent gateway method over gRPC. + + Gets details of a single AgentGateway. + + Returns: + Callable[[~.GetAgentGatewayRequest], + ~.AgentGateway]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_agent_gateway" not in self._stubs: + self._stubs["get_agent_gateway"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/GetAgentGateway", + request_serializer=agent_gateway.GetAgentGatewayRequest.serialize, + response_deserializer=agent_gateway.AgentGateway.deserialize, + ) + return self._stubs["get_agent_gateway"] + + @property + def create_agent_gateway( + self, + ) -> Callable[ + [gcn_agent_gateway.CreateAgentGatewayRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create agent gateway method over gRPC. + + Creates a new AgentGateway in a given project and + location. + + Returns: + Callable[[~.CreateAgentGatewayRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_agent_gateway" not in self._stubs: + self._stubs["create_agent_gateway"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/CreateAgentGateway", + request_serializer=gcn_agent_gateway.CreateAgentGatewayRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_agent_gateway"] + + @property + def update_agent_gateway( + self, + ) -> Callable[ + [gcn_agent_gateway.UpdateAgentGatewayRequest], operations_pb2.Operation + ]: + r"""Return a callable for the update agent gateway method over gRPC. + + Updates the parameters of a single AgentGateway. + + Returns: + Callable[[~.UpdateAgentGatewayRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_agent_gateway" not in self._stubs: + self._stubs["update_agent_gateway"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/UpdateAgentGateway", + request_serializer=gcn_agent_gateway.UpdateAgentGatewayRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_agent_gateway"] + + @property + def delete_agent_gateway( + self, + ) -> Callable[[agent_gateway.DeleteAgentGatewayRequest], operations_pb2.Operation]: + r"""Return a callable for the delete agent gateway method over gRPC. + + Deletes a single AgentGateway. + + Returns: + Callable[[~.DeleteAgentGatewayRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_agent_gateway" not in self._stubs: + self._stubs["delete_agent_gateway"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/DeleteAgentGateway", + request_serializer=agent_gateway.DeleteAgentGatewayRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_agent_gateway"] + def close(self): self._logged_channel.close() diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/grpc_asyncio.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/grpc_asyncio.py index e3a12d68dfea..2a83c39fdc93 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/grpc_asyncio.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/grpc_asyncio.py @@ -38,6 +38,7 @@ from grpc.experimental import aio # type: ignore from google.cloud.network_services_v1.types import ( + agent_gateway, endpoint_policy, extensibility, gateway, @@ -50,6 +51,7 @@ tcp_route, tls_route, ) +from google.cloud.network_services_v1.types import agent_gateway as gcn_agent_gateway from google.cloud.network_services_v1.types import ( endpoint_policy as gcn_endpoint_policy, ) @@ -2022,6 +2024,150 @@ def list_mesh_route_views( ) return self._stubs["list_mesh_route_views"] + @property + def list_agent_gateways( + self, + ) -> Callable[ + [agent_gateway.ListAgentGatewaysRequest], + Awaitable[agent_gateway.ListAgentGatewaysResponse], + ]: + r"""Return a callable for the list agent gateways method over gRPC. + + Lists AgentGateways in a given project and location. + + Returns: + Callable[[~.ListAgentGatewaysRequest], + Awaitable[~.ListAgentGatewaysResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_agent_gateways" not in self._stubs: + self._stubs["list_agent_gateways"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/ListAgentGateways", + request_serializer=agent_gateway.ListAgentGatewaysRequest.serialize, + response_deserializer=agent_gateway.ListAgentGatewaysResponse.deserialize, + ) + return self._stubs["list_agent_gateways"] + + @property + def get_agent_gateway( + self, + ) -> Callable[ + [agent_gateway.GetAgentGatewayRequest], Awaitable[agent_gateway.AgentGateway] + ]: + r"""Return a callable for the get agent gateway method over gRPC. + + Gets details of a single AgentGateway. + + Returns: + Callable[[~.GetAgentGatewayRequest], + Awaitable[~.AgentGateway]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_agent_gateway" not in self._stubs: + self._stubs["get_agent_gateway"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/GetAgentGateway", + request_serializer=agent_gateway.GetAgentGatewayRequest.serialize, + response_deserializer=agent_gateway.AgentGateway.deserialize, + ) + return self._stubs["get_agent_gateway"] + + @property + def create_agent_gateway( + self, + ) -> Callable[ + [gcn_agent_gateway.CreateAgentGatewayRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the create agent gateway method over gRPC. + + Creates a new AgentGateway in a given project and + location. + + Returns: + Callable[[~.CreateAgentGatewayRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_agent_gateway" not in self._stubs: + self._stubs["create_agent_gateway"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/CreateAgentGateway", + request_serializer=gcn_agent_gateway.CreateAgentGatewayRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_agent_gateway"] + + @property + def update_agent_gateway( + self, + ) -> Callable[ + [gcn_agent_gateway.UpdateAgentGatewayRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the update agent gateway method over gRPC. + + Updates the parameters of a single AgentGateway. + + Returns: + Callable[[~.UpdateAgentGatewayRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_agent_gateway" not in self._stubs: + self._stubs["update_agent_gateway"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/UpdateAgentGateway", + request_serializer=gcn_agent_gateway.UpdateAgentGatewayRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_agent_gateway"] + + @property + def delete_agent_gateway( + self, + ) -> Callable[ + [agent_gateway.DeleteAgentGatewayRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete agent gateway method over gRPC. + + Deletes a single AgentGateway. + + Returns: + Callable[[~.DeleteAgentGatewayRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_agent_gateway" not in self._stubs: + self._stubs["delete_agent_gateway"] = self._logged_channel.unary_unary( + "/google.cloud.networkservices.v1.NetworkServices/DeleteAgentGateway", + request_serializer=agent_gateway.DeleteAgentGatewayRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_agent_gateway"] + def _prep_wrapped_messages(self, client_info): """Precompute the wrapped methods, overriding the base class method to use async wrappers.""" self._wrapped_methods = { @@ -2315,6 +2461,31 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.list_agent_gateways: self._wrap_method( + self.list_agent_gateways, + default_timeout=None, + client_info=client_info, + ), + self.get_agent_gateway: self._wrap_method( + self.get_agent_gateway, + default_timeout=None, + client_info=client_info, + ), + self.create_agent_gateway: self._wrap_method( + self.create_agent_gateway, + default_timeout=None, + client_info=client_info, + ), + self.update_agent_gateway: self._wrap_method( + self.update_agent_gateway, + default_timeout=None, + client_info=client_info, + ), + self.delete_agent_gateway: self._wrap_method( + self.delete_agent_gateway, + default_timeout=None, + client_info=client_info, + ), self.get_location: self._wrap_method( self.get_location, default_timeout=None, diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/rest.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/rest.py index a417f9eaa720..be7f856c9835 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/rest.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/rest.py @@ -35,6 +35,7 @@ from requests import __version__ as requests_version from google.cloud.network_services_v1.types import ( + agent_gateway, endpoint_policy, extensibility, gateway, @@ -47,6 +48,7 @@ tcp_route, tls_route, ) +from google.cloud.network_services_v1.types import agent_gateway as gcn_agent_gateway from google.cloud.network_services_v1.types import ( endpoint_policy as gcn_endpoint_policy, ) @@ -105,6 +107,14 @@ class NetworkServicesRestInterceptor: .. code-block:: python class MyCustomNetworkServicesInterceptor(NetworkServicesRestInterceptor): + def pre_create_agent_gateway(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_agent_gateway(self, response): + logging.log(f"Received response: {response}") + return response + def pre_create_endpoint_policy(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -193,6 +203,14 @@ def post_create_wasm_plugin_version(self, response): logging.log(f"Received response: {response}") return response + def pre_delete_agent_gateway(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_delete_agent_gateway(self, response): + logging.log(f"Received response: {response}") + return response + def pre_delete_endpoint_policy(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -281,6 +299,14 @@ def post_delete_wasm_plugin_version(self, response): logging.log(f"Received response: {response}") return response + def pre_get_agent_gateway(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_agent_gateway(self, response): + logging.log(f"Received response: {response}") + return response + def pre_get_endpoint_policy(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -385,6 +411,14 @@ def post_get_wasm_plugin_version(self, response): logging.log(f"Received response: {response}") return response + def pre_list_agent_gateways(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_agent_gateways(self, response): + logging.log(f"Received response: {response}") + return response + def pre_list_endpoint_policies(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -489,6 +523,14 @@ def post_list_wasm_plugin_versions(self, response): logging.log(f"Received response: {response}") return response + def pre_update_agent_gateway(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_agent_gateway(self, response): + logging.log(f"Received response: {response}") + return response + def pre_update_endpoint_policy(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -575,6 +617,55 @@ def post_update_wasm_plugin(self, response): """ + def pre_create_agent_gateway( + self, + request: gcn_agent_gateway.CreateAgentGatewayRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + gcn_agent_gateway.CreateAgentGatewayRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for create_agent_gateway + + Override in a subclass to manipulate the request or metadata + before they are sent to the NetworkServices server. + """ + return request, metadata + + def post_create_agent_gateway( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for create_agent_gateway + + DEPRECATED. Please use the `post_create_agent_gateway_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the NetworkServices server but before + it is returned to user code. This `post_create_agent_gateway` interceptor runs + before the `post_create_agent_gateway_with_metadata` interceptor. + """ + return response + + def post_create_agent_gateway_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for create_agent_gateway + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the NetworkServices server but before it is returned to user code. + + We recommend only using this `post_create_agent_gateway_with_metadata` + interceptor in new development instead of the `post_create_agent_gateway` interceptor. + When both interceptors are used, this `post_create_agent_gateway_with_metadata` interceptor runs after the + `post_create_agent_gateway` interceptor. The (possibly modified) response returned by + `post_create_agent_gateway` will be passed to + `post_create_agent_gateway_with_metadata`. + """ + return response, metadata + def pre_create_endpoint_policy( self, request: gcn_endpoint_policy.CreateEndpointPolicyRequest, @@ -1105,6 +1196,54 @@ def post_create_wasm_plugin_version_with_metadata( """ return response, metadata + def pre_delete_agent_gateway( + self, + request: agent_gateway.DeleteAgentGatewayRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + agent_gateway.DeleteAgentGatewayRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for delete_agent_gateway + + Override in a subclass to manipulate the request or metadata + before they are sent to the NetworkServices server. + """ + return request, metadata + + def post_delete_agent_gateway( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for delete_agent_gateway + + DEPRECATED. Please use the `post_delete_agent_gateway_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the NetworkServices server but before + it is returned to user code. This `post_delete_agent_gateway` interceptor runs + before the `post_delete_agent_gateway_with_metadata` interceptor. + """ + return response + + def post_delete_agent_gateway_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for delete_agent_gateway + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the NetworkServices server but before it is returned to user code. + + We recommend only using this `post_delete_agent_gateway_with_metadata` + interceptor in new development instead of the `post_delete_agent_gateway` interceptor. + When both interceptors are used, this `post_delete_agent_gateway_with_metadata` interceptor runs after the + `post_delete_agent_gateway` interceptor. The (possibly modified) response returned by + `post_delete_agent_gateway` will be passed to + `post_delete_agent_gateway_with_metadata`. + """ + return response, metadata + def pre_delete_endpoint_policy( self, request: endpoint_policy.DeleteEndpointPolicyRequest, @@ -1633,6 +1772,54 @@ def post_delete_wasm_plugin_version_with_metadata( """ return response, metadata + def pre_get_agent_gateway( + self, + request: agent_gateway.GetAgentGatewayRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + agent_gateway.GetAgentGatewayRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for get_agent_gateway + + Override in a subclass to manipulate the request or metadata + before they are sent to the NetworkServices server. + """ + return request, metadata + + def post_get_agent_gateway( + self, response: agent_gateway.AgentGateway + ) -> agent_gateway.AgentGateway: + """Post-rpc interceptor for get_agent_gateway + + DEPRECATED. Please use the `post_get_agent_gateway_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the NetworkServices server but before + it is returned to user code. This `post_get_agent_gateway` interceptor runs + before the `post_get_agent_gateway_with_metadata` interceptor. + """ + return response + + def post_get_agent_gateway_with_metadata( + self, + response: agent_gateway.AgentGateway, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[agent_gateway.AgentGateway, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_agent_gateway + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the NetworkServices server but before it is returned to user code. + + We recommend only using this `post_get_agent_gateway_with_metadata` + interceptor in new development instead of the `post_get_agent_gateway` interceptor. + When both interceptors are used, this `post_get_agent_gateway_with_metadata` interceptor runs after the + `post_get_agent_gateway` interceptor. The (possibly modified) response returned by + `post_get_agent_gateway` will be passed to + `post_get_agent_gateway_with_metadata`. + """ + return response, metadata + def pre_get_endpoint_policy( self, request: endpoint_policy.GetEndpointPolicyRequest, @@ -2243,6 +2430,56 @@ def post_get_wasm_plugin_version_with_metadata( """ return response, metadata + def pre_list_agent_gateways( + self, + request: agent_gateway.ListAgentGatewaysRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + agent_gateway.ListAgentGatewaysRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for list_agent_gateways + + Override in a subclass to manipulate the request or metadata + before they are sent to the NetworkServices server. + """ + return request, metadata + + def post_list_agent_gateways( + self, response: agent_gateway.ListAgentGatewaysResponse + ) -> agent_gateway.ListAgentGatewaysResponse: + """Post-rpc interceptor for list_agent_gateways + + DEPRECATED. Please use the `post_list_agent_gateways_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the NetworkServices server but before + it is returned to user code. This `post_list_agent_gateways` interceptor runs + before the `post_list_agent_gateways_with_metadata` interceptor. + """ + return response + + def post_list_agent_gateways_with_metadata( + self, + response: agent_gateway.ListAgentGatewaysResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + agent_gateway.ListAgentGatewaysResponse, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Post-rpc interceptor for list_agent_gateways + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the NetworkServices server but before it is returned to user code. + + We recommend only using this `post_list_agent_gateways_with_metadata` + interceptor in new development instead of the `post_list_agent_gateways` interceptor. + When both interceptors are used, this `post_list_agent_gateways_with_metadata` interceptor runs after the + `post_list_agent_gateways` interceptor. The (possibly modified) response returned by + `post_list_agent_gateways` will be passed to + `post_list_agent_gateways_with_metadata`. + """ + return response, metadata + def pre_list_endpoint_policies( self, request: endpoint_policy.ListEndpointPoliciesRequest, @@ -2890,6 +3127,55 @@ def post_list_wasm_plugin_versions_with_metadata( """ return response, metadata + def pre_update_agent_gateway( + self, + request: gcn_agent_gateway.UpdateAgentGatewayRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + gcn_agent_gateway.UpdateAgentGatewayRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for update_agent_gateway + + Override in a subclass to manipulate the request or metadata + before they are sent to the NetworkServices server. + """ + return request, metadata + + def post_update_agent_gateway( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for update_agent_gateway + + DEPRECATED. Please use the `post_update_agent_gateway_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the NetworkServices server but before + it is returned to user code. This `post_update_agent_gateway` interceptor runs + before the `post_update_agent_gateway_with_metadata` interceptor. + """ + return response + + def post_update_agent_gateway_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for update_agent_gateway + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the NetworkServices server but before it is returned to user code. + + We recommend only using this `post_update_agent_gateway_with_metadata` + interceptor in new development instead of the `post_update_agent_gateway` interceptor. + When both interceptors are used, this `post_update_agent_gateway_with_metadata` interceptor runs after the + `post_update_agent_gateway` interceptor. The (possibly modified) response returned by + `post_update_agent_gateway` will be passed to + `post_update_agent_gateway_with_metadata`. + """ + return response, metadata + def pre_update_endpoint_policy( self, request: gcn_endpoint_policy.UpdateEndpointPolicyRequest, @@ -3737,12 +4023,12 @@ def operations_client(self) -> operations_v1.AbstractOperationsClient: # Return the client from cache. return self._operations_client - class _CreateEndpointPolicy( - _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy, + class _CreateAgentGateway( + _BaseNetworkServicesRestTransport._BaseCreateAgentGateway, NetworkServicesRestStub, ): def __hash__(self): - return hash("NetworkServicesRestTransport.CreateEndpointPolicy") + return hash("NetworkServicesRestTransport.CreateAgentGateway") @staticmethod def _get_response( @@ -3769,18 +4055,18 @@ def _get_response( def __call__( self, - request: gcn_endpoint_policy.CreateEndpointPolicyRequest, + request: gcn_agent_gateway.CreateAgentGatewayRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: - r"""Call the create endpoint policy method over HTTP. + r"""Call the create agent gateway method over HTTP. Args: - request (~.gcn_endpoint_policy.CreateEndpointPolicyRequest): - The request object. Request used with the - CreateEndpointPolicy method. + request (~.gcn_agent_gateway.CreateAgentGatewayRequest): + The request object. Request used by the + CreateAgentGateway method. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -3797,21 +4083,21 @@ def __call__( """ - http_options = _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy._get_http_options() + http_options = _BaseNetworkServicesRestTransport._BaseCreateAgentGateway._get_http_options() - request, metadata = self._interceptor.pre_create_endpoint_policy( + request, metadata = self._interceptor.pre_create_agent_gateway( request, metadata ) - transcoded_request = _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy._get_transcoded_request( + transcoded_request = _BaseNetworkServicesRestTransport._BaseCreateAgentGateway._get_transcoded_request( http_options, request ) - body = _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy._get_request_body_json( + body = _BaseNetworkServicesRestTransport._BaseCreateAgentGateway._get_request_body_json( transcoded_request ) # Jsonify the query params - query_params = _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy._get_query_params_json( + query_params = _BaseNetworkServicesRestTransport._BaseCreateAgentGateway._get_query_params_json( transcoded_request ) @@ -3833,17 +4119,17 @@ def __call__( "headers": dict(metadata), } _LOGGER.debug( - f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.CreateEndpointPolicy", + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.CreateAgentGateway", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "CreateEndpointPolicy", + "rpcName": "CreateAgentGateway", "httpRequest": http_request, "metadata": http_request["headers"], }, ) # Send the request - response = NetworkServicesRestTransport._CreateEndpointPolicy._get_response( + response = NetworkServicesRestTransport._CreateAgentGateway._get_response( self._host, metadata, query_params, @@ -3862,9 +4148,9 @@ def __call__( resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_endpoint_policy(resp) + resp = self._interceptor.post_create_agent_gateway(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_create_endpoint_policy_with_metadata( + resp, _ = self._interceptor.post_create_agent_gateway_with_metadata( resp, response_metadata ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( @@ -3880,21 +4166,22 @@ def __call__( "status": response.status_code, } _LOGGER.debug( - "Received response for google.cloud.networkservices_v1.NetworkServicesClient.create_endpoint_policy", + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.create_agent_gateway", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "CreateEndpointPolicy", + "rpcName": "CreateAgentGateway", "metadata": http_response["headers"], "httpResponse": http_response, }, ) return resp - class _CreateGateway( - _BaseNetworkServicesRestTransport._BaseCreateGateway, NetworkServicesRestStub + class _CreateEndpointPolicy( + _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy, + NetworkServicesRestStub, ): def __hash__(self): - return hash("NetworkServicesRestTransport.CreateGateway") + return hash("NetworkServicesRestTransport.CreateEndpointPolicy") @staticmethod def _get_response( @@ -3921,18 +4208,18 @@ def _get_response( def __call__( self, - request: gcn_gateway.CreateGatewayRequest, + request: gcn_endpoint_policy.CreateEndpointPolicyRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: - r"""Call the create gateway method over HTTP. + r"""Call the create endpoint policy method over HTTP. Args: - request (~.gcn_gateway.CreateGatewayRequest): - The request object. Request used by the CreateGateway - method. + request (~.gcn_endpoint_policy.CreateEndpointPolicyRequest): + The request object. Request used with the + CreateEndpointPolicy method. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -3949,21 +4236,21 @@ def __call__( """ - http_options = ( - _BaseNetworkServicesRestTransport._BaseCreateGateway._get_http_options() - ) + http_options = _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy._get_http_options() - request, metadata = self._interceptor.pre_create_gateway(request, metadata) - transcoded_request = _BaseNetworkServicesRestTransport._BaseCreateGateway._get_transcoded_request( + request, metadata = self._interceptor.pre_create_endpoint_policy( + request, metadata + ) + transcoded_request = _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy._get_transcoded_request( http_options, request ) - body = _BaseNetworkServicesRestTransport._BaseCreateGateway._get_request_body_json( + body = _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy._get_request_body_json( transcoded_request ) # Jsonify the query params - query_params = _BaseNetworkServicesRestTransport._BaseCreateGateway._get_query_params_json( + query_params = _BaseNetworkServicesRestTransport._BaseCreateEndpointPolicy._get_query_params_json( transcoded_request ) @@ -3985,17 +4272,17 @@ def __call__( "headers": dict(metadata), } _LOGGER.debug( - f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.CreateGateway", + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.CreateEndpointPolicy", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "CreateGateway", + "rpcName": "CreateEndpointPolicy", "httpRequest": http_request, "metadata": http_request["headers"], }, ) # Send the request - response = NetworkServicesRestTransport._CreateGateway._get_response( + response = NetworkServicesRestTransport._CreateEndpointPolicy._get_response( self._host, metadata, query_params, @@ -4014,9 +4301,9 @@ def __call__( resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_gateway(resp) + resp = self._interceptor.post_create_endpoint_policy(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_create_gateway_with_metadata( + resp, _ = self._interceptor.post_create_endpoint_policy_with_metadata( resp, response_metadata ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( @@ -4032,21 +4319,21 @@ def __call__( "status": response.status_code, } _LOGGER.debug( - "Received response for google.cloud.networkservices_v1.NetworkServicesClient.create_gateway", + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.create_endpoint_policy", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "CreateGateway", + "rpcName": "CreateEndpointPolicy", "metadata": http_response["headers"], "httpResponse": http_response, }, ) return resp - class _CreateGrpcRoute( - _BaseNetworkServicesRestTransport._BaseCreateGrpcRoute, NetworkServicesRestStub + class _CreateGateway( + _BaseNetworkServicesRestTransport._BaseCreateGateway, NetworkServicesRestStub ): def __hash__(self): - return hash("NetworkServicesRestTransport.CreateGrpcRoute") + return hash("NetworkServicesRestTransport.CreateGateway") @staticmethod def _get_response( @@ -4073,13 +4360,165 @@ def _get_response( def __call__( self, - request: gcn_grpc_route.CreateGrpcRouteRequest, + request: gcn_gateway.CreateGatewayRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: - r"""Call the create grpc route method over HTTP. + r"""Call the create gateway method over HTTP. + + Args: + request (~.gcn_gateway.CreateGatewayRequest): + The request object. Request used by the CreateGateway + method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BaseNetworkServicesRestTransport._BaseCreateGateway._get_http_options() + ) + + request, metadata = self._interceptor.pre_create_gateway(request, metadata) + transcoded_request = _BaseNetworkServicesRestTransport._BaseCreateGateway._get_transcoded_request( + http_options, request + ) + + body = _BaseNetworkServicesRestTransport._BaseCreateGateway._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BaseNetworkServicesRestTransport._BaseCreateGateway._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.CreateGateway", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "CreateGateway", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = NetworkServicesRestTransport._CreateGateway._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_create_gateway(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_create_gateway_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.create_gateway", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "CreateGateway", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _CreateGrpcRoute( + _BaseNetworkServicesRestTransport._BaseCreateGrpcRoute, NetworkServicesRestStub + ): + def __hash__(self): + return hash("NetworkServicesRestTransport.CreateGrpcRoute") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: gcn_grpc_route.CreateGrpcRouteRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the create grpc route method over HTTP. Args: request (~.gcn_grpc_route.CreateGrpcRouteRequest): @@ -5413,6 +5852,153 @@ def __call__( ) return resp + class _DeleteAgentGateway( + _BaseNetworkServicesRestTransport._BaseDeleteAgentGateway, + NetworkServicesRestStub, + ): + def __hash__(self): + return hash("NetworkServicesRestTransport.DeleteAgentGateway") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: agent_gateway.DeleteAgentGatewayRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the delete agent gateway method over HTTP. + + Args: + request (~.agent_gateway.DeleteAgentGatewayRequest): + The request object. Request used by the + DeleteAgentGateway method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = _BaseNetworkServicesRestTransport._BaseDeleteAgentGateway._get_http_options() + + request, metadata = self._interceptor.pre_delete_agent_gateway( + request, metadata + ) + transcoded_request = _BaseNetworkServicesRestTransport._BaseDeleteAgentGateway._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseNetworkServicesRestTransport._BaseDeleteAgentGateway._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.DeleteAgentGateway", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "DeleteAgentGateway", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = NetworkServicesRestTransport._DeleteAgentGateway._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_delete_agent_gateway(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_delete_agent_gateway_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.delete_agent_gateway", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "DeleteAgentGateway", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + class _DeleteEndpointPolicy( _BaseNetworkServicesRestTransport._BaseDeleteEndpointPolicy, NetworkServicesRestStub, @@ -6781,25 +7367,172 @@ def __call__( but for metadata keys ending with the suffix `-bin`, the corresponding values must be of type `bytes`. - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = _BaseNetworkServicesRestTransport._BaseDeleteWasmPlugin._get_http_options() + + request, metadata = self._interceptor.pre_delete_wasm_plugin( + request, metadata + ) + transcoded_request = _BaseNetworkServicesRestTransport._BaseDeleteWasmPlugin._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseNetworkServicesRestTransport._BaseDeleteWasmPlugin._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.DeleteWasmPlugin", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "DeleteWasmPlugin", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = NetworkServicesRestTransport._DeleteWasmPlugin._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_delete_wasm_plugin(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_delete_wasm_plugin_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.delete_wasm_plugin", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "DeleteWasmPlugin", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _DeleteWasmPluginVersion( + _BaseNetworkServicesRestTransport._BaseDeleteWasmPluginVersion, + NetworkServicesRestStub, + ): + def __hash__(self): + return hash("NetworkServicesRestTransport.DeleteWasmPluginVersion") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: extensibility.DeleteWasmPluginVersionRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the delete wasm plugin + version method over HTTP. + + Args: + request (~.extensibility.DeleteWasmPluginVersionRequest): + The request object. Request used by the ``DeleteWasmPluginVersion`` method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. """ - http_options = _BaseNetworkServicesRestTransport._BaseDeleteWasmPlugin._get_http_options() + http_options = _BaseNetworkServicesRestTransport._BaseDeleteWasmPluginVersion._get_http_options() - request, metadata = self._interceptor.pre_delete_wasm_plugin( + request, metadata = self._interceptor.pre_delete_wasm_plugin_version( request, metadata ) - transcoded_request = _BaseNetworkServicesRestTransport._BaseDeleteWasmPlugin._get_transcoded_request( + transcoded_request = _BaseNetworkServicesRestTransport._BaseDeleteWasmPluginVersion._get_transcoded_request( http_options, request ) # Jsonify the query params - query_params = _BaseNetworkServicesRestTransport._BaseDeleteWasmPlugin._get_query_params_json( + query_params = _BaseNetworkServicesRestTransport._BaseDeleteWasmPluginVersion._get_query_params_json( transcoded_request ) @@ -6821,23 +7554,25 @@ def __call__( "headers": dict(metadata), } _LOGGER.debug( - f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.DeleteWasmPlugin", + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.DeleteWasmPluginVersion", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "DeleteWasmPlugin", + "rpcName": "DeleteWasmPluginVersion", "httpRequest": http_request, "metadata": http_request["headers"], }, ) # Send the request - response = NetworkServicesRestTransport._DeleteWasmPlugin._get_response( - self._host, - metadata, - query_params, - self._session, - timeout, - transcoded_request, + response = ( + NetworkServicesRestTransport._DeleteWasmPluginVersion._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -6849,9 +7584,9 @@ def __call__( resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_delete_wasm_plugin(resp) + resp = self._interceptor.post_delete_wasm_plugin_version(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_delete_wasm_plugin_with_metadata( + resp, _ = self._interceptor.post_delete_wasm_plugin_version_with_metadata( resp, response_metadata ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( @@ -6867,22 +7602,21 @@ def __call__( "status": response.status_code, } _LOGGER.debug( - "Received response for google.cloud.networkservices_v1.NetworkServicesClient.delete_wasm_plugin", + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.delete_wasm_plugin_version", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "DeleteWasmPlugin", + "rpcName": "DeleteWasmPluginVersion", "metadata": http_response["headers"], "httpResponse": http_response, }, ) return resp - class _DeleteWasmPluginVersion( - _BaseNetworkServicesRestTransport._BaseDeleteWasmPluginVersion, - NetworkServicesRestStub, + class _GetAgentGateway( + _BaseNetworkServicesRestTransport._BaseGetAgentGateway, NetworkServicesRestStub ): def __hash__(self): - return hash("NetworkServicesRestTransport.DeleteWasmPluginVersion") + return hash("NetworkServicesRestTransport.GetAgentGateway") @staticmethod def _get_response( @@ -6908,45 +7642,44 @@ def _get_response( def __call__( self, - request: extensibility.DeleteWasmPluginVersionRequest, + request: agent_gateway.GetAgentGatewayRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> operations_pb2.Operation: - r"""Call the delete wasm plugin - version method over HTTP. + ) -> agent_gateway.AgentGateway: + r"""Call the get agent gateway method over HTTP. - Args: - request (~.extensibility.DeleteWasmPluginVersionRequest): - The request object. Request used by the ``DeleteWasmPluginVersion`` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. + Args: + request (~.agent_gateway.GetAgentGatewayRequest): + The request object. Request used by the GetAgentGateway + method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. + Returns: + ~.agent_gateway.AgentGateway: + AgentGateway represents the agent + gateway resource. """ - http_options = _BaseNetworkServicesRestTransport._BaseDeleteWasmPluginVersion._get_http_options() + http_options = _BaseNetworkServicesRestTransport._BaseGetAgentGateway._get_http_options() - request, metadata = self._interceptor.pre_delete_wasm_plugin_version( + request, metadata = self._interceptor.pre_get_agent_gateway( request, metadata ) - transcoded_request = _BaseNetworkServicesRestTransport._BaseDeleteWasmPluginVersion._get_transcoded_request( + transcoded_request = _BaseNetworkServicesRestTransport._BaseGetAgentGateway._get_transcoded_request( http_options, request ) # Jsonify the query params - query_params = _BaseNetworkServicesRestTransport._BaseDeleteWasmPluginVersion._get_query_params_json( + query_params = _BaseNetworkServicesRestTransport._BaseGetAgentGateway._get_query_params_json( transcoded_request ) @@ -6968,25 +7701,23 @@ def __call__( "headers": dict(metadata), } _LOGGER.debug( - f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.DeleteWasmPluginVersion", + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.GetAgentGateway", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "DeleteWasmPluginVersion", + "rpcName": "GetAgentGateway", "httpRequest": http_request, "metadata": http_request["headers"], }, ) # Send the request - response = ( - NetworkServicesRestTransport._DeleteWasmPluginVersion._get_response( - self._host, - metadata, - query_params, - self._session, - timeout, - transcoded_request, - ) + response = NetworkServicesRestTransport._GetAgentGateway._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -6995,19 +7726,21 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = agent_gateway.AgentGateway() + pb_resp = agent_gateway.AgentGateway.pb(resp) - resp = self._interceptor.post_delete_wasm_plugin_version(resp) + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_get_agent_gateway(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_delete_wasm_plugin_version_with_metadata( + resp, _ = self._interceptor.post_get_agent_gateway_with_metadata( resp, response_metadata ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( logging.DEBUG ): # pragma: NO COVER try: - response_payload = json_format.MessageToJson(resp) + response_payload = agent_gateway.AgentGateway.to_json(response) except: response_payload = None http_response = { @@ -7016,10 +7749,10 @@ def __call__( "status": response.status_code, } _LOGGER.debug( - "Received response for google.cloud.networkservices_v1.NetworkServicesClient.delete_wasm_plugin_version", + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.get_agent_gateway", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "DeleteWasmPluginVersion", + "rpcName": "GetAgentGateway", "metadata": http_response["headers"], "httpResponse": http_response, }, @@ -8672,21 +9405,168 @@ def __call__( "status": response.status_code, } _LOGGER.debug( - "Received response for google.cloud.networkservices_v1.NetworkServicesClient.get_tls_route", + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.get_tls_route", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "GetTlsRoute", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _GetWasmPlugin( + _BaseNetworkServicesRestTransport._BaseGetWasmPlugin, NetworkServicesRestStub + ): + def __hash__(self): + return hash("NetworkServicesRestTransport.GetWasmPlugin") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: extensibility.GetWasmPluginRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> extensibility.WasmPlugin: + r"""Call the get wasm plugin method over HTTP. + + Args: + request (~.extensibility.GetWasmPluginRequest): + The request object. Request used by the ``GetWasmPlugin`` method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.extensibility.WasmPlugin: + ``WasmPlugin`` is a resource representing a service + executing a customer-provided Wasm module. + + """ + + http_options = ( + _BaseNetworkServicesRestTransport._BaseGetWasmPlugin._get_http_options() + ) + + request, metadata = self._interceptor.pre_get_wasm_plugin(request, metadata) + transcoded_request = _BaseNetworkServicesRestTransport._BaseGetWasmPlugin._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseNetworkServicesRestTransport._BaseGetWasmPlugin._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.GetWasmPlugin", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "GetWasmPlugin", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = NetworkServicesRestTransport._GetWasmPlugin._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = extensibility.WasmPlugin() + pb_resp = extensibility.WasmPlugin.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_get_wasm_plugin(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_wasm_plugin_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = extensibility.WasmPlugin.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.get_wasm_plugin", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "GetTlsRoute", + "rpcName": "GetWasmPlugin", "metadata": http_response["headers"], "httpResponse": http_response, }, ) return resp - class _GetWasmPlugin( - _BaseNetworkServicesRestTransport._BaseGetWasmPlugin, NetworkServicesRestStub + class _GetWasmPluginVersion( + _BaseNetworkServicesRestTransport._BaseGetWasmPluginVersion, + NetworkServicesRestStub, ): def __hash__(self): - return hash("NetworkServicesRestTransport.GetWasmPlugin") + return hash("NetworkServicesRestTransport.GetWasmPluginVersion") @staticmethod def _get_response( @@ -8712,17 +9592,17 @@ def _get_response( def __call__( self, - request: extensibility.GetWasmPluginRequest, + request: extensibility.GetWasmPluginVersionRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> extensibility.WasmPlugin: - r"""Call the get wasm plugin method over HTTP. + ) -> extensibility.WasmPluginVersion: + r"""Call the get wasm plugin version method over HTTP. Args: - request (~.extensibility.GetWasmPluginRequest): - The request object. Request used by the ``GetWasmPlugin`` method. + request (~.extensibility.GetWasmPluginVersionRequest): + The request object. Request used by the ``GetWasmPluginVersion`` method. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -8732,23 +9612,24 @@ def __call__( be of type `bytes`. Returns: - ~.extensibility.WasmPlugin: - ``WasmPlugin`` is a resource representing a service - executing a customer-provided Wasm module. + ~.extensibility.WasmPluginVersion: + A single immutable version of a ``WasmPlugin`` resource. + Defines the Wasm module used and optionally its runtime + config. """ - http_options = ( - _BaseNetworkServicesRestTransport._BaseGetWasmPlugin._get_http_options() - ) + http_options = _BaseNetworkServicesRestTransport._BaseGetWasmPluginVersion._get_http_options() - request, metadata = self._interceptor.pre_get_wasm_plugin(request, metadata) - transcoded_request = _BaseNetworkServicesRestTransport._BaseGetWasmPlugin._get_transcoded_request( + request, metadata = self._interceptor.pre_get_wasm_plugin_version( + request, metadata + ) + transcoded_request = _BaseNetworkServicesRestTransport._BaseGetWasmPluginVersion._get_transcoded_request( http_options, request ) # Jsonify the query params - query_params = _BaseNetworkServicesRestTransport._BaseGetWasmPlugin._get_query_params_json( + query_params = _BaseNetworkServicesRestTransport._BaseGetWasmPluginVersion._get_query_params_json( transcoded_request ) @@ -8770,17 +9651,17 @@ def __call__( "headers": dict(metadata), } _LOGGER.debug( - f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.GetWasmPlugin", + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.GetWasmPluginVersion", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "GetWasmPlugin", + "rpcName": "GetWasmPluginVersion", "httpRequest": http_request, "metadata": http_request["headers"], }, ) # Send the request - response = NetworkServicesRestTransport._GetWasmPlugin._get_response( + response = NetworkServicesRestTransport._GetWasmPluginVersion._get_response( self._host, metadata, query_params, @@ -8795,21 +9676,21 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = extensibility.WasmPlugin() - pb_resp = extensibility.WasmPlugin.pb(resp) + resp = extensibility.WasmPluginVersion() + pb_resp = extensibility.WasmPluginVersion.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_wasm_plugin(resp) + resp = self._interceptor.post_get_wasm_plugin_version(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_get_wasm_plugin_with_metadata( + resp, _ = self._interceptor.post_get_wasm_plugin_version_with_metadata( resp, response_metadata ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( logging.DEBUG ): # pragma: NO COVER try: - response_payload = extensibility.WasmPlugin.to_json(response) + response_payload = extensibility.WasmPluginVersion.to_json(response) except: response_payload = None http_response = { @@ -8818,22 +9699,22 @@ def __call__( "status": response.status_code, } _LOGGER.debug( - "Received response for google.cloud.networkservices_v1.NetworkServicesClient.get_wasm_plugin", + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.get_wasm_plugin_version", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "GetWasmPlugin", + "rpcName": "GetWasmPluginVersion", "metadata": http_response["headers"], "httpResponse": http_response, }, ) return resp - class _GetWasmPluginVersion( - _BaseNetworkServicesRestTransport._BaseGetWasmPluginVersion, + class _ListAgentGateways( + _BaseNetworkServicesRestTransport._BaseListAgentGateways, NetworkServicesRestStub, ): def __hash__(self): - return hash("NetworkServicesRestTransport.GetWasmPluginVersion") + return hash("NetworkServicesRestTransport.ListAgentGateways") @staticmethod def _get_response( @@ -8859,17 +9740,18 @@ def _get_response( def __call__( self, - request: extensibility.GetWasmPluginVersionRequest, + request: agent_gateway.ListAgentGatewaysRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> extensibility.WasmPluginVersion: - r"""Call the get wasm plugin version method over HTTP. + ) -> agent_gateway.ListAgentGatewaysResponse: + r"""Call the list agent gateways method over HTTP. Args: - request (~.extensibility.GetWasmPluginVersionRequest): - The request object. Request used by the ``GetWasmPluginVersion`` method. + request (~.agent_gateway.ListAgentGatewaysRequest): + The request object. Request used with the + ListAgentGateways method. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -8879,24 +9761,23 @@ def __call__( be of type `bytes`. Returns: - ~.extensibility.WasmPluginVersion: - A single immutable version of a ``WasmPlugin`` resource. - Defines the Wasm module used and optionally its runtime - config. + ~.agent_gateway.ListAgentGatewaysResponse: + Response returned by the + ListAgentGateways method. """ - http_options = _BaseNetworkServicesRestTransport._BaseGetWasmPluginVersion._get_http_options() + http_options = _BaseNetworkServicesRestTransport._BaseListAgentGateways._get_http_options() - request, metadata = self._interceptor.pre_get_wasm_plugin_version( + request, metadata = self._interceptor.pre_list_agent_gateways( request, metadata ) - transcoded_request = _BaseNetworkServicesRestTransport._BaseGetWasmPluginVersion._get_transcoded_request( + transcoded_request = _BaseNetworkServicesRestTransport._BaseListAgentGateways._get_transcoded_request( http_options, request ) # Jsonify the query params - query_params = _BaseNetworkServicesRestTransport._BaseGetWasmPluginVersion._get_query_params_json( + query_params = _BaseNetworkServicesRestTransport._BaseListAgentGateways._get_query_params_json( transcoded_request ) @@ -8918,17 +9799,17 @@ def __call__( "headers": dict(metadata), } _LOGGER.debug( - f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.GetWasmPluginVersion", + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.ListAgentGateways", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "GetWasmPluginVersion", + "rpcName": "ListAgentGateways", "httpRequest": http_request, "metadata": http_request["headers"], }, ) # Send the request - response = NetworkServicesRestTransport._GetWasmPluginVersion._get_response( + response = NetworkServicesRestTransport._ListAgentGateways._get_response( self._host, metadata, query_params, @@ -8943,21 +9824,23 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = extensibility.WasmPluginVersion() - pb_resp = extensibility.WasmPluginVersion.pb(resp) + resp = agent_gateway.ListAgentGatewaysResponse() + pb_resp = agent_gateway.ListAgentGatewaysResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_wasm_plugin_version(resp) + resp = self._interceptor.post_list_agent_gateways(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_get_wasm_plugin_version_with_metadata( + resp, _ = self._interceptor.post_list_agent_gateways_with_metadata( resp, response_metadata ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( logging.DEBUG ): # pragma: NO COVER try: - response_payload = extensibility.WasmPluginVersion.to_json(response) + response_payload = agent_gateway.ListAgentGatewaysResponse.to_json( + response + ) except: response_payload = None http_response = { @@ -8966,10 +9849,10 @@ def __call__( "status": response.status_code, } _LOGGER.debug( - "Received response for google.cloud.networkservices_v1.NetworkServicesClient.get_wasm_plugin_version", + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.list_agent_gateways", extra={ "serviceName": "google.cloud.networkservices.v1.NetworkServices", - "rpcName": "GetWasmPluginVersion", + "rpcName": "ListAgentGateways", "metadata": http_response["headers"], "httpResponse": http_response, }, @@ -10915,6 +11798,159 @@ def __call__( ) return resp + class _UpdateAgentGateway( + _BaseNetworkServicesRestTransport._BaseUpdateAgentGateway, + NetworkServicesRestStub, + ): + def __hash__(self): + return hash("NetworkServicesRestTransport.UpdateAgentGateway") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: gcn_agent_gateway.UpdateAgentGatewayRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the update agent gateway method over HTTP. + + Args: + request (~.gcn_agent_gateway.UpdateAgentGatewayRequest): + The request object. Request used by the + UpdateAgentGateway method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = _BaseNetworkServicesRestTransport._BaseUpdateAgentGateway._get_http_options() + + request, metadata = self._interceptor.pre_update_agent_gateway( + request, metadata + ) + transcoded_request = _BaseNetworkServicesRestTransport._BaseUpdateAgentGateway._get_transcoded_request( + http_options, request + ) + + body = _BaseNetworkServicesRestTransport._BaseUpdateAgentGateway._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BaseNetworkServicesRestTransport._BaseUpdateAgentGateway._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.networkservices_v1.NetworkServicesClient.UpdateAgentGateway", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "UpdateAgentGateway", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = NetworkServicesRestTransport._UpdateAgentGateway._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_update_agent_gateway(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_update_agent_gateway_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.networkservices_v1.NetworkServicesClient.update_agent_gateway", + extra={ + "serviceName": "google.cloud.networkservices.v1.NetworkServices", + "rpcName": "UpdateAgentGateway", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + class _UpdateEndpointPolicy( _BaseNetworkServicesRestTransport._BaseUpdateEndpointPolicy, NetworkServicesRestStub, @@ -12439,6 +13475,16 @@ def __call__( ) return resp + @property + def create_agent_gateway( + self, + ) -> Callable[ + [gcn_agent_gateway.CreateAgentGatewayRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateAgentGateway(self._session, self._host, self._interceptor) # type: ignore + @property def create_endpoint_policy( self, @@ -12537,6 +13583,14 @@ def create_wasm_plugin_version( self._session, self._host, self._interceptor ) # type: ignore + @property + def delete_agent_gateway( + self, + ) -> Callable[[agent_gateway.DeleteAgentGatewayRequest], operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteAgentGateway(self._session, self._host, self._interceptor) # type: ignore + @property def delete_endpoint_policy( self, @@ -12635,6 +13689,14 @@ def delete_wasm_plugin_version( self._session, self._host, self._interceptor ) # type: ignore + @property + def get_agent_gateway( + self, + ) -> Callable[[agent_gateway.GetAgentGatewayRequest], agent_gateway.AgentGateway]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetAgentGateway(self._session, self._host, self._interceptor) # type: ignore + @property def get_endpoint_policy( self, @@ -12743,6 +13805,17 @@ def get_wasm_plugin_version( # In C++ this would require a dynamic_cast return self._GetWasmPluginVersion(self._session, self._host, self._interceptor) # type: ignore + @property + def list_agent_gateways( + self, + ) -> Callable[ + [agent_gateway.ListAgentGatewaysRequest], + agent_gateway.ListAgentGatewaysResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListAgentGateways(self._session, self._host, self._interceptor) # type: ignore + @property def list_endpoint_policies( self, @@ -12872,6 +13945,16 @@ def list_wasm_plugin_versions( self._session, self._host, self._interceptor ) # type: ignore + @property + def update_agent_gateway( + self, + ) -> Callable[ + [gcn_agent_gateway.UpdateAgentGatewayRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateAgentGateway(self._session, self._host, self._interceptor) # type: ignore + @property def update_endpoint_policy( self, diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/rest_base.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/rest_base.py index f2b00448edec..d8904ad397bd 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/rest_base.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/services/network_services/transports/rest_base.py @@ -27,6 +27,7 @@ from google.protobuf import json_format from google.cloud.network_services_v1.types import ( + agent_gateway, endpoint_policy, extensibility, gateway, @@ -39,6 +40,7 @@ tcp_route, tls_route, ) +from google.cloud.network_services_v1.types import agent_gateway as gcn_agent_gateway from google.cloud.network_services_v1.types import ( endpoint_policy as gcn_endpoint_policy, ) @@ -120,6 +122,65 @@ def __init__( api_audience=api_audience, ) + class _BaseCreateAgentGateway: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "agentGatewayId": "", + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{parent=projects/*/locations/*}/agentGateways", + "body": "agent_gateway", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = gcn_agent_gateway.CreateAgentGatewayRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseNetworkServicesRestTransport._BaseCreateAgentGateway._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + class _BaseCreateEndpointPolicy: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") @@ -769,6 +830,53 @@ def _get_query_params_json(transcoded_request): query_params["$alt"] = "json;enum-encoding=int" return query_params + class _BaseDeleteAgentGateway: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "delete", + "uri": "/v1/{name=projects/*/locations/*/agentGateways/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = agent_gateway.DeleteAgentGatewayRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseNetworkServicesRestTransport._BaseDeleteAgentGateway._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + class _BaseDeleteEndpointPolicy: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") @@ -1286,6 +1394,53 @@ def _get_query_params_json(transcoded_request): query_params["$alt"] = "json;enum-encoding=int" return query_params + class _BaseGetAgentGateway: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/agentGateways/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = agent_gateway.GetAgentGatewayRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseNetworkServicesRestTransport._BaseGetAgentGateway._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + class _BaseGetEndpointPolicy: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") @@ -1897,6 +2052,53 @@ def _get_query_params_json(transcoded_request): query_params["$alt"] = "json;enum-encoding=int" return query_params + class _BaseListAgentGateways: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*}/agentGateways", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = agent_gateway.ListAgentGatewaysRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseNetworkServicesRestTransport._BaseListAgentGateways._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + class _BaseListEndpointPolicies: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") @@ -2508,6 +2710,63 @@ def _get_query_params_json(transcoded_request): query_params["$alt"] = "json;enum-encoding=int" return query_params + class _BaseUpdateAgentGateway: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/v1/{agent_gateway.name=projects/*/locations/*/agentGateways/*}", + "body": "agent_gateway", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = gcn_agent_gateway.UpdateAgentGatewayRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseNetworkServicesRestTransport._BaseUpdateAgentGateway._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + class _BaseUpdateEndpointPolicy: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/__init__.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/__init__.py index 5a1aceb06136..f05745737966 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/__init__.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/__init__.py @@ -13,6 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from .agent_gateway import ( + AgentGateway, + CreateAgentGatewayRequest, + DeleteAgentGatewayRequest, + GetAgentGatewayRequest, + ListAgentGatewaysRequest, + ListAgentGatewaysResponse, + UpdateAgentGatewayRequest, +) from .common import ( EndpointMatcher, EnvoyHeaders, @@ -21,6 +30,7 @@ ) from .dep import ( AuthzExtension, + BodySendMode, CreateAuthzExtensionRequest, CreateLbEdgeExtensionRequest, CreateLbRouteExtensionRequest, @@ -162,6 +172,13 @@ ) __all__ = ( + "AgentGateway", + "CreateAgentGatewayRequest", + "DeleteAgentGatewayRequest", + "GetAgentGatewayRequest", + "ListAgentGatewaysRequest", + "ListAgentGatewaysResponse", + "UpdateAgentGatewayRequest", "EndpointMatcher", "OperationMetadata", "TrafficPortSelector", @@ -195,6 +212,7 @@ "UpdateLbEdgeExtensionRequest", "UpdateLbRouteExtensionRequest", "UpdateLbTrafficExtensionRequest", + "BodySendMode", "EventType", "LoadBalancingScheme", "WireFormat", diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/agent_gateway.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/agent_gateway.py new file mode 100644 index 000000000000..0bbb0e9f9893 --- /dev/null +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/agent_gateway.py @@ -0,0 +1,515 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore +import proto # type: ignore + +__protobuf__ = proto.module( + package="google.cloud.networkservices.v1", + manifest={ + "AgentGateway", + "ListAgentGatewaysRequest", + "ListAgentGatewaysResponse", + "GetAgentGatewayRequest", + "CreateAgentGatewayRequest", + "UpdateAgentGatewayRequest", + "DeleteAgentGatewayRequest", + }, +) + + +class AgentGateway(proto.Message): + r"""AgentGateway represents the agent gateway resource. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + google_managed (google.cloud.network_services_v1.types.AgentGateway.GoogleManaged): + Optional. Proxy is orchestrated and managed + by GoogleCloud in a tenant project. + + This field is a member of `oneof`_ ``deployment_mode``. + self_managed (google.cloud.network_services_v1.types.AgentGateway.SelfManaged): + Optional. Attach to existing Application Load + Balancers or Secure Web Proxies. + + This field is a member of `oneof`_ ``deployment_mode``. + name (str): + Identifier. Name of the AgentGateway resource. It matches + pattern + ``projects/*/locations/*/agentGateways/``. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The timestamp when the resource + was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The timestamp when the resource + was updated. + labels (MutableMapping[str, str]): + Optional. Set of label tags associated with + the AgentGateway resource. + description (str): + Optional. A free-text description of the + resource. Max length 1024 characters. + etag (str): + Optional. Etag of the resource. + If this is provided, it must match the server's + etag. If the provided etag does not match the + server's etag, the request will fail with a 409 + ABORTED error. + protocols (MutableSequence[google.cloud.network_services_v1.types.AgentGateway.Protocol]): + Optional. Deprecated. + registries (MutableSequence[str]): + Optional. A list of Agent registries containing the agents, + MCP servers and tools governed by the Agent Gateway. Note: + Currently limited to project-scoped registries Must be of + format + \`//agentregistry.googleapis.com/projects/{project}/locations/{location}/ + network_config (google.cloud.network_services_v1.types.AgentGateway.NetworkConfig): + Optional. Network configuration for the + AgentGateway. + agent_gateway_card (google.cloud.network_services_v1.types.AgentGateway.AgentGatewayOutputCard): + Output only. Field for populated AgentGateway + card. + """ + + class Protocol(proto.Enum): + r"""Enums of all supported protocols + + Values: + PROTOCOL_UNSPECIFIED (0): + Unspecified protocol. + MCP (1): + Message Control Plane protocol. + """ + + PROTOCOL_UNSPECIFIED = 0 + MCP = 1 + + class GoogleManaged(proto.Message): + r"""Configuration for Google Managed deployment mode. + Proxy is orchestrated and managed by GoogleCloud in a tenant + project. + + Attributes: + governed_access_path (google.cloud.network_services_v1.types.AgentGateway.GoogleManaged.GovernedAccessPath): + Optional. Operating Mode of Agent Gateway. + """ + + class GovernedAccessPath(proto.Enum): + r"""GovernedAccessPath defines the type of access to protect. + + Values: + GOVERNED_ACCESS_PATH_UNSPECIFIED (0): + Governed access path is not specified. + AGENT_TO_ANYWHERE (1): + Govern agent conections to destinations. + CLIENT_TO_AGENT (2): + Protect connection to Agent or Tool. + """ + + GOVERNED_ACCESS_PATH_UNSPECIFIED = 0 + AGENT_TO_ANYWHERE = 1 + CLIENT_TO_AGENT = 2 + + governed_access_path: "AgentGateway.GoogleManaged.GovernedAccessPath" = ( + proto.Field( + proto.ENUM, + number=1, + enum="AgentGateway.GoogleManaged.GovernedAccessPath", + ) + ) + + class SelfManaged(proto.Message): + r"""Configuration for Self Managed deployment mode. + Attach to existing Application Load Balancers or Secure Web + Proxies. + + Attributes: + resource_uri (str): + Optional. A supported Google Cloud networking + proxy in the Project and Location + """ + + resource_uri: str = proto.Field( + proto.STRING, + number=1, + ) + + class NetworkConfig(proto.Message): + r"""NetworkConfig contains network configurations for the + AgentGateway. + + Attributes: + egress (google.cloud.network_services_v1.types.AgentGateway.NetworkConfig.Egress): + Optional. Optional PSC-Interface network + attachment for connectivity to your private VPCs + network. + dns_peering_config (google.cloud.network_services_v1.types.AgentGateway.NetworkConfig.DnsPeeringConfig): + Optional. Optional DNS peering configuration + for connectivity to your private VPC network. + """ + + class Egress(proto.Message): + r"""Configuration for Egress + + Attributes: + network_attachment (str): + Optional. The URI of the Network Attachment + resource. + trust_config (google.cloud.network_services_v1.types.AgentGateway.NetworkConfig.Egress.TrustConfig): + Optional. TrustConfig defines the trust + configuration for egress. + """ + + class TrustConfig(proto.Message): + r"""TrustConfig defines the trust configuration for egress. + + Attributes: + pem_certificates (MutableSequence[str]): + Required. PEM encoded root certificates used + to validate the identity of the upstream + servers/destinations during egress connections. + """ + + pem_certificates: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=1, + ) + + network_attachment: str = proto.Field( + proto.STRING, + number=1, + ) + trust_config: "AgentGateway.NetworkConfig.Egress.TrustConfig" = proto.Field( + proto.MESSAGE, + number=2, + message="AgentGateway.NetworkConfig.Egress.TrustConfig", + ) + + class DnsPeeringConfig(proto.Message): + r"""DNS peering config for the user VPC network. + + Attributes: + domains (MutableSequence[str]): + Required. Domain names for which DNS queries + should be forwarded to the target network. + target_project (str): + Required. Target project ID to which DNS + queries should be forwarded to. This can be the + same project that contains the AgentGateway or a + different project. + target_network (str): + Required. Target network in 'target project' to which DNS + queries should be forwarded to. Must be in format of + ``projects/{project}/global/networks/{network}``. + """ + + domains: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=1, + ) + target_project: str = proto.Field( + proto.STRING, + number=2, + ) + target_network: str = proto.Field( + proto.STRING, + number=3, + ) + + egress: "AgentGateway.NetworkConfig.Egress" = proto.Field( + proto.MESSAGE, + number=1, + message="AgentGateway.NetworkConfig.Egress", + ) + dns_peering_config: "AgentGateway.NetworkConfig.DnsPeeringConfig" = proto.Field( + proto.MESSAGE, + number=2, + message="AgentGateway.NetworkConfig.DnsPeeringConfig", + ) + + class AgentGatewayOutputCard(proto.Message): + r"""AgentGatewayOutputCard contains informational output-only + fields + + Attributes: + mtls_endpoint (str): + Output only. mTLS Endpoint associated with + this AgentGateway + root_certificates (MutableSequence[str]): + Output only. Root Certificates for Agents to + validate this AgentGateway + service_extensions_service_account (str): + Output only. Service Account used by Service + Extensions to operate. + """ + + mtls_endpoint: str = proto.Field( + proto.STRING, + number=1, + ) + root_certificates: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=5, + ) + service_extensions_service_account: str = proto.Field( + proto.STRING, + number=4, + ) + + google_managed: GoogleManaged = proto.Field( + proto.MESSAGE, + number=8, + oneof="deployment_mode", + message=GoogleManaged, + ) + self_managed: SelfManaged = proto.Field( + proto.MESSAGE, + number=9, + oneof="deployment_mode", + message=SelfManaged, + ) + name: str = proto.Field( + proto.STRING, + number=1, + ) + create_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + update_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + labels: MutableMapping[str, str] = proto.MapField( + proto.STRING, + proto.STRING, + number=4, + ) + description: str = proto.Field( + proto.STRING, + number=5, + ) + etag: str = proto.Field( + proto.STRING, + number=6, + ) + protocols: MutableSequence[Protocol] = proto.RepeatedField( + proto.ENUM, + number=12, + enum=Protocol, + ) + registries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=13, + ) + network_config: NetworkConfig = proto.Field( + proto.MESSAGE, + number=10, + message=NetworkConfig, + ) + agent_gateway_card: AgentGatewayOutputCard = proto.Field( + proto.MESSAGE, + number=11, + message=AgentGatewayOutputCard, + ) + + +class ListAgentGatewaysRequest(proto.Message): + r"""Request used with the ListAgentGateways method. + + Attributes: + parent (str): + Required. The project and location from which the + AgentGateways should be listed, specified in the format + ``projects/*/locations/*``. + page_size (int): + Optional. Maximum number of AgentGateways to + return per call. + page_token (str): + Optional. The value returned by the last + ``ListAgentGatewaysResponse`` Indicates that this is a + continuation of a prior ``ListAgentGateways`` call, and that + the system should return the next page of data. + return_partial_success (bool): + Optional. If true, allow partial responses + for multi-regional Aggregated List requests. + Otherwise if one of the locations is down or + unreachable, the Aggregated List request will + fail. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + return_partial_success: bool = proto.Field( + proto.BOOL, + number=4, + ) + + +class ListAgentGatewaysResponse(proto.Message): + r"""Response returned by the ListAgentGateways method. + + Attributes: + agent_gateways (MutableSequence[google.cloud.network_services_v1.types.AgentGateway]): + List of AgentGateway resources. + next_page_token (str): + If there might be more results than those appearing in this + response, then ``next_page_token`` is included. To get the + next set of results, call this method again using the value + of ``next_page_token`` as ``page_token``. + unreachable (MutableSequence[str]): + Unreachable resources. Populated when the + request attempts to list all resources across + all supported locations, while some locations + are temporarily unavailable. + """ + + @property + def raw_page(self): + return self + + agent_gateways: MutableSequence["AgentGateway"] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="AgentGateway", + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + unreachable: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=3, + ) + + +class GetAgentGatewayRequest(proto.Message): + r"""Request used by the GetAgentGateway method. + + Attributes: + name (str): + Required. A name of the AgentGateway to get. Must be in the + format ``projects/*/locations/*/agentGateways/*``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateAgentGatewayRequest(proto.Message): + r"""Request used by the CreateAgentGateway method. + + Attributes: + parent (str): + Required. The parent resource of the AgentGateway. Must be + in the format ``projects/*/locations/*``. + agent_gateway_id (str): + Required. Short name of the AgentGateway + resource to be created. + agent_gateway (google.cloud.network_services_v1.types.AgentGateway): + Required. AgentGateway resource to be + created. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + agent_gateway_id: str = proto.Field( + proto.STRING, + number=2, + ) + agent_gateway: "AgentGateway" = proto.Field( + proto.MESSAGE, + number=3, + message="AgentGateway", + ) + + +class UpdateAgentGatewayRequest(proto.Message): + r"""Request used by the UpdateAgentGateway method. + + Attributes: + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Field mask is used to specify the fields to be + overwritten in the AgentGateway resource by the update. The + fields specified in the update_mask are relative to the + resource, not the full request. A field will be overwritten + if it is in the mask. If the user does not provide a mask + then all fields will be overwritten. + agent_gateway (google.cloud.network_services_v1.types.AgentGateway): + Required. Updated AgentGateway resource. + """ + + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, + ) + agent_gateway: "AgentGateway" = proto.Field( + proto.MESSAGE, + number=2, + message="AgentGateway", + ) + + +class DeleteAgentGatewayRequest(proto.Message): + r"""Request used by the DeleteAgentGateway method. + + Attributes: + name (str): + Required. A name of the AgentGateway to delete. Must be in + the format ``projects/*/locations/*/agentGateways/*``. + etag (str): + Optional. The etag of the AgentGateway to + delete. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + etag: str = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/common.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/common.py index e1afd94a954f..cf13886a1e53 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/common.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/common.py @@ -42,9 +42,9 @@ class EnvoyHeaders(proto.Enum): DEBUG_HEADERS (2): Envoy will insert default internal debug headers into upstream requests: - x-envoy-attempt-count x-envoy-is-timeout-retry - x-envoy-expected-rq-timeout-ms - x-envoy-original-path + x-envoy-attempt-count, x-envoy-is-timeout-retry, + x-envoy-expected-rq-timeout-ms, + x-envoy-original-path, x-envoy-upstream-stream-duration-ms """ diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/dep.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/dep.py index ec484aa5bedc..2b04be1e8202 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/dep.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/dep.py @@ -29,6 +29,7 @@ "EventType", "LoadBalancingScheme", "WireFormat", + "BodySendMode", "ExtensionChain", "LbTrafficExtension", "ListLbTrafficExtensionsRequest", @@ -132,10 +133,51 @@ class WireFormat(proto.Enum): specified. The backend service for the extension must use HTTP2 or H2C as the protocol. All ``supported_events`` for a client request are sent as part of the same gRPC stream. + EXT_AUTHZ_GRPC (3): + The extension service uses Envoy's ``ext_authz`` gRPC API. + The backend service for the extension must use HTTP2 or H2C + as the protocol. ``EXT_AUTHZ_GRPC`` is only supported for + regional ``AuthzExtension`` resources. """ WIRE_FORMAT_UNSPECIFIED = 0 EXT_PROC_GRPC = 1 + EXT_AUTHZ_GRPC = 3 + + +class BodySendMode(proto.Enum): + r"""The send mode for body processing. + + Values: + BODY_SEND_MODE_UNSPECIFIED (0): + Default value. Do not use. + BODY_SEND_MODE_STREAMED (1): + Calls to the extension are executed in the + streamed mode. Subsequent chunks will be sent + only after the previous chunks have been + processed. + + The content of the body chunks is sent one way + to the extension. Extension may send modified + chunks back. + + This is the default value if the processing mode + is not specified. + BODY_SEND_MODE_FULL_DUPLEX_STREAMED (2): + Calls are executed in the full duplex mode. Subsequent + chunks will be sent for processing without waiting for the + response for the previous chunk or for the response for + ``REQUEST_HEADERS`` event. + + Extension can freely modify or chunk the body contents. If + the extension doesn't send the body contents back, the next + extension in the chain or the upstream will receive an empty + body. + """ + + BODY_SEND_MODE_UNSPECIFIED = 0 + BODY_SEND_MODE_STREAMED = 1 + BODY_SEND_MODE_FULL_DUPLEX_STREAMED = 2 class ExtensionChain(proto.Message): @@ -188,7 +230,7 @@ class Extension(proto.Message): Attributes: name (str): - Required. The name for this extension. + Optional. The name for this extension. The name is logged as part of the HTTP request logs. The name must conform with RFC-1034, is restricted to lower-cased letters, numbers and @@ -196,6 +238,9 @@ class Extension(proto.Message): characters. Additionally, the first character must be a letter and the last a letter or a number. + + This field is required except for + AuthzExtension. authority (str): Optional. The ``:authority`` header in the gRPC request sent from Envoy to the extension service. Required for Callout @@ -239,6 +284,11 @@ class Extension(proto.Message): For the ``LbEdgeExtension`` resource, this field is required and must only contain ``REQUEST_HEADERS`` event. + + For the ``AuthzExtension`` resource, this field is optional. + ``REQUEST_HEADERS`` is the only supported event. If + unspecified, ``REQUEST_HEADERS`` event is assumed as + supported. timeout (google.protobuf.duration_pb2.Duration): Optional. Specifies the timeout for each individual message on the stream. The timeout must be between ``10``-``10000`` @@ -268,13 +318,27 @@ class Extension(proto.Message): to the extension (from the client or backend). If omitted, all headers are sent. Each element is a string indicating the header name. + forward_attributes (MutableSequence[str]): + Optional. List of the Envoy attributes to forward to the + extension server. The attributes provided here are included + as part of the ``ProcessingRequest.attributes`` field (of + type ``map``), where the + keys are the attribute names. Refer to the + `documentation `__ + for the names of attributes that can be forwarded. If + omitted, no attributes are sent. Each element is a string + indicating the attribute name. metadata (google.protobuf.struct_pb2.Struct): Optional. The metadata provided here is included as part of the ``metadata_context`` (of type ``google.protobuf.Struct``) in the ``ProcessingRequest`` message sent to the extension server. - The metadata is available under the namespace + For ``AuthzExtension`` resources, the metadata is available + under the namespace + ``com.google.authz_extension.``. For other + types of extensions, the metadata is available under the + namespace ``com.google....``. For example: ``com.google.lb_traffic_extension.lbtrafficextension1.chain1.ext1``. @@ -301,6 +365,49 @@ class Extension(proto.Message): - The length of each value must be less than 1024 characters. - All values must be strings. + request_body_send_mode (google.cloud.network_services_v1.types.BodySendMode): + Optional. Configures the send mode for request body + processing. + + The field can only be set if ``supported_events`` includes + ``REQUEST_BODY``. If ``supported_events`` includes + ``REQUEST_BODY``, but ``request_body_send_mode`` is unset, + the default value ``STREAMED`` is used. + + When this field is set to ``FULL_DUPLEX_STREAMED``, + ``supported_events`` must include both ``REQUEST_BODY`` and + ``REQUEST_TRAILERS``. + + This field can be set only for ``LbTrafficExtension`` and + ``LbRouteExtension`` resources, and only when the + ``service`` field of the extension points to a + ``BackendService``. Only ``FULL_DUPLEX_STREAMED`` mode is + supported for ``LbRouteExtension`` resources. + response_body_send_mode (google.cloud.network_services_v1.types.BodySendMode): + Optional. Configures the send mode for response processing. + If unspecified, the default value ``STREAMED`` is used. + + The field can only be set if ``supported_events`` includes + ``RESPONSE_BODY``. If ``supported_events`` includes + ``RESPONSE_BODY``, but ``response_body_send_mode`` is unset, + the default value ``STREAMED`` is used. + + When this field is set to ``FULL_DUPLEX_STREAMED``, + ``supported_events`` must include both ``RESPONSE_BODY`` and + ``RESPONSE_TRAILERS``. + + This field can be set only for ``LbTrafficExtension`` + resources, and only when the ``service`` field of the + extension points to a ``BackendService``. + observability_mode (bool): + Optional. When set to ``true``, the calls to the extension + backend are performed asynchronously, without pausing the + processing of the ongoing request. In this mode, only + ``STREAMED`` (default) body processing is supported. + Responses, if any, are ignored. + + Supported by regional ``LbTrafficExtension`` and + ``LbRouteExtension`` resources. """ name: str = proto.Field( @@ -333,11 +440,29 @@ class Extension(proto.Message): proto.STRING, number=7, ) + forward_attributes: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=8, + ) metadata: struct_pb2.Struct = proto.Field( proto.MESSAGE, number=9, message=struct_pb2.Struct, ) + request_body_send_mode: "BodySendMode" = proto.Field( + proto.ENUM, + number=14, + enum="BodySendMode", + ) + response_body_send_mode: "BodySendMode" = proto.Field( + proto.ENUM, + number=15, + enum="BodySendMode", + ) + observability_mode: bool = proto.Field( + proto.BOOL, + number=16, + ) name: str = proto.Field( proto.STRING, @@ -1401,15 +1526,18 @@ class AuthzExtension(proto.Message): labels `__ for Google Cloud resources. load_balancing_scheme (google.cloud.network_services_v1.types.LoadBalancingScheme): - Required. All backend services and forwarding rules + Optional. All backend services and forwarding rules referenced by this extension must share the same load balancing scheme. Supported values: ``INTERNAL_MANAGED``, - ``EXTERNAL_MANAGED``. For more information, refer to - `Backend services + ``EXTERNAL_MANAGED``. Can be omitted for AuthzExtensions + that do not reference a backend service. For more + information, refer to `Backend services overview `__. authority (str): - Required. The ``:authority`` header in the gRPC request sent - from Envoy to the extension service. + Optional. The ``:authority`` header in the gRPC request sent + from Envoy to the extension service. It is required when the + ``service`` field points to a backend service or a wasm + plugin. service (str): Required. The reference to the service that runs the extension. @@ -1458,10 +1586,22 @@ class AuthzExtension(proto.Message): to the extension (from the client). If omitted, all headers are sent. Each element is a string indicating the header name. + forward_attributes (MutableSequence[str]): + Optional. List of the Envoy attributes to forward to the + extension server. The attributes provided here are included + as part of the ``ProcessingRequest.attributes`` field (of + type ``map``), where the + keys are the attribute names. Refer to the + `documentation `__ + for the names of attributes that can be forwarded. If + omitted, no attributes are sent. Each element is a string + indicating the attribute name. wire_format (google.cloud.network_services_v1.types.WireFormat): Optional. The format of communication supported by the - callout extension. If not specified, the default value - ``EXT_PROC_GRPC`` is used. + callout extension. This field is supported only for regional + ``AuthzExtension`` resources. If not specified, the default + value ``EXT_PROC_GRPC`` is used. Global ``AuthzExtension`` + resources use the ``EXT_PROC_GRPC`` wire format. """ name: str = proto.Field( @@ -1518,6 +1658,10 @@ class AuthzExtension(proto.Message): proto.STRING, number=12, ) + forward_attributes: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=13, + ) wire_format: "WireFormat" = proto.Field( proto.ENUM, number=14, diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/endpoint_policy.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/endpoint_policy.py index 23283388dbf7..9038e860f3c5 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/endpoint_policy.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/endpoint_policy.py @@ -47,7 +47,7 @@ class EndpointPolicy(proto.Message): name (str): Identifier. Name of the EndpointPolicy resource. It matches pattern - ``projects/{project}/locations/global/endpointPolicies/{endpoint_policy}``. + ``projects/{project}/locations/*/endpointPolicies/{endpoint_policy}``. create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The timestamp when the resource was created. @@ -173,7 +173,7 @@ class ListEndpointPoliciesRequest(proto.Message): parent (str): Required. The project and location from which the EndpointPolicies should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. page_size (int): Maximum number of EndpointPolicies to return per call. @@ -251,8 +251,7 @@ class GetEndpointPolicyRequest(proto.Message): Attributes: name (str): Required. A name of the EndpointPolicy to get. Must be in - the format - ``projects/*/locations/global/endpointPolicies/*``. + the format ``projects/*/locations/*/endpointPolicies/*``. """ name: str = proto.Field( @@ -267,7 +266,7 @@ class CreateEndpointPolicyRequest(proto.Message): Attributes: parent (str): Required. The parent resource of the EndpointPolicy. Must be - in the format ``projects/*/locations/global``. + in the format ``projects/*/locations/*``. endpoint_policy_id (str): Required. Short name of the EndpointPolicy resource to be created. E.g. "CustomECS". @@ -324,8 +323,7 @@ class DeleteEndpointPolicyRequest(proto.Message): Attributes: name (str): Required. A name of the EndpointPolicy to delete. Must be in - the format - ``projects/*/locations/global/endpointPolicies/*``. + the format ``projects/*/locations/*/endpointPolicies/*``. """ name: str = proto.Field( diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/extensibility.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/extensibility.py index 9652bf63ef2f..607d5ada166c 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/extensibility.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/extensibility.py @@ -148,11 +148,27 @@ class VersionDetails(proto.Message): plugin_config_uri (str): URI of the plugin configuration stored in the Artifact Registry. The configuration is provided to the plugin at - runtime through the ``ON_CONFIGURE`` callback. The container - image must contain only a single file with the name - ``plugin.config``. When a new ``WasmPluginVersion`` resource - is created, the digest of the container image is saved in - the ``plugin_config_digest`` field. + runtime through the ``ON_CONFIGURE`` callback. + + The URI can refer to one of the following repository + formats: + + - Container images: the ``plugin_config_uri`` must point to + a container that contains a single file with the name + ``plugin.config``. When a new ``WasmPluginVersion`` + resource is created, the digest of the image is saved in + the ``plugin_config_digest`` field. When pulling a + container image from Artifact Registry, the digest value + is used instead of an image tag. + + - Generic artifacts: the ``plugin_config_uri`` must be in + this format: + ``projects/{project}/locations/{location}/repositories/{repository}/ genericArtifacts/{package}:{version}``. + The specified package and version must contain a file with + the name ``plugin.config``. When a new + ``WasmPluginVersion`` resource is created, the checksum of + the contents of the file is saved in the + ``plugin_config_digest`` field. This field is a member of `oneof`_ ``plugin_config_source``. create_time (google.protobuf.timestamp_pb2.Timestamp): @@ -168,24 +184,40 @@ class VersionDetails(proto.Message): Optional. Set of labels associated with the ``WasmPluginVersion`` resource. image_uri (str): - Optional. URI of the container image containing the Wasm - module, stored in the Artifact Registry. The container image - must contain only a single file with the name - ``plugin.wasm``. When a new ``WasmPluginVersion`` resource - is created, the URI gets resolved to an image digest and - saved in the ``image_digest`` field. + Optional. URI of the image containing the Wasm module, + stored in Artifact Registry. + + The URI can refer to one of the following repository + formats: + + - Container images: the ``image_uri`` must point to a + container that contains a single file with the name + ``plugin.wasm``. When a new ``WasmPluginVersion`` resource + is created, the digest of the image is saved in the + ``image_digest`` field. When pulling a container image + from Artifact Registry, the digest value is used instead + of an image tag. + + - Generic artifacts: the ``image_uri`` must be in this + format: + ``projects/{project}/locations/{location}/repositories/{repository}/ genericArtifacts/{package}:{version}``. + The specified package and version must contain a file with + the name ``plugin.wasm``. When a new ``WasmPluginVersion`` + resource is created, the checksum of the contents of the + file is saved in the ``image_digest`` field. image_digest (str): - Output only. The resolved digest for the image specified in - ``image``. The digest is resolved during the creation of a - ``WasmPluginVersion`` resource. This field holds the digest - value regardless of whether a tag or digest was originally - specified in the ``image`` field. + Output only. This field holds the digest (usually checksum) + value for the plugin image. The value is calculated based on + the ``image_uri`` field. If the ``image_uri`` field refers + to a container image, the digest value is obtained from the + container image. If the ``image_uri`` field refers to a + generic artifact, the digest value is calculated based on + the contents of the file. plugin_config_digest (str): Output only. This field holds the digest (usually checksum) value for the plugin configuration. The value is calculated - based on the contents of the ``plugin_config_data`` field or - the container image defined by the ``plugin_config_uri`` - field. + based on the contents of ``plugin_config_data`` field or the + image defined by the ``plugin_config_uri`` field. """ plugin_config_data: bytes = proto.Field( @@ -255,8 +287,8 @@ class LogConfig(proto.Message): This field can be specified only if logging is enabled for this plugin. min_log_level (google.cloud.network_services_v1.types.WasmPlugin.LogConfig.LogLevel): - Non-empty default. Specificies the lowest level of the - plugin logs that are exported to Cloud Logging. This setting + Non-empty default. Specifies the lowest level of the plugin + logs that are exported to Cloud Logging. This setting relates to the logs generated by using logging statements in your Wasm code. @@ -393,11 +425,27 @@ class WasmPluginVersion(proto.Message): plugin_config_uri (str): URI of the plugin configuration stored in the Artifact Registry. The configuration is provided to the plugin at - runtime through the ``ON_CONFIGURE`` callback. The container - image must contain only a single file with the name - ``plugin.config``. When a new ``WasmPluginVersion`` resource - is created, the digest of the container image is saved in - the ``plugin_config_digest`` field. + runtime through the ``ON_CONFIGURE`` callback. + + The URI can refer to one of the following repository + formats: + + - Container images: the ``plugin_config_uri`` must point to + a container that contains a single file with the name + ``plugin.config``. When a new ``WasmPluginVersion`` + resource is created, the digest of the image is saved in + the ``plugin_config_digest`` field. When pulling a + container image from Artifact Registry, the digest value + is used instead of an image tag. + + - Generic artifacts: the ``plugin_config_uri`` must be in + this format: + ``projects/{project}/locations/{location}/repositories/{repository}/ genericArtifacts/{package}:{version}``. + The specified package and version must contain a file with + the name ``plugin.config``. When a new + ``WasmPluginVersion`` resource is created, the checksum of + the contents of the file is saved in the + ``plugin_config_digest`` field. This field is a member of `oneof`_ ``plugin_config_source``. name (str): @@ -417,23 +465,40 @@ class WasmPluginVersion(proto.Message): Optional. Set of labels associated with the ``WasmPluginVersion`` resource. image_uri (str): - Optional. URI of the container image containing the plugin, - stored in the Artifact Registry. When a new - ``WasmPluginVersion`` resource is created, the digest of the - container image is saved in the ``image_digest`` field. When - downloading an image, the digest value is used instead of an - image tag. + Optional. URI of the image containing the Wasm module, + stored in Artifact Registry. + + The URI can refer to one of the following repository + formats: + + - Container images: the ``image_uri`` must point to a + container that contains a single file with the name + ``plugin.wasm``. When a new ``WasmPluginVersion`` resource + is created, the digest of the image is saved in the + ``image_digest`` field. When pulling a container image + from Artifact Registry, the digest value is used instead + of an image tag. + + - Generic artifacts: the ``image_uri`` must be in this + format: + ``projects/{project}/locations/{location}/repositories/{repository}/ genericArtifacts/{package}:{version}``. + The specified package and version must contain a file with + the name ``plugin.wasm``. When a new ``WasmPluginVersion`` + resource is created, the checksum of the contents of the + file is saved in the ``image_digest`` field. image_digest (str): - Output only. The resolved digest for the image specified in - the ``image`` field. The digest is resolved during the - creation of ``WasmPluginVersion`` resource. This field holds - the digest value, regardless of whether a tag or digest was - originally specified in the ``image`` field. + Output only. This field holds the digest (usually checksum) + value for the plugin image. The value is calculated based on + the ``image_uri`` field. If the ``image_uri`` field refers + to a container image, the digest value is obtained from the + container image. If the ``image_uri`` field refers to a + generic artifact, the digest value is calculated based on + the contents of the file. plugin_config_digest (str): Output only. This field holds the digest (usually checksum) value for the plugin configuration. The value is calculated - based on the contents of ``plugin_config_data`` or the - container image defined by the ``plugin_config_uri`` field. + based on the contents of ``plugin_config_data`` field or the + image defined by the ``plugin_config_uri`` field. """ plugin_config_data: bytes = proto.Field( diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/gateway.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/gateway.py index b879ce113b1c..2dfde174e7b5 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/gateway.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/gateway.py @@ -82,8 +82,12 @@ class Gateway(proto.Message): Required. One or more port numbers (1-65535), on which the Gateway will receive traffic. The proxy binds to the specified ports. Gateways of type 'SECURE_WEB_GATEWAY' are - limited to 1 port. Gateways of type 'OPEN_MESH' listen on + limited to 5 ports. Gateways of type 'OPEN_MESH' listen on 0.0.0.0 for IPv4 and :: for IPv6 and support multiple ports. + all_ports (bool): + Optional. If true, the Gateway will listen on all ports. + This is mutually exclusive with the ``ports`` field. This + field only applies to gateways of type 'SECURE_WEB_GATEWAY'. scope (str): Optional. Scope determines how configuration across multiple Gateway instances are merged. @@ -146,6 +150,11 @@ class Gateway(proto.Message): configurable only for gateways of type SECURE_WEB_GATEWAY. This field is required for gateways of type SECURE_WEB_GATEWAY. + allow_global_access (bool): + Optional. If true, the gateway will allow traffic from + clients outside of the region where the gateway is located. + This field is configurable only for gateways of type + SECURE_WEB_GATEWAY. """ class Type(proto.Enum): @@ -255,6 +264,10 @@ class RoutingMode(proto.Enum): proto.INT32, number=11, ) + all_ports: bool = proto.Field( + proto.BOOL, + number=34, + ) scope: str = proto.Field( proto.STRING, number=8, @@ -295,6 +308,10 @@ class RoutingMode(proto.Enum): number=32, enum=RoutingMode, ) + allow_global_access: bool = proto.Field( + proto.BOOL, + number=33, + ) class ListGatewaysRequest(proto.Message): diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/grpc_route.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/grpc_route.py index 54e025159223..58be9e7c3749 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/grpc_route.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/grpc_route.py @@ -44,7 +44,7 @@ class GrpcRoute(proto.Message): name (str): Identifier. Name of the GrpcRoute resource. It matches pattern - ``projects/*/locations/global/grpcRoutes/`` + ``projects/*/locations/*/grpcRoutes/`` self_link (str): Output only. Server-defined URL of this resource @@ -106,14 +106,14 @@ class GrpcRoute(proto.Message): requests served by the mesh. Each mesh reference should match the pattern: - ``projects/*/locations/global/meshes/`` + ``projects/*/locations/*/meshes/`` gateways (MutableSequence[str]): Optional. Gateways defines a list of gateways this GrpcRoute is attached to, as one of the routing rules to route the requests served by the gateway. Each gateway reference should match the pattern: - ``projects/*/locations/global/gateways/`` + ``projects/*/locations/*/gateways/`` rules (MutableSequence[google.cloud.network_services_v1.types.GrpcRoute.RouteRule]): Required. A list of detailed rules defining how to route traffic. @@ -633,7 +633,7 @@ class ListGrpcRoutesRequest(proto.Message): parent (str): Required. The project and location from which the GrpcRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. page_size (int): Maximum number of GrpcRoutes to return per call. @@ -711,7 +711,7 @@ class GetGrpcRouteRequest(proto.Message): Attributes: name (str): Required. A name of the GrpcRoute to get. Must be in the - format ``projects/*/locations/global/grpcRoutes/*``. + format ``projects/*/locations/*/grpcRoutes/*``. """ name: str = proto.Field( @@ -726,7 +726,7 @@ class CreateGrpcRouteRequest(proto.Message): Attributes: parent (str): Required. The parent resource of the GrpcRoute. Must be in - the format ``projects/*/locations/global``. + the format ``projects/*/locations/*``. grpc_route_id (str): Required. Short name of the GrpcRoute resource to be created. @@ -782,7 +782,7 @@ class DeleteGrpcRouteRequest(proto.Message): Attributes: name (str): Required. A name of the GrpcRoute to delete. Must be in the - format ``projects/*/locations/global/grpcRoutes/*``. + format ``projects/*/locations/*/grpcRoutes/*``. """ name: str = proto.Field( diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/http_route.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/http_route.py index 0dbd3ef1cd51..b4cc52fd59aa 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/http_route.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/http_route.py @@ -44,7 +44,7 @@ class HttpRoute(proto.Message): name (str): Identifier. Name of the HttpRoute resource. It matches pattern - ``projects/*/locations/global/httpRoutes/http_route_name>``. + ``projects/*/locations/*/httpRoutes/http_route_name>``. self_link (str): Output only. Server-defined URL of this resource @@ -95,7 +95,7 @@ class HttpRoute(proto.Message): requests served by the mesh. Each mesh reference should match the pattern: - ``projects/*/locations/global/meshes/`` + ``projects/*/locations/*/meshes/`` The attached Mesh should be of a type SIDECAR gateways (MutableSequence[str]): @@ -104,7 +104,7 @@ class HttpRoute(proto.Message): requests served by the gateway. Each gateway reference should match the pattern: - ``projects/*/locations/global/gateways/`` + ``projects/*/locations/*/gateways/`` labels (MutableMapping[str, str]): Optional. Set of label tags associated with the HttpRoute resource. @@ -1120,7 +1120,7 @@ class ListHttpRoutesRequest(proto.Message): parent (str): Required. The project and location from which the HttpRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. page_size (int): Maximum number of HttpRoutes to return per call. @@ -1135,6 +1135,9 @@ class ListHttpRoutesRequest(proto.Message): Otherwise if one of the locations is down or unreachable, the Aggregated List request will fail. + filter (str): + Optional. Filter expression to restrict the + list. """ parent: str = proto.Field( @@ -1153,6 +1156,10 @@ class ListHttpRoutesRequest(proto.Message): proto.BOOL, number=4, ) + filter: str = proto.Field( + proto.STRING, + number=5, + ) class ListHttpRoutesResponse(proto.Message): @@ -1198,7 +1205,7 @@ class GetHttpRouteRequest(proto.Message): Attributes: name (str): Required. A name of the HttpRoute to get. Must be in the - format ``projects/*/locations/global/httpRoutes/*``. + format ``projects/*/locations/*/httpRoutes/*``. """ name: str = proto.Field( @@ -1213,12 +1220,14 @@ class CreateHttpRouteRequest(proto.Message): Attributes: parent (str): Required. The parent resource of the HttpRoute. Must be in - the format ``projects/*/locations/global``. + the format ``projects/*/locations/*``. http_route_id (str): Required. Short name of the HttpRoute resource to be created. http_route (google.cloud.network_services_v1.types.HttpRoute): Required. HttpRoute resource to be created. + request_id (str): + Optional. Idempotent request UUID. """ parent: str = proto.Field( @@ -1234,6 +1243,10 @@ class CreateHttpRouteRequest(proto.Message): number=3, message="HttpRoute", ) + request_id: str = proto.Field( + proto.STRING, + number=4, + ) class UpdateHttpRouteRequest(proto.Message): @@ -1269,7 +1282,7 @@ class DeleteHttpRouteRequest(proto.Message): Attributes: name (str): Required. A name of the HttpRoute to delete. Must be in the - format ``projects/*/locations/global/httpRoutes/*``. + format ``projects/*/locations/*/httpRoutes/*``. """ name: str = proto.Field( diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/mesh.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/mesh.py index 68245ca40b68..7da44a79c75e 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/mesh.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/mesh.py @@ -49,7 +49,7 @@ class Mesh(proto.Message): Attributes: name (str): Identifier. Name of the Mesh resource. It matches pattern - ``projects/*/locations/global/meshes/``. + ``projects/*/locations/*/meshes/``. self_link (str): Output only. Server-defined URL of this resource @@ -131,7 +131,7 @@ class ListMeshesRequest(proto.Message): parent (str): Required. The project and location from which the Meshes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. page_size (int): Maximum number of Meshes to return per call. page_token (str): @@ -208,7 +208,7 @@ class GetMeshRequest(proto.Message): Attributes: name (str): Required. A name of the Mesh to get. Must be in the format - ``projects/*/locations/global/meshes/*``. + ``projects/*/locations/*/meshes/*``. """ name: str = proto.Field( @@ -223,7 +223,7 @@ class CreateMeshRequest(proto.Message): Attributes: parent (str): Required. The parent resource of the Mesh. Must be in the - format ``projects/*/locations/global``. + format ``projects/*/locations/*``. mesh_id (str): Required. Short name of the Mesh resource to be created. @@ -279,7 +279,7 @@ class DeleteMeshRequest(proto.Message): Attributes: name (str): Required. A name of the Mesh to delete. Must be in the - format ``projects/*/locations/global/meshes/*``. + format ``projects/*/locations/*/meshes/*``. """ name: str = proto.Field( diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/tcp_route.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/tcp_route.py index 228cbc753905..8d95d7e8fdf5 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/tcp_route.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/tcp_route.py @@ -44,7 +44,7 @@ class TcpRoute(proto.Message): name (str): Identifier. Name of the TcpRoute resource. It matches pattern - ``projects/*/locations/global/tcpRoutes/tcp_route_name>``. + ``projects/*/locations/*/tcpRoutes/tcp_route_name>``. self_link (str): Output only. Server-defined URL of this resource @@ -69,7 +69,7 @@ class TcpRoute(proto.Message): requests served by the mesh. Each mesh reference should match the pattern: - ``projects/*/locations/global/meshes/`` + ``projects/*/locations/*/meshes/`` The attached Mesh should be of a type SIDECAR gateways (MutableSequence[str]): @@ -78,7 +78,7 @@ class TcpRoute(proto.Message): requests served by the gateway. Each gateway reference should match the pattern: - ``projects/*/locations/global/gateways/`` + ``projects/*/locations/*/gateways/`` labels (MutableMapping[str, str]): Optional. Set of label tags associated with the TcpRoute resource. @@ -276,7 +276,7 @@ class ListTcpRoutesRequest(proto.Message): parent (str): Required. The project and location from which the TcpRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. page_size (int): Maximum number of TcpRoutes to return per call. @@ -354,7 +354,7 @@ class GetTcpRouteRequest(proto.Message): Attributes: name (str): Required. A name of the TcpRoute to get. Must be in the - format ``projects/*/locations/global/tcpRoutes/*``. + format ``projects/*/locations/*/tcpRoutes/*``. """ name: str = proto.Field( @@ -369,7 +369,7 @@ class CreateTcpRouteRequest(proto.Message): Attributes: parent (str): Required. The parent resource of the TcpRoute. Must be in - the format ``projects/*/locations/global``. + the format ``projects/*/locations/*``. tcp_route_id (str): Required. Short name of the TcpRoute resource to be created. @@ -425,7 +425,7 @@ class DeleteTcpRouteRequest(proto.Message): Attributes: name (str): Required. A name of the TcpRoute to delete. Must be in the - format ``projects/*/locations/global/tcpRoutes/*``. + format ``projects/*/locations/*/tcpRoutes/*``. """ name: str = proto.Field( diff --git a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/tls_route.py b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/tls_route.py index 4c910bcd69cd..25219e4699dd 100644 --- a/packages/google-cloud-network-services/google/cloud/network_services_v1/types/tls_route.py +++ b/packages/google-cloud-network-services/google/cloud/network_services_v1/types/tls_route.py @@ -44,7 +44,7 @@ class TlsRoute(proto.Message): name (str): Identifier. Name of the TlsRoute resource. It matches pattern - ``projects/*/locations/global/tlsRoutes/tls_route_name>``. + ``projects/*/locations/*/tlsRoutes/tls_route_name>``. self_link (str): Output only. Server-defined URL of this resource @@ -69,7 +69,7 @@ class TlsRoute(proto.Message): requests served by the mesh. Each mesh reference should match the pattern: - ``projects/*/locations/global/meshes/`` + ``projects/*/locations/*/meshes/`` The attached Mesh should be of a type SIDECAR gateways (MutableSequence[str]): @@ -78,7 +78,14 @@ class TlsRoute(proto.Message): requests served by the gateway. Each gateway reference should match the pattern: - ``projects/*/locations/global/gateways/`` + ``projects/*/locations/*/gateways/`` + target_proxies (MutableSequence[str]): + Optional. TargetProxies defines a list of TargetTcpProxies + this TlsRoute is attached to, as one of the routing rules to + route the requests served by the TargetTcpProxy. + + Each TargetTcpProxy reference should match the pattern: + ``projects/*/locations/*/targetTcpProxies/`` labels (MutableMapping[str, str]): Optional. Set of label tags associated with the TlsRoute resource. @@ -232,6 +239,10 @@ class RouteDestination(proto.Message): proto.STRING, number=7, ) + target_proxies: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=13, + ) labels: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, @@ -246,7 +257,7 @@ class ListTlsRoutesRequest(proto.Message): parent (str): Required. The project and location from which the TlsRoutes should be listed, specified in the format - ``projects/*/locations/global``. + ``projects/*/locations/*``. page_size (int): Maximum number of TlsRoutes to return per call. @@ -324,7 +335,7 @@ class GetTlsRouteRequest(proto.Message): Attributes: name (str): Required. A name of the TlsRoute to get. Must be in the - format ``projects/*/locations/global/tlsRoutes/*``. + format ``projects/*/locations/*/tlsRoutes/*``. """ name: str = proto.Field( @@ -339,7 +350,7 @@ class CreateTlsRouteRequest(proto.Message): Attributes: parent (str): Required. The parent resource of the TlsRoute. Must be in - the format ``projects/*/locations/global``. + the format ``projects/*/locations/*``. tls_route_id (str): Required. Short name of the TlsRoute resource to be created. @@ -395,7 +406,7 @@ class DeleteTlsRouteRequest(proto.Message): Attributes: name (str): Required. A name of the TlsRoute to delete. Must be in the - format ``projects/*/locations/global/tlsRoutes/*``. + format ``projects/*/locations/*/tlsRoutes/*``. """ name: str = proto.Field( diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_authz_extension_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_authz_extension_async.py index 2ef94239f3b7..3846293fab42 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_authz_extension_async.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_authz_extension_async.py @@ -41,8 +41,6 @@ async def sample_create_authz_extension(): # Initialize request argument(s) authz_extension = network_services_v1.AuthzExtension() authz_extension.name = "name_value" - authz_extension.load_balancing_scheme = "EXTERNAL_MANAGED" - authz_extension.authority = "authority_value" authz_extension.service = "service_value" request = network_services_v1.CreateAuthzExtensionRequest( diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_authz_extension_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_authz_extension_sync.py index 0e194e957bc7..4cf7ffd27337 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_authz_extension_sync.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_authz_extension_sync.py @@ -41,8 +41,6 @@ def sample_create_authz_extension(): # Initialize request argument(s) authz_extension = network_services_v1.AuthzExtension() authz_extension.name = "name_value" - authz_extension.load_balancing_scheme = "EXTERNAL_MANAGED" - authz_extension.authority = "authority_value" authz_extension.service = "service_value" request = network_services_v1.CreateAuthzExtensionRequest( diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_edge_extension_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_edge_extension_async.py index f625cf6a5af5..1dc5756e2282 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_edge_extension_async.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_edge_extension_async.py @@ -49,7 +49,6 @@ async def sample_create_lb_edge_extension(): lb_edge_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_edge_extension.extension_chains.extensions.name = "name_value" lb_edge_extension.extension_chains.extensions.service = "service_value" lb_edge_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_edge_extension_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_edge_extension_sync.py index cf6982908d3e..ecb1e28837e2 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_edge_extension_sync.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_edge_extension_sync.py @@ -49,7 +49,6 @@ def sample_create_lb_edge_extension(): lb_edge_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_edge_extension.extension_chains.extensions.name = "name_value" lb_edge_extension.extension_chains.extensions.service = "service_value" lb_edge_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_route_extension_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_route_extension_async.py index 089086ce9992..bc8e15df293b 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_route_extension_async.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_route_extension_async.py @@ -49,7 +49,6 @@ async def sample_create_lb_route_extension(): lb_route_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_route_extension.extension_chains.extensions.name = "name_value" lb_route_extension.extension_chains.extensions.service = "service_value" lb_route_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_route_extension_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_route_extension_sync.py index d6e429c371a0..557a6ea5c982 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_route_extension_sync.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_route_extension_sync.py @@ -49,7 +49,6 @@ def sample_create_lb_route_extension(): lb_route_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_route_extension.extension_chains.extensions.name = "name_value" lb_route_extension.extension_chains.extensions.service = "service_value" lb_route_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_traffic_extension_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_traffic_extension_async.py index db6dee246ec5..ecb85f8230e0 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_traffic_extension_async.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_traffic_extension_async.py @@ -45,7 +45,6 @@ async def sample_create_lb_traffic_extension(): lb_traffic_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_traffic_extension.extension_chains.extensions.name = "name_value" lb_traffic_extension.extension_chains.extensions.service = "service_value" lb_traffic_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_traffic_extension_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_traffic_extension_sync.py index 6088394a7cf1..5d7f8b72e83a 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_traffic_extension_sync.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_create_lb_traffic_extension_sync.py @@ -45,7 +45,6 @@ def sample_create_lb_traffic_extension(): lb_traffic_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_traffic_extension.extension_chains.extensions.name = "name_value" lb_traffic_extension.extension_chains.extensions.service = "service_value" lb_traffic_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_authz_extension_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_authz_extension_async.py index 1545bcd4ec27..9aab556a4df2 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_authz_extension_async.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_authz_extension_async.py @@ -41,8 +41,6 @@ async def sample_update_authz_extension(): # Initialize request argument(s) authz_extension = network_services_v1.AuthzExtension() authz_extension.name = "name_value" - authz_extension.load_balancing_scheme = "EXTERNAL_MANAGED" - authz_extension.authority = "authority_value" authz_extension.service = "service_value" request = network_services_v1.UpdateAuthzExtensionRequest( diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_authz_extension_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_authz_extension_sync.py index c3d31d026404..8ef116979bec 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_authz_extension_sync.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_authz_extension_sync.py @@ -41,8 +41,6 @@ def sample_update_authz_extension(): # Initialize request argument(s) authz_extension = network_services_v1.AuthzExtension() authz_extension.name = "name_value" - authz_extension.load_balancing_scheme = "EXTERNAL_MANAGED" - authz_extension.authority = "authority_value" authz_extension.service = "service_value" request = network_services_v1.UpdateAuthzExtensionRequest( diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_edge_extension_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_edge_extension_async.py index 4079c9a6697a..82e480e57c05 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_edge_extension_async.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_edge_extension_async.py @@ -49,7 +49,6 @@ async def sample_update_lb_edge_extension(): lb_edge_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_edge_extension.extension_chains.extensions.name = "name_value" lb_edge_extension.extension_chains.extensions.service = "service_value" lb_edge_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_edge_extension_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_edge_extension_sync.py index 5cfabd8ee546..55a247f194df 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_edge_extension_sync.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_edge_extension_sync.py @@ -49,7 +49,6 @@ def sample_update_lb_edge_extension(): lb_edge_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_edge_extension.extension_chains.extensions.name = "name_value" lb_edge_extension.extension_chains.extensions.service = "service_value" lb_edge_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_route_extension_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_route_extension_async.py index a3e6bff4db4d..019e9164ce03 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_route_extension_async.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_route_extension_async.py @@ -49,7 +49,6 @@ async def sample_update_lb_route_extension(): lb_route_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_route_extension.extension_chains.extensions.name = "name_value" lb_route_extension.extension_chains.extensions.service = "service_value" lb_route_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_route_extension_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_route_extension_sync.py index 3afdd0c5fa7e..fcc53c4dbe11 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_route_extension_sync.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_route_extension_sync.py @@ -49,7 +49,6 @@ def sample_update_lb_route_extension(): lb_route_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_route_extension.extension_chains.extensions.name = "name_value" lb_route_extension.extension_chains.extensions.service = "service_value" lb_route_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_traffic_extension_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_traffic_extension_async.py index e67bc558d7d4..747bda3e909d 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_traffic_extension_async.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_traffic_extension_async.py @@ -45,7 +45,6 @@ async def sample_update_lb_traffic_extension(): lb_traffic_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_traffic_extension.extension_chains.extensions.name = "name_value" lb_traffic_extension.extension_chains.extensions.service = "service_value" lb_traffic_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_traffic_extension_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_traffic_extension_sync.py index c05e0fb7ab7d..df1332a36862 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_traffic_extension_sync.py +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_dep_service_update_lb_traffic_extension_sync.py @@ -45,7 +45,6 @@ def sample_update_lb_traffic_extension(): lb_traffic_extension.extension_chains.match_condition.cel_expression = ( "cel_expression_value" ) - lb_traffic_extension.extension_chains.extensions.name = "name_value" lb_traffic_extension.extension_chains.extensions.service = "service_value" lb_traffic_extension.load_balancing_scheme = "EXTERNAL_MANAGED" diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_create_agent_gateway_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_create_agent_gateway_async.py new file mode 100644 index 000000000000..5a6ddac09764 --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_create_agent_gateway_async.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateAgentGateway +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_CreateAgentGateway_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +async def sample_create_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.CreateAgentGatewayRequest( + parent="parent_value", + agent_gateway_id="agent_gateway_id_value", + ) + + # Make the request + operation = await client.create_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + +# [END networkservices_v1_generated_NetworkServices_CreateAgentGateway_async] diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_create_agent_gateway_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_create_agent_gateway_sync.py new file mode 100644 index 000000000000..5a878783043a --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_create_agent_gateway_sync.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateAgentGateway +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_CreateAgentGateway_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +def sample_create_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.CreateAgentGatewayRequest( + parent="parent_value", + agent_gateway_id="agent_gateway_id_value", + ) + + # Make the request + operation = client.create_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + +# [END networkservices_v1_generated_NetworkServices_CreateAgentGateway_sync] diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_delete_agent_gateway_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_delete_agent_gateway_async.py new file mode 100644 index 000000000000..4cd6ca2d6271 --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_delete_agent_gateway_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteAgentGateway +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_DeleteAgentGateway_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +async def sample_delete_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.DeleteAgentGatewayRequest( + name="name_value", + ) + + # Make the request + operation = await client.delete_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + +# [END networkservices_v1_generated_NetworkServices_DeleteAgentGateway_async] diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_delete_agent_gateway_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_delete_agent_gateway_sync.py new file mode 100644 index 000000000000..2ac7d846e0a6 --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_delete_agent_gateway_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteAgentGateway +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_DeleteAgentGateway_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +def sample_delete_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.DeleteAgentGatewayRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + +# [END networkservices_v1_generated_NetworkServices_DeleteAgentGateway_sync] diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_get_agent_gateway_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_get_agent_gateway_async.py new file mode 100644 index 000000000000..5023bb19b743 --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_get_agent_gateway_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAgentGateway +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_GetAgentGateway_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +async def sample_get_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.GetAgentGatewayRequest( + name="name_value", + ) + + # Make the request + response = await client.get_agent_gateway(request=request) + + # Handle the response + print(response) + + +# [END networkservices_v1_generated_NetworkServices_GetAgentGateway_async] diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_get_agent_gateway_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_get_agent_gateway_sync.py new file mode 100644 index 000000000000..4cd0fd9a8dd0 --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_get_agent_gateway_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAgentGateway +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_GetAgentGateway_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +def sample_get_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.GetAgentGatewayRequest( + name="name_value", + ) + + # Make the request + response = client.get_agent_gateway(request=request) + + # Handle the response + print(response) + + +# [END networkservices_v1_generated_NetworkServices_GetAgentGateway_sync] diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_list_agent_gateways_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_list_agent_gateways_async.py new file mode 100644 index 000000000000..d5feb9f25b84 --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_list_agent_gateways_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAgentGateways +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_ListAgentGateways_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +async def sample_list_agent_gateways(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.ListAgentGatewaysRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_agent_gateways(request=request) + + # Handle the response + async for response in page_result: + print(response) + + +# [END networkservices_v1_generated_NetworkServices_ListAgentGateways_async] diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_list_agent_gateways_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_list_agent_gateways_sync.py new file mode 100644 index 000000000000..91d8ced79b00 --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_list_agent_gateways_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAgentGateways +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_ListAgentGateways_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +def sample_list_agent_gateways(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.ListAgentGatewaysRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_agent_gateways(request=request) + + # Handle the response + for response in page_result: + print(response) + + +# [END networkservices_v1_generated_NetworkServices_ListAgentGateways_sync] diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_update_agent_gateway_async.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_update_agent_gateway_async.py new file mode 100644 index 000000000000..ab723589fa54 --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_update_agent_gateway_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateAgentGateway +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_UpdateAgentGateway_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +async def sample_update_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesAsyncClient() + + # Initialize request argument(s) + request = network_services_v1.UpdateAgentGatewayRequest() + + # Make the request + operation = await client.update_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + +# [END networkservices_v1_generated_NetworkServices_UpdateAgentGateway_async] diff --git a/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_update_agent_gateway_sync.py b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_update_agent_gateway_sync.py new file mode 100644 index 000000000000..62f4b35e15e8 --- /dev/null +++ b/packages/google-cloud-network-services/samples/generated_samples/networkservices_v1_generated_network_services_update_agent_gateway_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateAgentGateway +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-network-services + + +# [START networkservices_v1_generated_NetworkServices_UpdateAgentGateway_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import network_services_v1 + + +def sample_update_agent_gateway(): + # Create a client + client = network_services_v1.NetworkServicesClient() + + # Initialize request argument(s) + request = network_services_v1.UpdateAgentGatewayRequest() + + # Make the request + operation = client.update_agent_gateway(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + +# [END networkservices_v1_generated_NetworkServices_UpdateAgentGateway_sync] diff --git a/packages/google-cloud-network-services/samples/generated_samples/snippet_metadata_google.cloud.networkservices.v1.json b/packages/google-cloud-network-services/samples/generated_samples/snippet_metadata_google.cloud.networkservices.v1.json index 63ae4ff67dbe..f3c4a8668983 100644 --- a/packages/google-cloud-network-services/samples/generated_samples/snippet_metadata_google.cloud.networkservices.v1.json +++ b/packages/google-cloud-network-services/samples/generated_samples/snippet_metadata_google.cloud.networkservices.v1.json @@ -68,12 +68,12 @@ "regionTag": "networkservices_v1_generated_DepService_CreateAuthzExtension_async", "segments": [ { - "end": 63, + "end": 61, "start": 27, "type": "FULL" }, { - "end": 63, + "end": 61, "start": 27, "type": "SHORT" }, @@ -83,18 +83,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 53, + "end": 51, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 60, - "start": 54, + "end": 58, + "start": 52, "type": "REQUEST_EXECUTION" }, { - "end": 64, - "start": 61, + "end": 62, + "start": 59, "type": "RESPONSE_HANDLING" } ], @@ -156,12 +156,12 @@ "regionTag": "networkservices_v1_generated_DepService_CreateAuthzExtension_sync", "segments": [ { - "end": 63, + "end": 61, "start": 27, "type": "FULL" }, { - "end": 63, + "end": 61, "start": 27, "type": "SHORT" }, @@ -171,18 +171,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 53, + "end": 51, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 60, - "start": 54, + "end": 58, + "start": 52, "type": "REQUEST_EXECUTION" }, { - "end": 64, - "start": 61, + "end": 62, + "start": 59, "type": "RESPONSE_HANDLING" } ], @@ -245,12 +245,12 @@ "regionTag": "networkservices_v1_generated_DepService_CreateLbEdgeExtension_async", "segments": [ { - "end": 66, + "end": 65, "start": 27, "type": "FULL" }, { - "end": 66, + "end": 65, "start": 27, "type": "SHORT" }, @@ -260,18 +260,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 56, + "end": 55, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 63, - "start": 57, + "end": 62, + "start": 56, "type": "REQUEST_EXECUTION" }, { - "end": 67, - "start": 64, + "end": 66, + "start": 63, "type": "RESPONSE_HANDLING" } ], @@ -333,12 +333,12 @@ "regionTag": "networkservices_v1_generated_DepService_CreateLbEdgeExtension_sync", "segments": [ { - "end": 66, + "end": 65, "start": 27, "type": "FULL" }, { - "end": 66, + "end": 65, "start": 27, "type": "SHORT" }, @@ -348,18 +348,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 56, + "end": 55, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 63, - "start": 57, + "end": 62, + "start": 56, "type": "REQUEST_EXECUTION" }, { - "end": 67, - "start": 64, + "end": 66, + "start": 63, "type": "RESPONSE_HANDLING" } ], @@ -422,12 +422,12 @@ "regionTag": "networkservices_v1_generated_DepService_CreateLbRouteExtension_async", "segments": [ { - "end": 66, + "end": 65, "start": 27, "type": "FULL" }, { - "end": 66, + "end": 65, "start": 27, "type": "SHORT" }, @@ -437,18 +437,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 56, + "end": 55, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 63, - "start": 57, + "end": 62, + "start": 56, "type": "REQUEST_EXECUTION" }, { - "end": 67, - "start": 64, + "end": 66, + "start": 63, "type": "RESPONSE_HANDLING" } ], @@ -510,12 +510,12 @@ "regionTag": "networkservices_v1_generated_DepService_CreateLbRouteExtension_sync", "segments": [ { - "end": 66, + "end": 65, "start": 27, "type": "FULL" }, { - "end": 66, + "end": 65, "start": 27, "type": "SHORT" }, @@ -525,18 +525,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 56, + "end": 55, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 63, - "start": 57, + "end": 62, + "start": 56, "type": "REQUEST_EXECUTION" }, { - "end": 67, - "start": 64, + "end": 66, + "start": 63, "type": "RESPONSE_HANDLING" } ], @@ -599,12 +599,12 @@ "regionTag": "networkservices_v1_generated_DepService_CreateLbTrafficExtension_async", "segments": [ { - "end": 65, + "end": 64, "start": 27, "type": "FULL" }, { - "end": 65, + "end": 64, "start": 27, "type": "SHORT" }, @@ -614,18 +614,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 55, + "end": 54, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 62, - "start": 56, + "end": 61, + "start": 55, "type": "REQUEST_EXECUTION" }, { - "end": 66, - "start": 63, + "end": 65, + "start": 62, "type": "RESPONSE_HANDLING" } ], @@ -687,12 +687,12 @@ "regionTag": "networkservices_v1_generated_DepService_CreateLbTrafficExtension_sync", "segments": [ { - "end": 65, + "end": 64, "start": 27, "type": "FULL" }, { - "end": 65, + "end": 64, "start": 27, "type": "SHORT" }, @@ -702,18 +702,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 55, + "end": 54, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 62, - "start": 56, + "end": 61, + "start": 55, "type": "REQUEST_EXECUTION" }, { - "end": 66, - "start": 63, + "end": 65, + "start": 62, "type": "RESPONSE_HANDLING" } ], @@ -2704,12 +2704,12 @@ "regionTag": "networkservices_v1_generated_DepService_UpdateAuthzExtension_async", "segments": [ { - "end": 61, + "end": 59, "start": 27, "type": "FULL" }, { - "end": 61, + "end": 59, "start": 27, "type": "SHORT" }, @@ -2719,18 +2719,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 51, + "end": 49, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 58, - "start": 52, + "end": 56, + "start": 50, "type": "REQUEST_EXECUTION" }, { - "end": 62, - "start": 59, + "end": 60, + "start": 57, "type": "RESPONSE_HANDLING" } ], @@ -2788,12 +2788,12 @@ "regionTag": "networkservices_v1_generated_DepService_UpdateAuthzExtension_sync", "segments": [ { - "end": 61, + "end": 59, "start": 27, "type": "FULL" }, { - "end": 61, + "end": 59, "start": 27, "type": "SHORT" }, @@ -2803,18 +2803,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 51, + "end": 49, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 58, - "start": 52, + "end": 56, + "start": 50, "type": "REQUEST_EXECUTION" }, { - "end": 62, - "start": 59, + "end": 60, + "start": 57, "type": "RESPONSE_HANDLING" } ], @@ -2873,12 +2873,12 @@ "regionTag": "networkservices_v1_generated_DepService_UpdateLbEdgeExtension_async", "segments": [ { - "end": 64, + "end": 63, "start": 27, "type": "FULL" }, { - "end": 64, + "end": 63, "start": 27, "type": "SHORT" }, @@ -2888,18 +2888,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 54, + "end": 53, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 61, - "start": 55, + "end": 60, + "start": 54, "type": "REQUEST_EXECUTION" }, { - "end": 65, - "start": 62, + "end": 64, + "start": 61, "type": "RESPONSE_HANDLING" } ], @@ -2957,12 +2957,12 @@ "regionTag": "networkservices_v1_generated_DepService_UpdateLbEdgeExtension_sync", "segments": [ { - "end": 64, + "end": 63, "start": 27, "type": "FULL" }, { - "end": 64, + "end": 63, "start": 27, "type": "SHORT" }, @@ -2972,18 +2972,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 54, + "end": 53, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 61, - "start": 55, + "end": 60, + "start": 54, "type": "REQUEST_EXECUTION" }, { - "end": 65, - "start": 62, + "end": 64, + "start": 61, "type": "RESPONSE_HANDLING" } ], @@ -3042,12 +3042,12 @@ "regionTag": "networkservices_v1_generated_DepService_UpdateLbRouteExtension_async", "segments": [ { - "end": 64, + "end": 63, "start": 27, "type": "FULL" }, { - "end": 64, + "end": 63, "start": 27, "type": "SHORT" }, @@ -3057,18 +3057,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 54, + "end": 53, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 61, - "start": 55, + "end": 60, + "start": 54, "type": "REQUEST_EXECUTION" }, { - "end": 65, - "start": 62, + "end": 64, + "start": 61, "type": "RESPONSE_HANDLING" } ], @@ -3126,12 +3126,12 @@ "regionTag": "networkservices_v1_generated_DepService_UpdateLbRouteExtension_sync", "segments": [ { - "end": 64, + "end": 63, "start": 27, "type": "FULL" }, { - "end": 64, + "end": 63, "start": 27, "type": "SHORT" }, @@ -3141,18 +3141,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 54, + "end": 53, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 61, - "start": 55, + "end": 60, + "start": 54, "type": "REQUEST_EXECUTION" }, { - "end": 65, - "start": 62, + "end": 64, + "start": 61, "type": "RESPONSE_HANDLING" } ], @@ -3211,12 +3211,12 @@ "regionTag": "networkservices_v1_generated_DepService_UpdateLbTrafficExtension_async", "segments": [ { - "end": 63, + "end": 62, "start": 27, "type": "FULL" }, { - "end": 63, + "end": 62, "start": 27, "type": "SHORT" }, @@ -3226,18 +3226,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 53, + "end": 52, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 60, - "start": 54, + "end": 59, + "start": 53, "type": "REQUEST_EXECUTION" }, { - "end": 64, - "start": 61, + "end": 63, + "start": 60, "type": "RESPONSE_HANDLING" } ], @@ -3295,12 +3295,12 @@ "regionTag": "networkservices_v1_generated_DepService_UpdateLbTrafficExtension_sync", "segments": [ { - "end": 63, + "end": 62, "start": 27, "type": "FULL" }, { - "end": 63, + "end": 62, "start": 27, "type": "SHORT" }, @@ -3310,18 +3310,18 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 53, + "end": 52, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 60, - "start": 54, + "end": 59, + "start": 53, "type": "REQUEST_EXECUTION" }, { - "end": 64, - "start": 61, + "end": 63, + "start": 60, "type": "RESPONSE_HANDLING" } ], @@ -3335,30 +3335,30 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", "shortName": "NetworkServicesAsyncClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.create_endpoint_policy", + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.create_agent_gateway", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.CreateEndpointPolicy", + "fullName": "google.cloud.networkservices.v1.NetworkServices.CreateAgentGateway", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "CreateEndpointPolicy" + "shortName": "CreateAgentGateway" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.CreateEndpointPolicyRequest" + "type": "google.cloud.network_services_v1.types.CreateAgentGatewayRequest" }, { "name": "parent", "type": "str" }, { - "name": "endpoint_policy", - "type": "google.cloud.network_services_v1.types.EndpointPolicy" + "name": "agent_gateway", + "type": "google.cloud.network_services_v1.types.AgentGateway" }, { - "name": "endpoint_policy_id", + "name": "agent_gateway_id", "type": "str" }, { @@ -3375,21 +3375,21 @@ } ], "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "create_endpoint_policy" + "shortName": "create_agent_gateway" }, - "description": "Sample for CreateEndpointPolicy", - "file": "networkservices_v1_generated_network_services_create_endpoint_policy_async.py", + "description": "Sample for CreateAgentGateway", + "file": "networkservices_v1_generated_network_services_create_agent_gateway_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_CreateEndpointPolicy_async", + "regionTag": "networkservices_v1_generated_NetworkServices_CreateAgentGateway_async", "segments": [ { - "end": 60, + "end": 56, "start": 27, "type": "FULL" }, { - "end": 60, + "end": 56, "start": 27, "type": "SHORT" }, @@ -3399,22 +3399,22 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 50, + "end": 46, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 57, - "start": 51, + "end": 53, + "start": 47, "type": "REQUEST_EXECUTION" }, { - "end": 61, - "start": 58, + "end": 57, + "start": 54, "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_create_endpoint_policy_async.py" + "title": "networkservices_v1_generated_network_services_create_agent_gateway_async.py" }, { "canonical": true, @@ -3423,30 +3423,30 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesClient", "shortName": "NetworkServicesClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesClient.create_endpoint_policy", + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.create_agent_gateway", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.CreateEndpointPolicy", + "fullName": "google.cloud.networkservices.v1.NetworkServices.CreateAgentGateway", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "CreateEndpointPolicy" + "shortName": "CreateAgentGateway" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.CreateEndpointPolicyRequest" + "type": "google.cloud.network_services_v1.types.CreateAgentGatewayRequest" }, { "name": "parent", "type": "str" }, { - "name": "endpoint_policy", - "type": "google.cloud.network_services_v1.types.EndpointPolicy" + "name": "agent_gateway", + "type": "google.cloud.network_services_v1.types.AgentGateway" }, { - "name": "endpoint_policy_id", + "name": "agent_gateway_id", "type": "str" }, { @@ -3463,21 +3463,21 @@ } ], "resultType": "google.api_core.operation.Operation", - "shortName": "create_endpoint_policy" + "shortName": "create_agent_gateway" }, - "description": "Sample for CreateEndpointPolicy", - "file": "networkservices_v1_generated_network_services_create_endpoint_policy_sync.py", + "description": "Sample for CreateAgentGateway", + "file": "networkservices_v1_generated_network_services_create_agent_gateway_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_CreateEndpointPolicy_sync", + "regionTag": "networkservices_v1_generated_NetworkServices_CreateAgentGateway_sync", "segments": [ { - "end": 60, + "end": 56, "start": 27, "type": "FULL" }, { - "end": 60, + "end": 56, "start": 27, "type": "SHORT" }, @@ -3487,14 +3487,191 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 50, + "end": 46, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 57, - "start": 51, - "type": "REQUEST_EXECUTION" + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_create_agent_gateway_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", + "shortName": "NetworkServicesAsyncClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.create_endpoint_policy", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.CreateEndpointPolicy", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "CreateEndpointPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.CreateEndpointPolicyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "endpoint_policy", + "type": "google.cloud.network_services_v1.types.EndpointPolicy" + }, + { + "name": "endpoint_policy_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_endpoint_policy" + }, + "description": "Sample for CreateEndpointPolicy", + "file": "networkservices_v1_generated_network_services_create_endpoint_policy_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_CreateEndpointPolicy_async", + "segments": [ + { + "end": 60, + "start": 27, + "type": "FULL" + }, + { + "end": 60, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 57, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 61, + "start": 58, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_create_endpoint_policy_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesClient", + "shortName": "NetworkServicesClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.create_endpoint_policy", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.CreateEndpointPolicy", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "CreateEndpointPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.CreateEndpointPolicyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "endpoint_policy", + "type": "google.cloud.network_services_v1.types.EndpointPolicy" + }, + { + "name": "endpoint_policy_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_endpoint_policy" + }, + "description": "Sample for CreateEndpointPolicy", + "file": "networkservices_v1_generated_network_services_create_endpoint_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_CreateEndpointPolicy_sync", + "segments": [ + { + "end": 60, + "start": 27, + "type": "FULL" + }, + { + "end": 60, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 57, + "start": 51, + "type": "REQUEST_EXECUTION" }, { "end": 61, @@ -5282,19 +5459,19 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", "shortName": "NetworkServicesAsyncClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.delete_endpoint_policy", + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.delete_agent_gateway", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteEndpointPolicy", + "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteAgentGateway", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "DeleteEndpointPolicy" + "shortName": "DeleteAgentGateway" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.DeleteEndpointPolicyRequest" + "type": "google.cloud.network_services_v1.types.DeleteAgentGatewayRequest" }, { "name": "name", @@ -5314,13 +5491,13 @@ } ], "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "delete_endpoint_policy" + "shortName": "delete_agent_gateway" }, - "description": "Sample for DeleteEndpointPolicy", - "file": "networkservices_v1_generated_network_services_delete_endpoint_policy_async.py", + "description": "Sample for DeleteAgentGateway", + "file": "networkservices_v1_generated_network_services_delete_agent_gateway_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_DeleteEndpointPolicy_async", + "regionTag": "networkservices_v1_generated_NetworkServices_DeleteAgentGateway_async", "segments": [ { "end": 55, @@ -5353,7 +5530,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_delete_endpoint_policy_async.py" + "title": "networkservices_v1_generated_network_services_delete_agent_gateway_async.py" }, { "canonical": true, @@ -5362,19 +5539,19 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesClient", "shortName": "NetworkServicesClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesClient.delete_endpoint_policy", + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.delete_agent_gateway", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteEndpointPolicy", + "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteAgentGateway", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "DeleteEndpointPolicy" + "shortName": "DeleteAgentGateway" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.DeleteEndpointPolicyRequest" + "type": "google.cloud.network_services_v1.types.DeleteAgentGatewayRequest" }, { "name": "name", @@ -5394,13 +5571,13 @@ } ], "resultType": "google.api_core.operation.Operation", - "shortName": "delete_endpoint_policy" + "shortName": "delete_agent_gateway" }, - "description": "Sample for DeleteEndpointPolicy", - "file": "networkservices_v1_generated_network_services_delete_endpoint_policy_sync.py", + "description": "Sample for DeleteAgentGateway", + "file": "networkservices_v1_generated_network_services_delete_agent_gateway_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_DeleteEndpointPolicy_sync", + "regionTag": "networkservices_v1_generated_NetworkServices_DeleteAgentGateway_sync", "segments": [ { "end": 55, @@ -5433,7 +5610,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_delete_endpoint_policy_sync.py" + "title": "networkservices_v1_generated_network_services_delete_agent_gateway_sync.py" }, { "canonical": true, @@ -5443,19 +5620,19 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", "shortName": "NetworkServicesAsyncClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.delete_gateway", + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.delete_endpoint_policy", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteGateway", + "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteEndpointPolicy", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "DeleteGateway" + "shortName": "DeleteEndpointPolicy" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.DeleteGatewayRequest" + "type": "google.cloud.network_services_v1.types.DeleteEndpointPolicyRequest" }, { "name": "name", @@ -5475,13 +5652,13 @@ } ], "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "delete_gateway" + "shortName": "delete_endpoint_policy" }, - "description": "Sample for DeleteGateway", - "file": "networkservices_v1_generated_network_services_delete_gateway_async.py", + "description": "Sample for DeleteEndpointPolicy", + "file": "networkservices_v1_generated_network_services_delete_endpoint_policy_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_DeleteGateway_async", + "regionTag": "networkservices_v1_generated_NetworkServices_DeleteEndpointPolicy_async", "segments": [ { "end": 55, @@ -5514,7 +5691,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_delete_gateway_async.py" + "title": "networkservices_v1_generated_network_services_delete_endpoint_policy_async.py" }, { "canonical": true, @@ -5523,19 +5700,19 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesClient", "shortName": "NetworkServicesClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesClient.delete_gateway", + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.delete_endpoint_policy", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteGateway", + "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteEndpointPolicy", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "DeleteGateway" + "shortName": "DeleteEndpointPolicy" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.DeleteGatewayRequest" + "type": "google.cloud.network_services_v1.types.DeleteEndpointPolicyRequest" }, { "name": "name", @@ -5555,13 +5732,13 @@ } ], "resultType": "google.api_core.operation.Operation", - "shortName": "delete_gateway" + "shortName": "delete_endpoint_policy" }, - "description": "Sample for DeleteGateway", - "file": "networkservices_v1_generated_network_services_delete_gateway_sync.py", + "description": "Sample for DeleteEndpointPolicy", + "file": "networkservices_v1_generated_network_services_delete_endpoint_policy_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_DeleteGateway_sync", + "regionTag": "networkservices_v1_generated_NetworkServices_DeleteEndpointPolicy_sync", "segments": [ { "end": 55, @@ -5594,7 +5771,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_delete_gateway_sync.py" + "title": "networkservices_v1_generated_network_services_delete_endpoint_policy_sync.py" }, { "canonical": true, @@ -5604,19 +5781,19 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", "shortName": "NetworkServicesAsyncClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.delete_grpc_route", + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.delete_gateway", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteGrpcRoute", + "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteGateway", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "DeleteGrpcRoute" + "shortName": "DeleteGateway" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.DeleteGrpcRouteRequest" + "type": "google.cloud.network_services_v1.types.DeleteGatewayRequest" }, { "name": "name", @@ -5636,13 +5813,13 @@ } ], "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "delete_grpc_route" + "shortName": "delete_gateway" }, - "description": "Sample for DeleteGrpcRoute", - "file": "networkservices_v1_generated_network_services_delete_grpc_route_async.py", + "description": "Sample for DeleteGateway", + "file": "networkservices_v1_generated_network_services_delete_gateway_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_DeleteGrpcRoute_async", + "regionTag": "networkservices_v1_generated_NetworkServices_DeleteGateway_async", "segments": [ { "end": 55, @@ -5675,7 +5852,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_delete_grpc_route_async.py" + "title": "networkservices_v1_generated_network_services_delete_gateway_async.py" }, { "canonical": true, @@ -5684,14 +5861,175 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesClient", "shortName": "NetworkServicesClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesClient.delete_grpc_route", + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.delete_gateway", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteGrpcRoute", + "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteGateway", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "DeleteGrpcRoute" + "shortName": "DeleteGateway" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.DeleteGatewayRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_gateway" + }, + "description": "Sample for DeleteGateway", + "file": "networkservices_v1_generated_network_services_delete_gateway_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_DeleteGateway_sync", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_delete_gateway_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", + "shortName": "NetworkServicesAsyncClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.delete_grpc_route", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteGrpcRoute", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "DeleteGrpcRoute" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.DeleteGrpcRouteRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_grpc_route" + }, + "description": "Sample for DeleteGrpcRoute", + "file": "networkservices_v1_generated_network_services_delete_grpc_route_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_DeleteGrpcRoute_async", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_delete_grpc_route_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesClient", + "shortName": "NetworkServicesClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.delete_grpc_route", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.DeleteGrpcRoute", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "DeleteGrpcRoute" }, "parameters": [ { @@ -7045,6 +7383,167 @@ ], "title": "networkservices_v1_generated_network_services_delete_wasm_plugin_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", + "shortName": "NetworkServicesAsyncClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.get_agent_gateway", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.GetAgentGateway", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "GetAgentGateway" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.GetAgentGatewayRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.cloud.network_services_v1.types.AgentGateway", + "shortName": "get_agent_gateway" + }, + "description": "Sample for GetAgentGateway", + "file": "networkservices_v1_generated_network_services_get_agent_gateway_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_GetAgentGateway_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_get_agent_gateway_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesClient", + "shortName": "NetworkServicesClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.get_agent_gateway", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.GetAgentGateway", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "GetAgentGateway" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.GetAgentGatewayRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.cloud.network_services_v1.types.AgentGateway", + "shortName": "get_agent_gateway" + }, + "description": "Sample for GetAgentGateway", + "file": "networkservices_v1_generated_network_services_get_agent_gateway_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_GetAgentGateway_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_get_agent_gateway_sync.py" + }, { "canonical": true, "clientMethod": { @@ -8694,14 +9193,175 @@ "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], - "resultType": "google.cloud.network_services_v1.types.TlsRoute", - "shortName": "get_tls_route" + "resultType": "google.cloud.network_services_v1.types.TlsRoute", + "shortName": "get_tls_route" + }, + "description": "Sample for GetTlsRoute", + "file": "networkservices_v1_generated_network_services_get_tls_route_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_GetTlsRoute_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_get_tls_route_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesClient", + "shortName": "NetworkServicesClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.get_tls_route", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.GetTlsRoute", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "GetTlsRoute" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.GetTlsRouteRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.cloud.network_services_v1.types.TlsRoute", + "shortName": "get_tls_route" + }, + "description": "Sample for GetTlsRoute", + "file": "networkservices_v1_generated_network_services_get_tls_route_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_GetTlsRoute_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_get_tls_route_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", + "shortName": "NetworkServicesAsyncClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.get_wasm_plugin_version", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.GetWasmPluginVersion", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "GetWasmPluginVersion" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.GetWasmPluginVersionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.cloud.network_services_v1.types.WasmPluginVersion", + "shortName": "get_wasm_plugin_version" }, - "description": "Sample for GetTlsRoute", - "file": "networkservices_v1_generated_network_services_get_tls_route_async.py", + "description": "Sample for GetWasmPluginVersion", + "file": "networkservices_v1_generated_network_services_get_wasm_plugin_version_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_GetTlsRoute_async", + "regionTag": "networkservices_v1_generated_NetworkServices_GetWasmPluginVersion_async", "segments": [ { "end": 51, @@ -8734,7 +9394,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_get_tls_route_async.py" + "title": "networkservices_v1_generated_network_services_get_wasm_plugin_version_async.py" }, { "canonical": true, @@ -8743,19 +9403,19 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesClient", "shortName": "NetworkServicesClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesClient.get_tls_route", + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.get_wasm_plugin_version", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.GetTlsRoute", + "fullName": "google.cloud.networkservices.v1.NetworkServices.GetWasmPluginVersion", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "GetTlsRoute" + "shortName": "GetWasmPluginVersion" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.GetTlsRouteRequest" + "type": "google.cloud.network_services_v1.types.GetWasmPluginVersionRequest" }, { "name": "name", @@ -8774,14 +9434,14 @@ "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], - "resultType": "google.cloud.network_services_v1.types.TlsRoute", - "shortName": "get_tls_route" + "resultType": "google.cloud.network_services_v1.types.WasmPluginVersion", + "shortName": "get_wasm_plugin_version" }, - "description": "Sample for GetTlsRoute", - "file": "networkservices_v1_generated_network_services_get_tls_route_sync.py", + "description": "Sample for GetWasmPluginVersion", + "file": "networkservices_v1_generated_network_services_get_wasm_plugin_version_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_GetTlsRoute_sync", + "regionTag": "networkservices_v1_generated_NetworkServices_GetWasmPluginVersion_sync", "segments": [ { "end": 51, @@ -8814,7 +9474,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_get_tls_route_sync.py" + "title": "networkservices_v1_generated_network_services_get_wasm_plugin_version_sync.py" }, { "canonical": true, @@ -8824,19 +9484,19 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", "shortName": "NetworkServicesAsyncClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.get_wasm_plugin_version", + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.get_wasm_plugin", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.GetWasmPluginVersion", + "fullName": "google.cloud.networkservices.v1.NetworkServices.GetWasmPlugin", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "GetWasmPluginVersion" + "shortName": "GetWasmPlugin" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.GetWasmPluginVersionRequest" + "type": "google.cloud.network_services_v1.types.GetWasmPluginRequest" }, { "name": "name", @@ -8855,14 +9515,14 @@ "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], - "resultType": "google.cloud.network_services_v1.types.WasmPluginVersion", - "shortName": "get_wasm_plugin_version" + "resultType": "google.cloud.network_services_v1.types.WasmPlugin", + "shortName": "get_wasm_plugin" }, - "description": "Sample for GetWasmPluginVersion", - "file": "networkservices_v1_generated_network_services_get_wasm_plugin_version_async.py", + "description": "Sample for GetWasmPlugin", + "file": "networkservices_v1_generated_network_services_get_wasm_plugin_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_GetWasmPluginVersion_async", + "regionTag": "networkservices_v1_generated_NetworkServices_GetWasmPlugin_async", "segments": [ { "end": 51, @@ -8895,7 +9555,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_get_wasm_plugin_version_async.py" + "title": "networkservices_v1_generated_network_services_get_wasm_plugin_async.py" }, { "canonical": true, @@ -8904,19 +9564,19 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesClient", "shortName": "NetworkServicesClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesClient.get_wasm_plugin_version", + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.get_wasm_plugin", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.GetWasmPluginVersion", + "fullName": "google.cloud.networkservices.v1.NetworkServices.GetWasmPlugin", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "GetWasmPluginVersion" + "shortName": "GetWasmPlugin" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.GetWasmPluginVersionRequest" + "type": "google.cloud.network_services_v1.types.GetWasmPluginRequest" }, { "name": "name", @@ -8935,14 +9595,14 @@ "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], - "resultType": "google.cloud.network_services_v1.types.WasmPluginVersion", - "shortName": "get_wasm_plugin_version" + "resultType": "google.cloud.network_services_v1.types.WasmPlugin", + "shortName": "get_wasm_plugin" }, - "description": "Sample for GetWasmPluginVersion", - "file": "networkservices_v1_generated_network_services_get_wasm_plugin_version_sync.py", + "description": "Sample for GetWasmPlugin", + "file": "networkservices_v1_generated_network_services_get_wasm_plugin_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_GetWasmPluginVersion_sync", + "regionTag": "networkservices_v1_generated_NetworkServices_GetWasmPlugin_sync", "segments": [ { "end": 51, @@ -8975,7 +9635,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_get_wasm_plugin_version_sync.py" + "title": "networkservices_v1_generated_network_services_get_wasm_plugin_sync.py" }, { "canonical": true, @@ -8985,22 +9645,22 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", "shortName": "NetworkServicesAsyncClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.get_wasm_plugin", + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.list_agent_gateways", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.GetWasmPlugin", + "fullName": "google.cloud.networkservices.v1.NetworkServices.ListAgentGateways", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "GetWasmPlugin" + "shortName": "ListAgentGateways" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.GetWasmPluginRequest" + "type": "google.cloud.network_services_v1.types.ListAgentGatewaysRequest" }, { - "name": "name", + "name": "parent", "type": "str" }, { @@ -9016,22 +9676,22 @@ "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], - "resultType": "google.cloud.network_services_v1.types.WasmPlugin", - "shortName": "get_wasm_plugin" + "resultType": "google.cloud.network_services_v1.services.network_services.pagers.ListAgentGatewaysAsyncPager", + "shortName": "list_agent_gateways" }, - "description": "Sample for GetWasmPlugin", - "file": "networkservices_v1_generated_network_services_get_wasm_plugin_async.py", + "description": "Sample for ListAgentGateways", + "file": "networkservices_v1_generated_network_services_list_agent_gateways_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_GetWasmPlugin_async", + "regionTag": "networkservices_v1_generated_NetworkServices_ListAgentGateways_async", "segments": [ { - "end": 51, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 52, "start": 27, "type": "SHORT" }, @@ -9051,12 +9711,12 @@ "type": "REQUEST_EXECUTION" }, { - "end": 52, + "end": 53, "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_get_wasm_plugin_async.py" + "title": "networkservices_v1_generated_network_services_list_agent_gateways_async.py" }, { "canonical": true, @@ -9065,22 +9725,22 @@ "fullName": "google.cloud.network_services_v1.NetworkServicesClient", "shortName": "NetworkServicesClient" }, - "fullName": "google.cloud.network_services_v1.NetworkServicesClient.get_wasm_plugin", + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.list_agent_gateways", "method": { - "fullName": "google.cloud.networkservices.v1.NetworkServices.GetWasmPlugin", + "fullName": "google.cloud.networkservices.v1.NetworkServices.ListAgentGateways", "service": { "fullName": "google.cloud.networkservices.v1.NetworkServices", "shortName": "NetworkServices" }, - "shortName": "GetWasmPlugin" + "shortName": "ListAgentGateways" }, "parameters": [ { "name": "request", - "type": "google.cloud.network_services_v1.types.GetWasmPluginRequest" + "type": "google.cloud.network_services_v1.types.ListAgentGatewaysRequest" }, { - "name": "name", + "name": "parent", "type": "str" }, { @@ -9096,22 +9756,22 @@ "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], - "resultType": "google.cloud.network_services_v1.types.WasmPlugin", - "shortName": "get_wasm_plugin" + "resultType": "google.cloud.network_services_v1.services.network_services.pagers.ListAgentGatewaysPager", + "shortName": "list_agent_gateways" }, - "description": "Sample for GetWasmPlugin", - "file": "networkservices_v1_generated_network_services_get_wasm_plugin_sync.py", + "description": "Sample for ListAgentGateways", + "file": "networkservices_v1_generated_network_services_list_agent_gateways_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "networkservices_v1_generated_NetworkServices_GetWasmPlugin_sync", + "regionTag": "networkservices_v1_generated_NetworkServices_ListAgentGateways_sync", "segments": [ { - "end": 51, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 52, "start": 27, "type": "SHORT" }, @@ -9131,12 +9791,12 @@ "type": "REQUEST_EXECUTION" }, { - "end": 52, + "end": 53, "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "networkservices_v1_generated_network_services_get_wasm_plugin_sync.py" + "title": "networkservices_v1_generated_network_services_list_agent_gateways_sync.py" }, { "canonical": true, @@ -11231,6 +11891,175 @@ ], "title": "networkservices_v1_generated_network_services_list_wasm_plugins_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient", + "shortName": "NetworkServicesAsyncClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesAsyncClient.update_agent_gateway", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.UpdateAgentGateway", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "UpdateAgentGateway" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.UpdateAgentGatewayRequest" + }, + { + "name": "agent_gateway", + "type": "google.cloud.network_services_v1.types.AgentGateway" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_agent_gateway" + }, + "description": "Sample for UpdateAgentGateway", + "file": "networkservices_v1_generated_network_services_update_agent_gateway_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_UpdateAgentGateway_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_update_agent_gateway_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.network_services_v1.NetworkServicesClient", + "shortName": "NetworkServicesClient" + }, + "fullName": "google.cloud.network_services_v1.NetworkServicesClient.update_agent_gateway", + "method": { + "fullName": "google.cloud.networkservices.v1.NetworkServices.UpdateAgentGateway", + "service": { + "fullName": "google.cloud.networkservices.v1.NetworkServices", + "shortName": "NetworkServices" + }, + "shortName": "UpdateAgentGateway" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.network_services_v1.types.UpdateAgentGatewayRequest" + }, + { + "name": "agent_gateway", + "type": "google.cloud.network_services_v1.types.AgentGateway" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_agent_gateway" + }, + "description": "Sample for UpdateAgentGateway", + "file": "networkservices_v1_generated_network_services_update_agent_gateway_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "networkservices_v1_generated_NetworkServices_UpdateAgentGateway_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "networkservices_v1_generated_network_services_update_agent_gateway_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/packages/google-cloud-network-services/tests/unit/gapic/network_services_v1/test_dep_service.py b/packages/google-cloud-network-services/tests/unit/gapic/network_services_v1/test_dep_service.py index 662b5f55a83a..9d362799288a 100644 --- a/packages/google-cloud-network-services/tests/unit/gapic/network_services_v1/test_dep_service.py +++ b/packages/google-cloud-network-services/tests/unit/gapic/network_services_v1/test_dep_service.py @@ -7835,6 +7835,7 @@ def test_get_authz_extension(request_type, transport: str = "grpc"): service="service_value", fail_open=True, forward_headers=["forward_headers_value"], + forward_attributes=["forward_attributes_value"], wire_format=dep.WireFormat.EXT_PROC_GRPC, ) response = client.get_authz_extension(request) @@ -7854,6 +7855,7 @@ def test_get_authz_extension(request_type, transport: str = "grpc"): assert response.service == "service_value" assert response.fail_open is True assert response.forward_headers == ["forward_headers_value"] + assert response.forward_attributes == ["forward_attributes_value"] assert response.wire_format == dep.WireFormat.EXT_PROC_GRPC @@ -8001,6 +8003,7 @@ async def test_get_authz_extension_async(request_type, transport: str = "grpc_as service="service_value", fail_open=True, forward_headers=["forward_headers_value"], + forward_attributes=["forward_attributes_value"], wire_format=dep.WireFormat.EXT_PROC_GRPC, ) ) @@ -8021,6 +8024,7 @@ async def test_get_authz_extension_async(request_type, transport: str = "grpc_as assert response.service == "service_value" assert response.fail_open is True assert response.forward_headers == ["forward_headers_value"] + assert response.forward_attributes == ["forward_attributes_value"] assert response.wire_format == dep.WireFormat.EXT_PROC_GRPC @@ -14501,6 +14505,7 @@ async def test_get_authz_extension_empty_call_grpc_asyncio(): service="service_value", fail_open=True, forward_headers=["forward_headers_value"], + forward_attributes=["forward_attributes_value"], wire_format=dep.WireFormat.EXT_PROC_GRPC, ) ) @@ -14940,7 +14945,14 @@ def test_create_lb_traffic_extension_rest_call_success(request_type): "forward_headers_value1", "forward_headers_value2", ], + "forward_attributes": [ + "forward_attributes_value1", + "forward_attributes_value2", + ], "metadata": {"fields": {}}, + "request_body_send_mode": 1, + "response_body_send_mode": 1, + "observability_mode": True, } ], } @@ -15174,7 +15186,14 @@ def test_update_lb_traffic_extension_rest_call_success(request_type): "forward_headers_value1", "forward_headers_value2", ], + "forward_attributes": [ + "forward_attributes_value1", + "forward_attributes_value2", + ], "metadata": {"fields": {}}, + "request_body_send_mode": 1, + "response_body_send_mode": 1, + "observability_mode": True, } ], } @@ -15804,7 +15823,14 @@ def test_create_lb_route_extension_rest_call_success(request_type): "forward_headers_value1", "forward_headers_value2", ], + "forward_attributes": [ + "forward_attributes_value1", + "forward_attributes_value2", + ], "metadata": {"fields": {}}, + "request_body_send_mode": 1, + "response_body_send_mode": 1, + "observability_mode": True, } ], } @@ -16036,7 +16062,14 @@ def test_update_lb_route_extension_rest_call_success(request_type): "forward_headers_value1", "forward_headers_value2", ], + "forward_attributes": [ + "forward_attributes_value1", + "forward_attributes_value2", + ], "metadata": {"fields": {}}, + "request_body_send_mode": 1, + "response_body_send_mode": 1, + "observability_mode": True, } ], } @@ -16664,7 +16697,14 @@ def test_create_lb_edge_extension_rest_call_success(request_type): "forward_headers_value1", "forward_headers_value2", ], + "forward_attributes": [ + "forward_attributes_value1", + "forward_attributes_value2", + ], "metadata": {"fields": {}}, + "request_body_send_mode": 1, + "response_body_send_mode": 1, + "observability_mode": True, } ], } @@ -16895,7 +16935,14 @@ def test_update_lb_edge_extension_rest_call_success(request_type): "forward_headers_value1", "forward_headers_value2", ], + "forward_attributes": [ + "forward_attributes_value1", + "forward_attributes_value2", + ], "metadata": {"fields": {}}, + "request_body_send_mode": 1, + "response_body_send_mode": 1, + "observability_mode": True, } ], } @@ -17375,6 +17422,7 @@ def test_get_authz_extension_rest_call_success(request_type): service="service_value", fail_open=True, forward_headers=["forward_headers_value"], + forward_attributes=["forward_attributes_value"], wire_format=dep.WireFormat.EXT_PROC_GRPC, ) @@ -17399,6 +17447,7 @@ def test_get_authz_extension_rest_call_success(request_type): assert response.service == "service_value" assert response.fail_open is True assert response.forward_headers == ["forward_headers_value"] + assert response.forward_attributes == ["forward_attributes_value"] assert response.wire_format == dep.WireFormat.EXT_PROC_GRPC @@ -17518,6 +17567,10 @@ def test_create_authz_extension_rest_call_success(request_type): "fail_open": True, "metadata": {"fields": {}}, "forward_headers": ["forward_headers_value1", "forward_headers_value2"], + "forward_attributes": [ + "forward_attributes_value1", + "forward_attributes_value2", + ], "wire_format": 1, } # The version of a generated dependency at test runtime may differ from the version used during generation. @@ -17734,6 +17787,10 @@ def test_update_authz_extension_rest_call_success(request_type): "fail_open": True, "metadata": {"fields": {}}, "forward_headers": ["forward_headers_value1", "forward_headers_value2"], + "forward_attributes": [ + "forward_attributes_value1", + "forward_attributes_value2", + ], "wire_format": 1, } # The version of a generated dependency at test runtime may differ from the version used during generation. diff --git a/packages/google-cloud-network-services/tests/unit/gapic/network_services_v1/test_network_services.py b/packages/google-cloud-network-services/tests/unit/gapic/network_services_v1/test_network_services.py index 6847a6781589..e4538e8eb636 100644 --- a/packages/google-cloud-network-services/tests/unit/gapic/network_services_v1/test_network_services.py +++ b/packages/google-cloud-network-services/tests/unit/gapic/network_services_v1/test_network_services.py @@ -74,6 +74,7 @@ transports, ) from google.cloud.network_services_v1.types import ( + agent_gateway, common, endpoint_policy, extensibility, @@ -87,6 +88,7 @@ tcp_route, tls_route, ) +from google.cloud.network_services_v1.types import agent_gateway as gcn_agent_gateway from google.cloud.network_services_v1.types import ( endpoint_policy as gcn_endpoint_policy, ) @@ -7516,6 +7518,7 @@ def test_get_gateway(request_type, transport: str = "grpc"): type_=gateway.Gateway.Type.OPEN_MESH, addresses=["addresses_value"], ports=[568], + all_ports=True, scope="scope_value", server_tls_policy="server_tls_policy_value", certificate_urls=["certificate_urls_value"], @@ -7525,6 +7528,7 @@ def test_get_gateway(request_type, transport: str = "grpc"): ip_version=gateway.Gateway.IpVersion.IPV4, envoy_headers=common.EnvoyHeaders.NONE, routing_mode=gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE, + allow_global_access=True, ) response = client.get_gateway(request) @@ -7542,6 +7546,7 @@ def test_get_gateway(request_type, transport: str = "grpc"): assert response.type_ == gateway.Gateway.Type.OPEN_MESH assert response.addresses == ["addresses_value"] assert response.ports == [568] + assert response.all_ports is True assert response.scope == "scope_value" assert response.server_tls_policy == "server_tls_policy_value" assert response.certificate_urls == ["certificate_urls_value"] @@ -7551,6 +7556,7 @@ def test_get_gateway(request_type, transport: str = "grpc"): assert response.ip_version == gateway.Gateway.IpVersion.IPV4 assert response.envoy_headers == common.EnvoyHeaders.NONE assert response.routing_mode == gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE + assert response.allow_global_access is True def test_get_gateway_non_empty_request_with_auto_populated_field(): @@ -7688,6 +7694,7 @@ async def test_get_gateway_async(request_type, transport: str = "grpc_asyncio"): type_=gateway.Gateway.Type.OPEN_MESH, addresses=["addresses_value"], ports=[568], + all_ports=True, scope="scope_value", server_tls_policy="server_tls_policy_value", certificate_urls=["certificate_urls_value"], @@ -7697,6 +7704,7 @@ async def test_get_gateway_async(request_type, transport: str = "grpc_asyncio"): ip_version=gateway.Gateway.IpVersion.IPV4, envoy_headers=common.EnvoyHeaders.NONE, routing_mode=gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE, + allow_global_access=True, ) ) response = await client.get_gateway(request) @@ -7715,6 +7723,7 @@ async def test_get_gateway_async(request_type, transport: str = "grpc_asyncio"): assert response.type_ == gateway.Gateway.Type.OPEN_MESH assert response.addresses == ["addresses_value"] assert response.ports == [568] + assert response.all_ports is True assert response.scope == "scope_value" assert response.server_tls_policy == "server_tls_policy_value" assert response.certificate_urls == ["certificate_urls_value"] @@ -7724,6 +7733,7 @@ async def test_get_gateway_async(request_type, transport: str = "grpc_asyncio"): assert response.ip_version == gateway.Gateway.IpVersion.IPV4 assert response.envoy_headers == common.EnvoyHeaders.NONE assert response.routing_mode == gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE + assert response.allow_global_access is True def test_get_gateway_field_headers(): @@ -10855,6 +10865,7 @@ def test_list_http_routes_non_empty_request_with_auto_populated_field(): request = http_route.ListHttpRoutesRequest( parent="parent_value", page_token="page_token_value", + filter="filter_value", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10868,6 +10879,7 @@ def test_list_http_routes_non_empty_request_with_auto_populated_field(): request_msg = http_route.ListHttpRoutesRequest( parent="parent_value", page_token="page_token_value", + filter="filter_value", ) assert args[0] == request_msg @@ -15149,6 +15161,7 @@ def test_get_tls_route(request_type, transport: str = "grpc"): description="description_value", meshes=["meshes_value"], gateways=["gateways_value"], + target_proxies=["target_proxies_value"], ) response = client.get_tls_route(request) @@ -15165,6 +15178,7 @@ def test_get_tls_route(request_type, transport: str = "grpc"): assert response.description == "description_value" assert response.meshes == ["meshes_value"] assert response.gateways == ["gateways_value"] + assert response.target_proxies == ["target_proxies_value"] def test_get_tls_route_non_empty_request_with_auto_populated_field(): @@ -15301,6 +15315,7 @@ async def test_get_tls_route_async(request_type, transport: str = "grpc_asyncio" description="description_value", meshes=["meshes_value"], gateways=["gateways_value"], + target_proxies=["target_proxies_value"], ) ) response = await client.get_tls_route(request) @@ -15318,6 +15333,7 @@ async def test_get_tls_route_async(request_type, transport: str = "grpc_asyncio" assert response.description == "description_value" assert response.meshes == ["meshes_value"] assert response.gateways == ["gateways_value"] + assert response.target_proxies == ["target_proxies_value"] def test_get_tls_route_field_headers(): @@ -24125,13 +24141,86 @@ async def test_list_mesh_route_views_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_endpoint_policies_rest_use_cached_wrapped_rpc(): +@pytest.mark.parametrize( + "request_type", + [ + agent_gateway.ListAgentGatewaysRequest(), + {}, + ], +) +def test_list_agent_gateways(request_type, transport: str = "grpc"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = agent_gateway.ListAgentGatewaysResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + response = client.list_agent_gateways(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = agent_gateway.ListAgentGatewaysRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAgentGatewaysPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +def test_list_agent_gateways_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = agent_gateway.ListAgentGatewaysRequest( + parent="parent_value", + page_token="page_token_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.list_agent_gateways(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.ListAgentGatewaysRequest( + parent="parent_value", + page_token="page_token_value", + ) + assert args[0] == request_msg + + +def test_list_agent_gateways_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport="grpc", ) # Should wrap all calls on client creation @@ -24140,8 +24229,7 @@ def test_list_endpoint_policies_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.list_endpoint_policies - in client._transport._wrapped_methods + client._transport.list_agent_gateways in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -24149,436 +24237,540 @@ def test_list_endpoint_policies_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_endpoint_policies] = ( + client._transport._wrapped_methods[client._transport.list_agent_gateways] = ( mock_rpc ) - request = {} - client.list_endpoint_policies(request) + client.list_agent_gateways(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_endpoint_policies(request) + client.list_agent_gateways(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_endpoint_policies_rest_required_fields( - request_type=endpoint_policy.ListEndpointPoliciesRequest, +@pytest.mark.asyncio +async def test_list_agent_gateways_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", ): - transport_class = transports.NetworkServicesRestTransport + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson(pb_request, use_integers_for_enums=False) - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # verify fields with default values are dropped + # Ensure method has been cached + assert ( + client._client._transport.list_agent_gateways + in client._client._transport._wrapped_methods + ) - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).list_endpoint_policies._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.list_agent_gateways + ] = mock_rpc - # verify required fields with default values are now present + request = {} + await client.list_agent_gateways(request) - jsonified_request["parent"] = "parent_value" + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).list_endpoint_policies._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - "return_partial_success", - ) + await client.list_agent_gateways(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "request_type", + [ + agent_gateway.ListAgentGatewaysRequest(), + {}, + ], +) +async def test_list_agent_gateways_async(request_type, transport: str = "grpc_asyncio"): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, ) - jsonified_request.update(unset_fields) - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + agent_gateway.ListAgentGatewaysResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + response = await client.list_agent_gateways(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = agent_gateway.ListAgentGatewaysRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAgentGatewaysAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + +def test_list_agent_gateways_field_headers(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = endpoint_policy.ListEndpointPoliciesResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "get", - "query_params": pb_request, - } - transcode.return_value = transcode_result - response_value = Response() - response_value.status_code = 200 + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = agent_gateway.ListAgentGatewaysRequest() - # Convert return value to protobuf type - return_value = endpoint_policy.ListEndpointPoliciesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) + request.parent = "parent_value" - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + call.return_value = agent_gateway.ListAgentGatewaysResponse() + client.list_agent_gateways(request) - response = client.list_endpoint_policies(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 - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert sorted(expected_params) == sorted(actual_params) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_list_endpoint_policies_rest_unset_required_fields(): - transport = transports.NetworkServicesRestTransport( - credentials=ga_credentials.AnonymousCredentials +@pytest.mark.asyncio +async def test_list_agent_gateways_field_headers_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), ) - unset_fields = transport.list_endpoint_policies._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - "returnPartialSuccess", - ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = agent_gateway.ListAgentGatewaysRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + agent_gateway.ListAgentGatewaysResponse() ) - & set(("parent",)) - ) + await client.list_agent_gateways(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", + "parent=parent_value", + ) in kw["metadata"] -def test_list_endpoint_policies_rest_flattened(): +def test_list_agent_gateways_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = endpoint_policy.ListEndpointPoliciesResponse() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = agent_gateway.ListAgentGatewaysResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_agent_gateways( + parent="parent_value", + ) - # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val - # get truthy value for each flattened field - mock_args = dict( + +def test_list_agent_gateways_flattened_error(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_agent_gateways( + agent_gateway.ListAgentGatewaysRequest(), parent="parent_value", ) - mock_args.update(sample_request) - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - # Convert return value to protobuf type - return_value = endpoint_policy.ListEndpointPoliciesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_endpoint_policies(**mock_args) +@pytest.mark.asyncio +async def test_list_agent_gateways_flattened_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = agent_gateway.ListAgentGatewaysResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + agent_gateway.ListAgentGatewaysResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_agent_gateways( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/endpointPolicies" - % client.transport._host, - args[1], - ) + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val -def test_list_endpoint_policies_rest_flattened_error(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, +@pytest.mark.asyncio +async def test_list_agent_gateways_flattened_error_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_endpoint_policies( - endpoint_policy.ListEndpointPoliciesRequest(), + await client.list_agent_gateways( + agent_gateway.ListAgentGatewaysRequest(), parent="parent_value", ) -def test_list_endpoint_policies_rest_pager(transport: str = "rest"): +def test_list_agent_gateways_pager(transport_name: str = "grpc"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + transport=transport_name, ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - endpoint_policy.ListEndpointPoliciesResponse( - endpoint_policies=[ - endpoint_policy.EndpointPolicy(), - endpoint_policy.EndpointPolicy(), - endpoint_policy.EndpointPolicy(), + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), ], next_page_token="abc", ), - endpoint_policy.ListEndpointPoliciesResponse( - endpoint_policies=[], + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[], next_page_token="def", ), - endpoint_policy.ListEndpointPoliciesResponse( - endpoint_policies=[ - endpoint_policy.EndpointPolicy(), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), ], next_page_token="ghi", ), - endpoint_policy.ListEndpointPoliciesResponse( - endpoint_policies=[ - endpoint_policy.EndpointPolicy(), - endpoint_policy.EndpointPolicy(), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), ], ), + RuntimeError, ) - # Two responses for two calls - response = response + response - # Wrap the values into proper Response objs - response = tuple( - endpoint_policy.ListEndpointPoliciesResponse.to_json(x) for x in response + expected_metadata = () + retry = retries.Retry() + timeout = 5 + expected_metadata = tuple(expected_metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} + pager = client.list_agent_gateways(request={}, retry=retry, timeout=timeout) - pager = client.list_endpoint_policies(request=sample_request) + assert pager._metadata == expected_metadata + assert pager._retry == retry + assert pager._timeout == timeout results = list(pager) assert len(results) == 6 - assert all(isinstance(i, endpoint_policy.EndpointPolicy) for i in results) + assert all(isinstance(i, agent_gateway.AgentGateway) for i in results) - pages = list(client.list_endpoint_policies(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token +def test_list_agent_gateways_pages(transport_name: str = "grpc"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) -def test_get_endpoint_policy_rest_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + ], + next_page_token="abc", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[], + next_page_token="def", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + ], + next_page_token="ghi", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + ], + ), + RuntimeError, ) + pages = list(client.list_agent_gateways(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - # Ensure method has been cached - assert ( - client._transport.get_endpoint_policy in client._transport._wrapped_methods - ) +@pytest.mark.asyncio +async def test_list_agent_gateways_async_pager(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + ], + next_page_token="abc", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[], + next_page_token="def", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + ], + next_page_token="ghi", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + ], + ), + RuntimeError, ) - client._transport._wrapped_methods[client._transport.get_endpoint_policy] = ( - mock_rpc + async_pager = await client.list_agent_gateways( + request={}, ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) - request = {} - client.get_endpoint_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 + assert len(responses) == 6 + assert all(isinstance(i, agent_gateway.AgentGateway) for i in responses) - client.get_endpoint_policy(request) - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 +@pytest.mark.asyncio +async def test_list_agent_gateways_async_pages(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + ], + next_page_token="abc", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[], + next_page_token="def", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + ], + next_page_token="ghi", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_agent_gateways(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_get_endpoint_policy_rest_required_fields( - request_type=endpoint_policy.GetEndpointPolicyRequest, -): - transport_class = transports.NetworkServicesRestTransport - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson(pb_request, use_integers_for_enums=False) +@pytest.mark.parametrize( + "request_type", + [ + agent_gateway.GetAgentGatewayRequest(), + {}, + ], +) +def test_get_agent_gateway(request_type, transport: str = "grpc"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # verify fields with default values are dropped - - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).get_endpoint_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type - # verify required fields with default values are now present + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = agent_gateway.AgentGateway( + name="name_value", + description="description_value", + etag="etag_value", + protocols=[agent_gateway.AgentGateway.Protocol.MCP], + registries=["registries_value"], + ) + response = client.get_agent_gateway(request) - jsonified_request["name"] = "name_value" + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = agent_gateway.GetAgentGatewayRequest() + assert args[0] == request - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).get_endpoint_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Establish that the response is the type that we expect. + assert isinstance(response, agent_gateway.AgentGateway) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.protocols == [agent_gateway.AgentGateway.Protocol.MCP] + assert response.registries == ["registries_value"] - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" +def test_get_agent_gateway_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = endpoint_policy.EndpointPolicy() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "get", - "query_params": pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = endpoint_policy.EndpointPolicy.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - response = client.get_endpoint_policy(request) - - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert sorted(expected_params) == sorted(actual_params) - - -def test_get_endpoint_policy_rest_unset_required_fields(): - transport = transports.NetworkServicesRestTransport( - credentials=ga_credentials.AnonymousCredentials + transport="grpc", ) - unset_fields = transport.get_endpoint_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) - - -def test_get_endpoint_policy_rest_flattened(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = agent_gateway.GetAgentGatewayRequest( + name="name_value", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = endpoint_policy.EndpointPolicy() - - # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" - } - - # get truthy value for each flattened field - mock_args = dict( - name="name_value", - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - # Convert return value to protobuf type - return_value = endpoint_policy.EndpointPolicy.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - client.get_endpoint_policy(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/endpointPolicies/*}" - % client.transport._host, - args[1], + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. ) - - -def test_get_endpoint_policy_rest_flattened_error(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_endpoint_policy( - endpoint_policy.GetEndpointPolicyRequest(), + client.get_agent_gateway(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.GetAgentGatewayRequest( name="name_value", ) + assert args[0] == request_msg -def test_create_endpoint_policy_rest_use_cached_wrapped_rpc(): +def test_get_agent_gateway_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport="grpc", ) # Should wrap all calls on client creation @@ -24586,210 +24778,346 @@ def test_create_endpoint_policy_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.create_endpoint_policy - in client._transport._wrapped_methods - ) + assert client._transport.get_agent_gateway in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_endpoint_policy] = ( + client._transport._wrapped_methods[client._transport.get_agent_gateway] = ( mock_rpc ) - request = {} - client.create_endpoint_policy(request) + client.get_agent_gateway(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_endpoint_policy(request) + client.get_agent_gateway(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_endpoint_policy_rest_required_fields( - request_type=gcn_endpoint_policy.CreateEndpointPolicyRequest, +@pytest.mark.asyncio +async def test_get_agent_gateway_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", ): - transport_class = transports.NetworkServicesRestTransport + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) - request_init = {} - request_init["parent"] = "" - request_init["endpoint_policy_id"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson(pb_request, use_integers_for_enums=False) - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # verify fields with default values are dropped - assert "endpointPolicyId" not in jsonified_request + # Ensure method has been cached + assert ( + client._client._transport.get_agent_gateway + in client._client._transport._wrapped_methods + ) - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).create_endpoint_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.get_agent_gateway + ] = mock_rpc - # verify required fields with default values are now present - assert "endpointPolicyId" in jsonified_request - assert jsonified_request["endpointPolicyId"] == request_init["endpoint_policy_id"] + request = {} + await client.get_agent_gateway(request) - jsonified_request["parent"] = "parent_value" - jsonified_request["endpointPolicyId"] = "endpoint_policy_id_value" + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).create_endpoint_policy._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("endpoint_policy_id",)) - jsonified_request.update(unset_fields) + await client.get_agent_gateway(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "request_type", + [ + agent_gateway.GetAgentGatewayRequest(), + {}, + ], +) +async def test_get_agent_gateway_async(request_type, transport: str = "grpc_asyncio"): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + agent_gateway.AgentGateway( + name="name_value", + description="description_value", + etag="etag_value", + protocols=[agent_gateway.AgentGateway.Protocol.MCP], + registries=["registries_value"], + ) + ) + response = await client.get_agent_gateway(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = agent_gateway.GetAgentGatewayRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, agent_gateway.AgentGateway) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.protocols == [agent_gateway.AgentGateway.Protocol.MCP] + assert response.registries == ["registries_value"] - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" - assert "endpointPolicyId" in jsonified_request - assert jsonified_request["endpointPolicyId"] == "endpoint_policy_id_value" +def test_get_agent_gateway_field_headers(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - request = request_type(**request_init) - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "post", - "query_params": pb_request, - } - transcode_result["body"] = pb_request - transcode.return_value = transcode_result + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = agent_gateway.GetAgentGatewayRequest() - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) + request.name = "name_value" - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + call.return_value = agent_gateway.AgentGateway() + client.get_agent_gateway(request) - response = client.create_endpoint_policy(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 - expected_params = [ - ( - "endpointPolicyId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] - actual_params = req.call_args.kwargs["params"] - assert sorted(expected_params) == sorted(actual_params) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_create_endpoint_policy_rest_unset_required_fields(): - transport = transports.NetworkServicesRestTransport( - credentials=ga_credentials.AnonymousCredentials +@pytest.mark.asyncio +async def test_get_agent_gateway_field_headers_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), ) - unset_fields = transport.create_endpoint_policy._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(("endpointPolicyId",)) - & set( - ( - "parent", - "endpointPolicyId", - "endpointPolicy", - ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = agent_gateway.GetAgentGatewayRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + agent_gateway.AgentGateway() ) - ) + await client.get_agent_gateway(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", + "name=name_value", + ) in kw["metadata"] -def test_create_endpoint_policy_rest_flattened(): +def test_get_agent_gateway_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = agent_gateway.AgentGateway() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_agent_gateway( + name="name_value", + ) - # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val - # get truthy value for each flattened field - mock_args = dict( - parent="parent_value", - endpoint_policy=gcn_endpoint_policy.EndpointPolicy(name="name_value"), - endpoint_policy_id="endpoint_policy_id_value", + +def test_get_agent_gateway_flattened_error(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_agent_gateway( + agent_gateway.GetAgentGatewayRequest(), + name="name_value", ) - mock_args.update(sample_request) - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_endpoint_policy(**mock_args) +@pytest.mark.asyncio +async def test_get_agent_gateway_flattened_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = agent_gateway.AgentGateway() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + agent_gateway.AgentGateway() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_agent_gateway( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/endpointPolicies" - % client.transport._host, - args[1], + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_agent_gateway_flattened_error_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_agent_gateway( + agent_gateway.GetAgentGatewayRequest(), + name="name_value", ) -def test_create_endpoint_policy_rest_flattened_error(transport: str = "rest"): +@pytest.mark.parametrize( + "request_type", + [ + gcn_agent_gateway.CreateAgentGatewayRequest(), + {}, + ], +) +def test_create_agent_gateway(request_type, transport: str = "grpc"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_endpoint_policy( - gcn_endpoint_policy.CreateEndpointPolicyRequest(), + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_agent_gateway(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = gcn_agent_gateway.CreateAgentGatewayRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_agent_gateway_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = gcn_agent_gateway.CreateAgentGatewayRequest( + parent="parent_value", + agent_gateway_id="agent_gateway_id_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.create_agent_gateway(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_agent_gateway.CreateAgentGatewayRequest( parent="parent_value", - endpoint_policy=gcn_endpoint_policy.EndpointPolicy(name="name_value"), - endpoint_policy_id="endpoint_policy_id_value", + agent_gateway_id="agent_gateway_id_value", ) + assert args[0] == request_msg -def test_update_endpoint_policy_rest_use_cached_wrapped_rpc(): +def test_create_agent_gateway_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport="grpc", ) # Should wrap all calls on client creation @@ -24798,8 +25126,7 @@ def test_update_endpoint_policy_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.update_endpoint_policy - in client._transport._wrapped_methods + client._transport.create_agent_gateway in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -24807,359 +25134,378 @@ def test_update_endpoint_policy_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_endpoint_policy] = ( + client._transport._wrapped_methods[client._transport.create_agent_gateway] = ( mock_rpc ) - request = {} - client.update_endpoint_policy(request) + client.create_agent_gateway(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.update_endpoint_policy(request) + client.create_agent_gateway(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_endpoint_policy_rest_required_fields( - request_type=gcn_endpoint_policy.UpdateEndpointPolicyRequest, +@pytest.mark.asyncio +async def test_create_agent_gateway_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", ): - transport_class = transports.NetworkServicesRestTransport + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) - request_init = {} - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson(pb_request, use_integers_for_enums=False) - ) - - # verify fields with default values are dropped + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).update_endpoint_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Ensure method has been cached + assert ( + client._client._transport.create_agent_gateway + in client._client._transport._wrapped_methods + ) - # verify required fields with default values are now present + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.create_agent_gateway + ] = mock_rpc - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).update_endpoint_policy._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) - jsonified_request.update(unset_fields) + request = {} + await client.create_agent_gateway(request) - # verify required fields with non-default values are left alone + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - request = request_type(**request_init) + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "patch", - "query_params": pb_request, - } - transcode_result["body"] = pb_request - transcode.return_value = transcode_result + await client.create_agent_gateway(request) - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_endpoint_policy(request) +@pytest.mark.asyncio +@pytest.mark.parametrize( + "request_type", + [ + gcn_agent_gateway.CreateAgentGatewayRequest(), + {}, + ], +) +async def test_create_agent_gateway_async( + request_type, transport: str = "grpc_asyncio" +): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert sorted(expected_params) == sorted(actual_params) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.create_agent_gateway(request) -def test_update_endpoint_policy_rest_unset_required_fields(): - transport = transports.NetworkServicesRestTransport( - credentials=ga_credentials.AnonymousCredentials - ) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = gcn_agent_gateway.CreateAgentGatewayRequest() + assert args[0] == request - unset_fields = transport.update_endpoint_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("endpointPolicy",))) + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) -def test_update_endpoint_policy_rest_flattened(): +def test_create_agent_gateway_field_headers(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") - - # get arguments that satisfy an http rule for this method - sample_request = { - "endpoint_policy": { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" - } - } + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = gcn_agent_gateway.CreateAgentGatewayRequest() - # get truthy value for each flattened field - mock_args = dict( - endpoint_policy=gcn_endpoint_policy.EndpointPolicy(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), - ) - mock_args.update(sample_request) + request.parent = "parent_value" - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_agent_gateway(request) - client.update_endpoint_policy(**mock_args) + # 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 underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{endpoint_policy.name=projects/*/locations/*/endpointPolicies/*}" - % client.transport._host, - args[1], - ) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_update_endpoint_policy_rest_flattened_error(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, +@pytest.mark.asyncio +async def test_create_agent_gateway_field_headers_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), ) - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_endpoint_policy( - gcn_endpoint_policy.UpdateEndpointPolicyRequest(), - endpoint_policy=gcn_endpoint_policy.EndpointPolicy(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), - ) - - -def test_delete_endpoint_policy_rest_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = gcn_agent_gateway.CreateAgentGatewayRequest() - # Ensure method has been cached - assert ( - client._transport.delete_endpoint_policy - in client._transport._wrapped_methods - ) + request.parent = "parent_value" - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. - ) - client._transport._wrapped_methods[client._transport.delete_endpoint_policy] = ( - mock_rpc + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") ) - - request = {} - client.delete_endpoint_policy(request) + await client.create_agent_gateway(request) # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.delete_endpoint_policy(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 + 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", + "parent=parent_value", + ) in kw["metadata"] -def test_delete_endpoint_policy_rest_required_fields( - request_type=endpoint_policy.DeleteEndpointPolicyRequest, -): - transport_class = transports.NetworkServicesRestTransport - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson(pb_request, use_integers_for_enums=False) +def test_create_agent_gateway_flattened(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), ) - # verify fields with default values are dropped - - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).delete_endpoint_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = "name_value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_agent_gateway( + parent="parent_value", + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + agent_gateway_id="agent_gateway_id_value", + ) - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).delete_endpoint_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].agent_gateway + mock_val = gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ) + assert arg == mock_val + arg = args[0].agent_gateway_id + mock_val = "agent_gateway_id_value" + assert arg == mock_val - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" +def test_create_agent_gateway_flattened_error(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - request = request_type(**request_init) - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "delete", - "query_params": pb_request, - } - transcode.return_value = transcode_result + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_agent_gateway( + gcn_agent_gateway.CreateAgentGatewayRequest(), + parent="parent_value", + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + agent_gateway_id="agent_gateway_id_value", + ) - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} +@pytest.mark.asyncio +async def test_create_agent_gateway_flattened_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) - response = client.delete_endpoint_policy(request) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert sorted(expected_params) == sorted(actual_params) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_agent_gateway( + parent="parent_value", + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + agent_gateway_id="agent_gateway_id_value", + ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].agent_gateway + mock_val = gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ) + assert arg == mock_val + arg = args[0].agent_gateway_id + mock_val = "agent_gateway_id_value" + assert arg == mock_val -def test_delete_endpoint_policy_rest_unset_required_fields(): - transport = transports.NetworkServicesRestTransport( - credentials=ga_credentials.AnonymousCredentials + +@pytest.mark.asyncio +async def test_create_agent_gateway_flattened_error_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), ) - unset_fields = transport.delete_endpoint_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_agent_gateway( + gcn_agent_gateway.CreateAgentGatewayRequest(), + parent="parent_value", + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + agent_gateway_id="agent_gateway_id_value", + ) -def test_delete_endpoint_policy_rest_flattened(): +@pytest.mark.parametrize( + "request_type", + [ + gcn_agent_gateway.UpdateAgentGatewayRequest(), + {}, + ], +) +def test_update_agent_gateway(request_type, transport: str = "grpc"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport=transport, ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") - - # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" - } - - # get truthy value for each flattened field - mock_args = dict( - name="name_value", - ) - mock_args.update(sample_request) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_agent_gateway(request) - client.delete_endpoint_policy(**mock_args) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = gcn_agent_gateway.UpdateAgentGatewayRequest() + assert args[0] == request - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/endpointPolicies/*}" - % client.transport._host, - args[1], - ) + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) -def test_delete_endpoint_policy_rest_flattened_error(transport: str = "rest"): +def test_update_agent_gateway_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + transport="grpc", ) - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_endpoint_policy( - endpoint_policy.DeleteEndpointPolicyRequest(), - name="name_value", + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = gcn_agent_gateway.UpdateAgentGatewayRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. ) + client.update_agent_gateway(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_agent_gateway.UpdateAgentGatewayRequest() + assert args[0] == request_msg -def test_list_wasm_plugin_versions_rest_use_cached_wrapped_rpc(): +def test_update_agent_gateway_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport="grpc", ) # Should wrap all calls on client creation @@ -25168,8 +25514,7 @@ def test_list_wasm_plugin_versions_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.list_wasm_plugin_versions - in client._transport._wrapped_methods + client._transport.update_agent_gateway in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -25177,254 +25522,374 @@ def test_list_wasm_plugin_versions_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_wasm_plugin_versions - ] = mock_rpc - + client._transport._wrapped_methods[client._transport.update_agent_gateway] = ( + mock_rpc + ) request = {} - client.list_wasm_plugin_versions(request) + client.update_agent_gateway(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_wasm_plugin_versions(request) + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_agent_gateway(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_wasm_plugin_versions_rest_required_fields( - request_type=extensibility.ListWasmPluginVersionsRequest, +@pytest.mark.asyncio +async def test_update_agent_gateway_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", ): - transport_class = transports.NetworkServicesRestTransport + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson(pb_request, use_integers_for_enums=False) - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # verify fields with default values are dropped + # Ensure method has been cached + assert ( + client._client._transport.update_agent_gateway + in client._client._transport._wrapped_methods + ) - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).list_wasm_plugin_versions._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.update_agent_gateway + ] = mock_rpc - # verify required fields with default values are now present + request = {} + await client.update_agent_gateway(request) - jsonified_request["parent"] = "parent_value" + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).list_wasm_plugin_versions._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) - jsonified_request.update(unset_fields) + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.update_agent_gateway(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "request_type", + [ + gcn_agent_gateway.UpdateAgentGatewayRequest(), + {}, + ], +) +async def test_update_agent_gateway_async( + request_type, transport: str = "grpc_asyncio" +): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.update_agent_gateway(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = gcn_agent_gateway.UpdateAgentGatewayRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" +def test_update_agent_gateway_field_headers(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - request = request_type(**request_init) - # Designate an appropriate value for the returned response. - return_value = extensibility.ListWasmPluginVersionsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "get", - "query_params": pb_request, - } - transcode.return_value = transcode_result + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = gcn_agent_gateway.UpdateAgentGatewayRequest() - response_value = Response() - response_value.status_code = 200 + request.agent_gateway.name = "name_value" - # Convert return value to protobuf type - return_value = extensibility.ListWasmPluginVersionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_agent_gateway(request) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - response = client.list_wasm_plugin_versions(request) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "agent_gateway.name=name_value", + ) in kw["metadata"] - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert sorted(expected_params) == sorted(actual_params) +@pytest.mark.asyncio +async def test_update_agent_gateway_field_headers_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = gcn_agent_gateway.UpdateAgentGatewayRequest() -def test_list_wasm_plugin_versions_rest_unset_required_fields(): - transport = transports.NetworkServicesRestTransport( - credentials=ga_credentials.AnonymousCredentials + request.agent_gateway.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_agent_gateway(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", + "agent_gateway.name=name_value", + ) in kw["metadata"] + + +def test_update_agent_gateway_flattened(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), ) - unset_fields = transport.list_wasm_plugin_versions._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_agent_gateway( + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].agent_gateway + mock_val = gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE ) ) - & set(("parent",)) - ) + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val -def test_list_wasm_plugin_versions_rest_flattened(): +def test_update_agent_gateway_flattened_error(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = extensibility.ListWasmPluginVersionsResponse() + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_agent_gateway( + gcn_agent_gateway.UpdateAgentGatewayRequest(), + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) - # get arguments that satisfy an http rule for this method - sample_request = { - "parent": "projects/sample1/locations/sample2/wasmPlugins/sample3" - } - # get truthy value for each flattened field - mock_args = dict( - parent="parent_value", - ) - mock_args.update(sample_request) +@pytest.mark.asyncio +async def test_update_agent_gateway_flattened_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - # Convert return value to protobuf type - return_value = extensibility.ListWasmPluginVersionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") - client.list_wasm_plugin_versions(**mock_args) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_agent_gateway( + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) # Establish that the underlying call was made with the expected # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*/wasmPlugins/*}/versions" - % client.transport._host, - args[1], + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].agent_gateway + mock_val = gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) ) + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val -def test_list_wasm_plugin_versions_rest_flattened_error(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, +@pytest.mark.asyncio +async def test_update_agent_gateway_flattened_error_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_wasm_plugin_versions( - extensibility.ListWasmPluginVersionsRequest(), - parent="parent_value", + await client.update_agent_gateway( + gcn_agent_gateway.UpdateAgentGatewayRequest(), + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_list_wasm_plugin_versions_rest_pager(transport: str = "rest"): +@pytest.mark.parametrize( + "request_type", + [ + agent_gateway.DeleteAgentGatewayRequest(), + {}, + ], +) +def test_delete_agent_gateway(request_type, transport: str = "grpc"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - extensibility.ListWasmPluginVersionsResponse( - wasm_plugin_versions=[ - extensibility.WasmPluginVersion(), - extensibility.WasmPluginVersion(), - extensibility.WasmPluginVersion(), - ], - next_page_token="abc", - ), - extensibility.ListWasmPluginVersionsResponse( - wasm_plugin_versions=[], - next_page_token="def", - ), - extensibility.ListWasmPluginVersionsResponse( - wasm_plugin_versions=[ - extensibility.WasmPluginVersion(), - ], - next_page_token="ghi", - ), - extensibility.ListWasmPluginVersionsResponse( - wasm_plugin_versions=[ - extensibility.WasmPluginVersion(), - extensibility.WasmPluginVersion(), - ], - ), - ) - # Two responses for two calls - response = response + response + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type - # Wrap the values into proper Response objs - response = tuple( - extensibility.ListWasmPluginVersionsResponse.to_json(x) for x in response - ) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_agent_gateway(request) - sample_request = { - "parent": "projects/sample1/locations/sample2/wasmPlugins/sample3" - } + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = agent_gateway.DeleteAgentGatewayRequest() + assert args[0] == request - pager = client.list_wasm_plugin_versions(request=sample_request) + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, extensibility.WasmPluginVersion) for i in results) - pages = list(client.list_wasm_plugin_versions(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token +def test_delete_agent_gateway_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = agent_gateway.DeleteAgentGatewayRequest( + name="name_value", + etag="etag_value", + ) -def test_get_wasm_plugin_version_rest_use_cached_wrapped_rpc(): + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.delete_agent_gateway(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.DeleteAgentGatewayRequest( + name="name_value", + etag="etag_value", + ) + assert args[0] == request_msg + + +def test_delete_agent_gateway_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport="grpc", ) # Should wrap all calls on client creation @@ -25433,8 +25898,7 @@ def test_get_wasm_plugin_version_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.get_wasm_plugin_version - in client._transport._wrapped_methods + client._transport.delete_agent_gateway in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -25442,168 +25906,266 @@ def test_get_wasm_plugin_version_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.get_wasm_plugin_version - ] = mock_rpc - + client._transport._wrapped_methods[client._transport.delete_agent_gateway] = ( + mock_rpc + ) request = {} - client.get_wasm_plugin_version(request) + client.delete_agent_gateway(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_wasm_plugin_version(request) + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_agent_gateway(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_wasm_plugin_version_rest_required_fields( - request_type=extensibility.GetWasmPluginVersionRequest, +@pytest.mark.asyncio +async def test_delete_agent_gateway_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", ): - transport_class = transports.NetworkServicesRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson(pb_request, use_integers_for_enums=False) - ) - - # verify fields with default values are dropped - - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).get_wasm_plugin_version._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) - # verify required fields with default values are now present + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - jsonified_request["name"] = "name_value" + # Ensure method has been cached + assert ( + client._client._transport.delete_agent_gateway + in client._client._transport._wrapped_methods + ) - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).get_wasm_plugin_version._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.delete_agent_gateway + ] = mock_rpc - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + request = {} + await client.delete_agent_gateway(request) - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - request = request_type(**request_init) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - # Designate an appropriate value for the returned response. - return_value = extensibility.WasmPluginVersion() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "get", - "query_params": pb_request, - } - transcode.return_value = transcode_result + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() - response_value = Response() - response_value.status_code = 200 + await client.delete_agent_gateway(request) - # Convert return value to protobuf type - return_value = extensibility.WasmPluginVersion.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_wasm_plugin_version(request) +@pytest.mark.asyncio +@pytest.mark.parametrize( + "request_type", + [ + agent_gateway.DeleteAgentGatewayRequest(), + {}, + ], +) +async def test_delete_agent_gateway_async( + request_type, transport: str = "grpc_asyncio" +): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert sorted(expected_params) == sorted(actual_params) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_agent_gateway(request) -def test_get_wasm_plugin_version_rest_unset_required_fields(): - transport = transports.NetworkServicesRestTransport( - credentials=ga_credentials.AnonymousCredentials - ) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = agent_gateway.DeleteAgentGatewayRequest() + assert args[0] == request - unset_fields = transport.get_wasm_plugin_version._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) -def test_get_wasm_plugin_version_rest_flattened(): +def test_delete_agent_gateway_field_headers(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = extensibility.WasmPluginVersion() - - # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" - } + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = agent_gateway.DeleteAgentGatewayRequest() - # get truthy value for each flattened field - mock_args = dict( - name="name_value", - ) - mock_args.update(sample_request) + request.name = "name_value" - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - # Convert return value to protobuf type - return_value = extensibility.WasmPluginVersion.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_agent_gateway(request) - client.get_wasm_plugin_version(**mock_args) + # 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 underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/wasmPlugins/*/versions/*}" - % client.transport._host, - args[1], + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_agent_gateway_field_headers_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = agent_gateway.DeleteAgentGatewayRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") ) + await client.delete_agent_gateway(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", + "name=name_value", + ) in kw["metadata"] -def test_get_wasm_plugin_version_rest_flattened_error(transport: str = "rest"): + +def test_delete_agent_gateway_flattened(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_agent_gateway( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_agent_gateway_flattened_error(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_wasm_plugin_version( - extensibility.GetWasmPluginVersionRequest(), + client.delete_agent_gateway( + agent_gateway.DeleteAgentGatewayRequest(), name="name_value", ) -def test_create_wasm_plugin_version_rest_use_cached_wrapped_rpc(): +@pytest.mark.asyncio +async def test_delete_agent_gateway_flattened_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_agent_gateway( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_agent_gateway_flattened_error_async(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_agent_gateway( + agent_gateway.DeleteAgentGatewayRequest(), + name="name_value", + ) + + +def test_list_endpoint_policies_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -25618,7 +26180,7 @@ def test_create_wasm_plugin_version_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.create_wasm_plugin_version + client._transport.list_endpoint_policies in client._transport._wrapped_methods ) @@ -25627,35 +26189,30 @@ def test_create_wasm_plugin_version_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_wasm_plugin_version - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_endpoint_policies] = ( + mock_rpc + ) request = {} - client.create_wasm_plugin_version(request) + client.list_endpoint_policies(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_wasm_plugin_version(request) + client.list_endpoint_policies(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_wasm_plugin_version_rest_required_fields( - request_type=extensibility.CreateWasmPluginVersionRequest, +def test_list_endpoint_policies_rest_required_fields( + request_type=endpoint_policy.ListEndpointPoliciesRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" - request_init["wasm_plugin_version_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -25663,35 +26220,32 @@ def test_create_wasm_plugin_version_rest_required_fields( ) # verify fields with default values are dropped - assert "wasmPluginVersionId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_wasm_plugin_version._get_unset_required_fields(jsonified_request) + ).list_endpoint_policies._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "wasmPluginVersionId" in jsonified_request - assert ( - jsonified_request["wasmPluginVersionId"] - == request_init["wasm_plugin_version_id"] - ) jsonified_request["parent"] = "parent_value" - jsonified_request["wasmPluginVersionId"] = "wasm_plugin_version_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_wasm_plugin_version._get_unset_required_fields(jsonified_request) + ).list_endpoint_policies._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("wasm_plugin_version_id",)) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + "return_partial_success", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "wasmPluginVersionId" in jsonified_request - assert jsonified_request["wasmPluginVersionId"] == "wasm_plugin_version_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -25700,7 +26254,7 @@ def test_create_wasm_plugin_version_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = endpoint_policy.ListEndpointPoliciesResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -25712,52 +26266,48 @@ def test_create_wasm_plugin_version_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = endpoint_policy.ListEndpointPoliciesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_wasm_plugin_version(request) + response = client.list_endpoint_policies(request) - expected_params = [ - ( - "wasmPluginVersionId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_wasm_plugin_version_rest_unset_required_fields(): +def test_list_endpoint_policies_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_wasm_plugin_version._get_unset_required_fields({}) + unset_fields = transport.list_endpoint_policies._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("wasmPluginVersionId",)) - & set( + set( ( - "parent", - "wasmPluginVersionId", - "wasmPluginVersion", + "pageSize", + "pageToken", + "returnPartialSuccess", ) ) + & set(("parent",)) ) -def test_create_wasm_plugin_version_rest_flattened(): +def test_list_endpoint_policies_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -25766,45 +26316,41 @@ def test_create_wasm_plugin_version_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = endpoint_policy.ListEndpointPoliciesResponse() # get arguments that satisfy an http rule for this method - sample_request = { - "parent": "projects/sample1/locations/sample2/wasmPlugins/sample3" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( parent="parent_value", - wasm_plugin_version=extensibility.WasmPluginVersion( - plugin_config_data=b"plugin_config_data_blob" - ), - wasm_plugin_version_id="wasm_plugin_version_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = endpoint_policy.ListEndpointPoliciesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_wasm_plugin_version(**mock_args) + client.list_endpoint_policies(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*/wasmPlugins/*}/versions" + "%s/v1/{parent=projects/*/locations/*}/endpointPolicies" % client.transport._host, args[1], ) -def test_create_wasm_plugin_version_rest_flattened_error(transport: str = "rest"): +def test_list_endpoint_policies_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -25813,17 +26359,76 @@ def test_create_wasm_plugin_version_rest_flattened_error(transport: str = "rest" # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_wasm_plugin_version( - extensibility.CreateWasmPluginVersionRequest(), + client.list_endpoint_policies( + endpoint_policy.ListEndpointPoliciesRequest(), parent="parent_value", - wasm_plugin_version=extensibility.WasmPluginVersion( - plugin_config_data=b"plugin_config_data_blob" + ) + + +def test_list_endpoint_policies_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + endpoint_policy.ListEndpointPoliciesResponse( + endpoint_policies=[ + endpoint_policy.EndpointPolicy(), + endpoint_policy.EndpointPolicy(), + endpoint_policy.EndpointPolicy(), + ], + next_page_token="abc", + ), + endpoint_policy.ListEndpointPoliciesResponse( + endpoint_policies=[], + next_page_token="def", + ), + endpoint_policy.ListEndpointPoliciesResponse( + endpoint_policies=[ + endpoint_policy.EndpointPolicy(), + ], + next_page_token="ghi", + ), + endpoint_policy.ListEndpointPoliciesResponse( + endpoint_policies=[ + endpoint_policy.EndpointPolicy(), + endpoint_policy.EndpointPolicy(), + ], ), - wasm_plugin_version_id="wasm_plugin_version_id_value", ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + endpoint_policy.ListEndpointPoliciesResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + sample_request = {"parent": "projects/sample1/locations/sample2"} -def test_delete_wasm_plugin_version_rest_use_cached_wrapped_rpc(): + pager = client.list_endpoint_policies(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, endpoint_policy.EndpointPolicy) for i in results) + + pages = list(client.list_endpoint_policies(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_endpoint_policy_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -25838,8 +26443,7 @@ def test_delete_wasm_plugin_version_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.delete_wasm_plugin_version - in client._transport._wrapped_methods + client._transport.get_endpoint_policy in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -25847,29 +26451,25 @@ def test_delete_wasm_plugin_version_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_wasm_plugin_version - ] = mock_rpc + client._transport._wrapped_methods[client._transport.get_endpoint_policy] = ( + mock_rpc + ) request = {} - client.delete_wasm_plugin_version(request) + client.get_endpoint_policy(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.delete_wasm_plugin_version(request) + client.get_endpoint_policy(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_wasm_plugin_version_rest_required_fields( - request_type=extensibility.DeleteWasmPluginVersionRequest, +def test_get_endpoint_policy_rest_required_fields( + request_type=endpoint_policy.GetEndpointPolicyRequest, ): transport_class = transports.NetworkServicesRestTransport @@ -25885,7 +26485,7 @@ def test_delete_wasm_plugin_version_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_wasm_plugin_version._get_unset_required_fields(jsonified_request) + ).get_endpoint_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -25894,7 +26494,7 @@ def test_delete_wasm_plugin_version_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_wasm_plugin_version._get_unset_required_fields(jsonified_request) + ).get_endpoint_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -25908,7 +26508,7 @@ def test_delete_wasm_plugin_version_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = endpoint_policy.EndpointPolicy() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -25920,36 +26520,39 @@ def test_delete_wasm_plugin_version_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "get", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = endpoint_policy.EndpointPolicy.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_wasm_plugin_version(request) + response = client.get_endpoint_policy(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_wasm_plugin_version_rest_unset_required_fields(): +def test_get_endpoint_policy_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_wasm_plugin_version._get_unset_required_fields({}) + unset_fields = transport.get_endpoint_policy._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_delete_wasm_plugin_version_rest_flattened(): +def test_get_endpoint_policy_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -25958,11 +26561,11 @@ def test_delete_wasm_plugin_version_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = endpoint_policy.EndpointPolicy() # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" } # get truthy value for each flattened field @@ -25974,25 +26577,27 @@ def test_delete_wasm_plugin_version_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = endpoint_policy.EndpointPolicy.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_wasm_plugin_version(**mock_args) + client.get_endpoint_policy(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/wasmPlugins/*/versions/*}" + "%s/v1/{name=projects/*/locations/*/endpointPolicies/*}" % client.transport._host, args[1], ) -def test_delete_wasm_plugin_version_rest_flattened_error(transport: str = "rest"): +def test_get_endpoint_policy_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -26001,13 +26606,13 @@ def test_delete_wasm_plugin_version_rest_flattened_error(transport: str = "rest" # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_wasm_plugin_version( - extensibility.DeleteWasmPluginVersionRequest(), + client.get_endpoint_policy( + endpoint_policy.GetEndpointPolicyRequest(), name="name_value", ) -def test_list_wasm_plugins_rest_use_cached_wrapped_rpc(): +def test_create_endpoint_policy_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -26021,37 +26626,45 @@ def test_list_wasm_plugins_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_wasm_plugins in client._transport._wrapped_methods + assert ( + client._transport.create_endpoint_policy + in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_wasm_plugins] = ( + client._transport._wrapped_methods[client._transport.create_endpoint_policy] = ( mock_rpc ) request = {} - client.list_wasm_plugins(request) + client.create_endpoint_policy(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_wasm_plugins(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_endpoint_policy(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_wasm_plugins_rest_required_fields( - request_type=extensibility.ListWasmPluginsRequest, +def test_create_endpoint_policy_rest_required_fields( + request_type=gcn_endpoint_policy.CreateEndpointPolicyRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" + request_init["endpoint_policy_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -26059,31 +26672,32 @@ def test_list_wasm_plugins_rest_required_fields( ) # verify fields with default values are dropped + assert "endpointPolicyId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_wasm_plugins._get_unset_required_fields(jsonified_request) + ).create_endpoint_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "endpointPolicyId" in jsonified_request + assert jsonified_request["endpointPolicyId"] == request_init["endpoint_policy_id"] jsonified_request["parent"] = "parent_value" + jsonified_request["endpointPolicyId"] = "endpoint_policy_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_wasm_plugins._get_unset_required_fields(jsonified_request) + ).create_endpoint_policy._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(("endpoint_policy_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" + assert "endpointPolicyId" in jsonified_request + assert jsonified_request["endpointPolicyId"] == "endpoint_policy_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26092,7 +26706,7 @@ def test_list_wasm_plugins_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = extensibility.ListWasmPluginsResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -26104,47 +26718,52 @@ def test_list_wasm_plugins_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = extensibility.ListWasmPluginsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_wasm_plugins(request) + response = client.create_endpoint_policy(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "endpointPolicyId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_wasm_plugins_rest_unset_required_fields(): +def test_create_endpoint_policy_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_wasm_plugins._get_unset_required_fields({}) + unset_fields = transport.create_endpoint_policy._get_unset_required_fields({}) assert set(unset_fields) == ( - set( + set(("endpointPolicyId",)) + & set( ( - "pageSize", - "pageToken", + "parent", + "endpointPolicyId", + "endpointPolicy", ) ) - & set(("parent",)) ) -def test_list_wasm_plugins_rest_flattened(): +def test_create_endpoint_policy_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -26153,7 +26772,7 @@ def test_list_wasm_plugins_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = extensibility.ListWasmPluginsResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method sample_request = {"parent": "projects/sample1/locations/sample2"} @@ -26161,33 +26780,33 @@ def test_list_wasm_plugins_rest_flattened(): # get truthy value for each flattened field mock_args = dict( parent="parent_value", + endpoint_policy=gcn_endpoint_policy.EndpointPolicy(name="name_value"), + endpoint_policy_id="endpoint_policy_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = extensibility.ListWasmPluginsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_wasm_plugins(**mock_args) + client.create_endpoint_policy(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/wasmPlugins" + "%s/v1/{parent=projects/*/locations/*}/endpointPolicies" % client.transport._host, args[1], ) -def test_list_wasm_plugins_rest_flattened_error(transport: str = "rest"): +def test_create_endpoint_policy_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -26196,76 +26815,15 @@ def test_list_wasm_plugins_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_wasm_plugins( - extensibility.ListWasmPluginsRequest(), + client.create_endpoint_policy( + gcn_endpoint_policy.CreateEndpointPolicyRequest(), parent="parent_value", + endpoint_policy=gcn_endpoint_policy.EndpointPolicy(name="name_value"), + endpoint_policy_id="endpoint_policy_id_value", ) -def test_list_wasm_plugins_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - extensibility.ListWasmPluginsResponse( - wasm_plugins=[ - extensibility.WasmPlugin(), - extensibility.WasmPlugin(), - extensibility.WasmPlugin(), - ], - next_page_token="abc", - ), - extensibility.ListWasmPluginsResponse( - wasm_plugins=[], - next_page_token="def", - ), - extensibility.ListWasmPluginsResponse( - wasm_plugins=[ - extensibility.WasmPlugin(), - ], - next_page_token="ghi", - ), - extensibility.ListWasmPluginsResponse( - wasm_plugins=[ - extensibility.WasmPlugin(), - extensibility.WasmPlugin(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple( - extensibility.ListWasmPluginsResponse.to_json(x) for x in response - ) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_wasm_plugins(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, extensibility.WasmPlugin) for i in results) - - pages = list(client.list_wasm_plugins(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -def test_get_wasm_plugin_rest_use_cached_wrapped_rpc(): +def test_update_endpoint_policy_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -26279,35 +26837,43 @@ def test_get_wasm_plugin_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_wasm_plugin in client._transport._wrapped_methods + assert ( + client._transport.update_endpoint_policy + in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_wasm_plugin] = mock_rpc + client._transport._wrapped_methods[client._transport.update_endpoint_policy] = ( + mock_rpc + ) request = {} - client.get_wasm_plugin(request) + client.update_endpoint_policy(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_wasm_plugin(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_endpoint_policy(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_wasm_plugin_rest_required_fields( - request_type=extensibility.GetWasmPluginRequest, +def test_update_endpoint_policy_rest_required_fields( + request_type=gcn_endpoint_policy.UpdateEndpointPolicyRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -26318,23 +26884,19 @@ def test_get_wasm_plugin_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_wasm_plugin._get_unset_required_fields(jsonified_request) + ).update_endpoint_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_wasm_plugin._get_unset_required_fields(jsonified_request) + ).update_endpoint_policy._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("view",)) + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26343,7 +26905,7 @@ def test_get_wasm_plugin_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = extensibility.WasmPlugin() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -26355,39 +26917,37 @@ def test_get_wasm_plugin_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = extensibility.WasmPlugin.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_wasm_plugin(request) + response = client.update_endpoint_policy(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_wasm_plugin_rest_unset_required_fields(): +def test_update_endpoint_policy_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_wasm_plugin._get_unset_required_fields({}) - assert set(unset_fields) == (set(("view",)) & set(("name",))) + unset_fields = transport.update_endpoint_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("endpointPolicy",))) -def test_get_wasm_plugin_rest_flattened(): +def test_update_endpoint_policy_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -26396,43 +26956,44 @@ def test_get_wasm_plugin_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = extensibility.WasmPlugin() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" + "endpoint_policy": { + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + } } # get truthy value for each flattened field mock_args = dict( - name="name_value", + endpoint_policy=gcn_endpoint_policy.EndpointPolicy(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = extensibility.WasmPlugin.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_wasm_plugin(**mock_args) + client.update_endpoint_policy(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/wasmPlugins/*}" + "%s/v1/{endpoint_policy.name=projects/*/locations/*/endpointPolicies/*}" % client.transport._host, args[1], ) -def test_get_wasm_plugin_rest_flattened_error(transport: str = "rest"): +def test_update_endpoint_policy_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -26441,13 +27002,14 @@ def test_get_wasm_plugin_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_wasm_plugin( - extensibility.GetWasmPluginRequest(), - name="name_value", + client.update_endpoint_policy( + gcn_endpoint_policy.UpdateEndpointPolicyRequest(), + endpoint_policy=gcn_endpoint_policy.EndpointPolicy(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_create_wasm_plugin_rest_use_cached_wrapped_rpc(): +def test_delete_endpoint_policy_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -26462,7 +27024,8 @@ def test_create_wasm_plugin_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.create_wasm_plugin in client._transport._wrapped_methods + client._transport.delete_endpoint_policy + in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -26470,12 +27033,12 @@ def test_create_wasm_plugin_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_wasm_plugin] = ( + client._transport._wrapped_methods[client._transport.delete_endpoint_policy] = ( mock_rpc ) request = {} - client.create_wasm_plugin(request) + client.delete_endpoint_policy(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -26484,21 +27047,20 @@ def test_create_wasm_plugin_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.create_wasm_plugin(request) + client.delete_endpoint_policy(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_wasm_plugin_rest_required_fields( - request_type=extensibility.CreateWasmPluginRequest, +def test_delete_endpoint_policy_rest_required_fields( + request_type=endpoint_policy.DeleteEndpointPolicyRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["parent"] = "" - request_init["wasm_plugin_id"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -26506,32 +27068,24 @@ def test_create_wasm_plugin_rest_required_fields( ) # verify fields with default values are dropped - assert "wasmPluginId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_wasm_plugin._get_unset_required_fields(jsonified_request) + ).delete_endpoint_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "wasmPluginId" in jsonified_request - assert jsonified_request["wasmPluginId"] == request_init["wasm_plugin_id"] - jsonified_request["parent"] = "parent_value" - jsonified_request["wasmPluginId"] = "wasm_plugin_id_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_wasm_plugin._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("wasm_plugin_id",)) + ).delete_endpoint_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" - assert "wasmPluginId" in jsonified_request - assert jsonified_request["wasmPluginId"] == "wasm_plugin_id_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26552,10 +27106,9 @@ def test_create_wasm_plugin_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "delete", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -26566,38 +27119,23 @@ def test_create_wasm_plugin_rest_required_fields( req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_wasm_plugin(request) + response = client.delete_endpoint_policy(request) - expected_params = [ - ( - "wasmPluginId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_wasm_plugin_rest_unset_required_fields(): +def test_delete_endpoint_policy_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_wasm_plugin._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(("wasmPluginId",)) - & set( - ( - "parent", - "wasmPluginId", - "wasmPlugin", - ) - ) - ) + unset_fields = transport.delete_endpoint_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_create_wasm_plugin_rest_flattened(): +def test_delete_endpoint_policy_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -26609,13 +27147,13 @@ def test_create_wasm_plugin_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", - wasm_plugin=extensibility.WasmPlugin(name="name_value"), - wasm_plugin_id="wasm_plugin_id_value", + name="name_value", ) mock_args.update(sample_request) @@ -26627,20 +27165,20 @@ def test_create_wasm_plugin_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_wasm_plugin(**mock_args) + client.delete_endpoint_policy(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/wasmPlugins" + "%s/v1/{name=projects/*/locations/*/endpointPolicies/*}" % client.transport._host, args[1], ) -def test_create_wasm_plugin_rest_flattened_error(transport: str = "rest"): +def test_delete_endpoint_policy_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -26649,15 +27187,13 @@ def test_create_wasm_plugin_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_wasm_plugin( - extensibility.CreateWasmPluginRequest(), - parent="parent_value", - wasm_plugin=extensibility.WasmPlugin(name="name_value"), - wasm_plugin_id="wasm_plugin_id_value", + client.delete_endpoint_policy( + endpoint_policy.DeleteEndpointPolicyRequest(), + name="name_value", ) -def test_update_wasm_plugin_rest_use_cached_wrapped_rpc(): +def test_list_wasm_plugin_versions_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -26672,7 +27208,8 @@ def test_update_wasm_plugin_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.update_wasm_plugin in client._transport._wrapped_methods + client._transport.list_wasm_plugin_versions + in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -26680,33 +27217,30 @@ def test_update_wasm_plugin_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_wasm_plugin] = ( - mock_rpc - ) + client._transport._wrapped_methods[ + client._transport.list_wasm_plugin_versions + ] = mock_rpc request = {} - client.update_wasm_plugin(request) + client.list_wasm_plugin_versions(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_wasm_plugin(request) + client.list_wasm_plugin_versions(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_wasm_plugin_rest_required_fields( - request_type=extensibility.UpdateWasmPluginRequest, +def test_list_wasm_plugin_versions_rest_required_fields( + request_type=extensibility.ListWasmPluginVersionsRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -26717,19 +27251,28 @@ def test_update_wasm_plugin_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_wasm_plugin._get_unset_required_fields(jsonified_request) + ).list_wasm_plugin_versions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["parent"] = "parent_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_wasm_plugin._get_unset_required_fields(jsonified_request) + ).list_wasm_plugin_versions._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26738,7 +27281,7 @@ def test_update_wasm_plugin_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = extensibility.ListWasmPluginVersionsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -26750,37 +27293,47 @@ def test_update_wasm_plugin_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = extensibility.ListWasmPluginVersionsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_wasm_plugin(request) + response = client.list_wasm_plugin_versions(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_update_wasm_plugin_rest_unset_required_fields(): +def test_list_wasm_plugin_versions_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_wasm_plugin._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("wasmPlugin",))) + unset_fields = transport.list_wasm_plugin_versions._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) -def test_update_wasm_plugin_rest_flattened(): +def test_list_wasm_plugin_versions_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -26789,44 +27342,43 @@ def test_update_wasm_plugin_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = extensibility.ListWasmPluginVersionsResponse() # get arguments that satisfy an http rule for this method sample_request = { - "wasm_plugin": { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" - } + "parent": "projects/sample1/locations/sample2/wasmPlugins/sample3" } # get truthy value for each flattened field mock_args = dict( - wasm_plugin=extensibility.WasmPlugin(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + parent="parent_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = extensibility.ListWasmPluginVersionsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_wasm_plugin(**mock_args) + client.list_wasm_plugin_versions(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{wasm_plugin.name=projects/*/locations/*/wasmPlugins/*}" + "%s/v1/{parent=projects/*/locations/*/wasmPlugins/*}/versions" % client.transport._host, args[1], ) -def test_update_wasm_plugin_rest_flattened_error(transport: str = "rest"): +def test_list_wasm_plugin_versions_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -26835,14 +27387,78 @@ def test_update_wasm_plugin_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_wasm_plugin( - extensibility.UpdateWasmPluginRequest(), - wasm_plugin=extensibility.WasmPlugin(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.list_wasm_plugin_versions( + extensibility.ListWasmPluginVersionsRequest(), + parent="parent_value", ) -def test_delete_wasm_plugin_rest_use_cached_wrapped_rpc(): +def test_list_wasm_plugin_versions_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + extensibility.ListWasmPluginVersionsResponse( + wasm_plugin_versions=[ + extensibility.WasmPluginVersion(), + extensibility.WasmPluginVersion(), + extensibility.WasmPluginVersion(), + ], + next_page_token="abc", + ), + extensibility.ListWasmPluginVersionsResponse( + wasm_plugin_versions=[], + next_page_token="def", + ), + extensibility.ListWasmPluginVersionsResponse( + wasm_plugin_versions=[ + extensibility.WasmPluginVersion(), + ], + next_page_token="ghi", + ), + extensibility.ListWasmPluginVersionsResponse( + wasm_plugin_versions=[ + extensibility.WasmPluginVersion(), + extensibility.WasmPluginVersion(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + extensibility.ListWasmPluginVersionsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = { + "parent": "projects/sample1/locations/sample2/wasmPlugins/sample3" + } + + pager = client.list_wasm_plugin_versions(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, extensibility.WasmPluginVersion) for i in results) + + pages = list(client.list_wasm_plugin_versions(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_wasm_plugin_version_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -26857,7 +27473,8 @@ def test_delete_wasm_plugin_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.delete_wasm_plugin in client._transport._wrapped_methods + client._transport.get_wasm_plugin_version + in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -26865,29 +27482,25 @@ def test_delete_wasm_plugin_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_wasm_plugin] = ( - mock_rpc - ) + client._transport._wrapped_methods[ + client._transport.get_wasm_plugin_version + ] = mock_rpc request = {} - client.delete_wasm_plugin(request) + client.get_wasm_plugin_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.delete_wasm_plugin(request) + client.get_wasm_plugin_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_wasm_plugin_rest_required_fields( - request_type=extensibility.DeleteWasmPluginRequest, +def test_get_wasm_plugin_version_rest_required_fields( + request_type=extensibility.GetWasmPluginVersionRequest, ): transport_class = transports.NetworkServicesRestTransport @@ -26903,7 +27516,7 @@ def test_delete_wasm_plugin_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_wasm_plugin._get_unset_required_fields(jsonified_request) + ).get_wasm_plugin_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -26912,7 +27525,7 @@ def test_delete_wasm_plugin_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_wasm_plugin._get_unset_required_fields(jsonified_request) + ).get_wasm_plugin_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -26926,7 +27539,7 @@ def test_delete_wasm_plugin_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = extensibility.WasmPluginVersion() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -26938,36 +27551,39 @@ def test_delete_wasm_plugin_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "get", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = extensibility.WasmPluginVersion.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_wasm_plugin(request) + response = client.get_wasm_plugin_version(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_wasm_plugin_rest_unset_required_fields(): +def test_get_wasm_plugin_version_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_wasm_plugin._get_unset_required_fields({}) + unset_fields = transport.get_wasm_plugin_version._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_delete_wasm_plugin_rest_flattened(): +def test_get_wasm_plugin_version_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -26976,11 +27592,11 @@ def test_delete_wasm_plugin_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = extensibility.WasmPluginVersion() # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" } # get truthy value for each flattened field @@ -26992,25 +27608,27 @@ def test_delete_wasm_plugin_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = extensibility.WasmPluginVersion.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_wasm_plugin(**mock_args) + client.get_wasm_plugin_version(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/wasmPlugins/*}" + "%s/v1/{name=projects/*/locations/*/wasmPlugins/*/versions/*}" % client.transport._host, args[1], ) -def test_delete_wasm_plugin_rest_flattened_error(transport: str = "rest"): +def test_get_wasm_plugin_version_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -27019,13 +27637,13 @@ def test_delete_wasm_plugin_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_wasm_plugin( - extensibility.DeleteWasmPluginRequest(), + client.get_wasm_plugin_version( + extensibility.GetWasmPluginVersionRequest(), name="name_value", ) -def test_list_gateways_rest_use_cached_wrapped_rpc(): +def test_create_wasm_plugin_version_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -27039,33 +27657,45 @@ def test_list_gateways_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_gateways in client._transport._wrapped_methods + assert ( + client._transport.create_wasm_plugin_version + in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_gateways] = mock_rpc + client._transport._wrapped_methods[ + client._transport.create_wasm_plugin_version + ] = mock_rpc request = {} - client.list_gateways(request) + client.create_wasm_plugin_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_gateways(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_wasm_plugin_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_gateways_rest_required_fields(request_type=gateway.ListGatewaysRequest): +def test_create_wasm_plugin_version_rest_required_fields( + request_type=extensibility.CreateWasmPluginVersionRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" + request_init["wasm_plugin_version_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -27073,31 +27703,35 @@ def test_list_gateways_rest_required_fields(request_type=gateway.ListGatewaysReq ) # verify fields with default values are dropped + assert "wasmPluginVersionId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_gateways._get_unset_required_fields(jsonified_request) + ).create_wasm_plugin_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "wasmPluginVersionId" in jsonified_request + assert ( + jsonified_request["wasmPluginVersionId"] + == request_init["wasm_plugin_version_id"] + ) jsonified_request["parent"] = "parent_value" + jsonified_request["wasmPluginVersionId"] = "wasm_plugin_version_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_gateways._get_unset_required_fields(jsonified_request) + ).create_wasm_plugin_version._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(("wasm_plugin_version_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" + assert "wasmPluginVersionId" in jsonified_request + assert jsonified_request["wasmPluginVersionId"] == "wasm_plugin_version_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27106,7 +27740,7 @@ def test_list_gateways_rest_required_fields(request_type=gateway.ListGatewaysReq request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gateway.ListGatewaysResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -27118,47 +27752,52 @@ def test_list_gateways_rest_required_fields(request_type=gateway.ListGatewaysReq pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = gateway.ListGatewaysResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_gateways(request) + response = client.create_wasm_plugin_version(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "wasmPluginVersionId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_gateways_rest_unset_required_fields(): +def test_create_wasm_plugin_version_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_gateways._get_unset_required_fields({}) + unset_fields = transport.create_wasm_plugin_version._get_unset_required_fields({}) assert set(unset_fields) == ( - set( + set(("wasmPluginVersionId",)) + & set( ( - "pageSize", - "pageToken", + "parent", + "wasmPluginVersionId", + "wasmPluginVersion", ) ) - & set(("parent",)) ) -def test_list_gateways_rest_flattened(): +def test_create_wasm_plugin_version_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -27167,40 +27806,45 @@ def test_list_gateways_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gateway.ListGatewaysResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "parent": "projects/sample1/locations/sample2/wasmPlugins/sample3" + } # get truthy value for each flattened field mock_args = dict( parent="parent_value", + wasm_plugin_version=extensibility.WasmPluginVersion( + plugin_config_data=b"plugin_config_data_blob" + ), + wasm_plugin_version_id="wasm_plugin_version_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = gateway.ListGatewaysResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_gateways(**mock_args) + client.create_wasm_plugin_version(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/gateways" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*/wasmPlugins/*}/versions" + % client.transport._host, args[1], ) -def test_list_gateways_rest_flattened_error(transport: str = "rest"): +def test_create_wasm_plugin_version_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -27209,74 +27853,17 @@ def test_list_gateways_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_gateways( - gateway.ListGatewaysRequest(), + client.create_wasm_plugin_version( + extensibility.CreateWasmPluginVersionRequest(), parent="parent_value", - ) - - -def test_list_gateways_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - gateway.ListGatewaysResponse( - gateways=[ - gateway.Gateway(), - gateway.Gateway(), - gateway.Gateway(), - ], - next_page_token="abc", - ), - gateway.ListGatewaysResponse( - gateways=[], - next_page_token="def", - ), - gateway.ListGatewaysResponse( - gateways=[ - gateway.Gateway(), - ], - next_page_token="ghi", - ), - gateway.ListGatewaysResponse( - gateways=[ - gateway.Gateway(), - gateway.Gateway(), - ], + wasm_plugin_version=extensibility.WasmPluginVersion( + plugin_config_data=b"plugin_config_data_blob" ), + wasm_plugin_version_id="wasm_plugin_version_id_value", ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(gateway.ListGatewaysResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_gateways(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, gateway.Gateway) for i in results) - - pages = list(client.list_gateways(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_get_gateway_rest_use_cached_wrapped_rpc(): +def test_delete_wasm_plugin_version_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -27290,29 +27877,40 @@ def test_get_gateway_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_gateway in client._transport._wrapped_methods + assert ( + client._transport.delete_wasm_plugin_version + in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_gateway] = mock_rpc + client._transport._wrapped_methods[ + client._transport.delete_wasm_plugin_version + ] = mock_rpc request = {} - client.get_gateway(request) + client.delete_wasm_plugin_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_gateway(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_wasm_plugin_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_gateway_rest_required_fields(request_type=gateway.GetGatewayRequest): +def test_delete_wasm_plugin_version_rest_required_fields( + request_type=extensibility.DeleteWasmPluginVersionRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} @@ -27327,7 +27925,7 @@ def test_get_gateway_rest_required_fields(request_type=gateway.GetGatewayRequest unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_gateway._get_unset_required_fields(jsonified_request) + ).delete_wasm_plugin_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -27336,7 +27934,7 @@ def test_get_gateway_rest_required_fields(request_type=gateway.GetGatewayRequest unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_gateway._get_unset_required_fields(jsonified_request) + ).delete_wasm_plugin_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -27350,7 +27948,7 @@ def test_get_gateway_rest_required_fields(request_type=gateway.GetGatewayRequest request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gateway.Gateway() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -27362,39 +27960,36 @@ def test_get_gateway_rest_required_fields(request_type=gateway.GetGatewayRequest pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "delete", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = gateway.Gateway.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_gateway(request) + response = client.delete_wasm_plugin_version(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_gateway_rest_unset_required_fields(): +def test_delete_wasm_plugin_version_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_gateway._get_unset_required_fields({}) + unset_fields = transport.delete_wasm_plugin_version._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_gateway_rest_flattened(): +def test_delete_wasm_plugin_version_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -27403,10 +27998,12 @@ def test_get_gateway_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gateway.Gateway() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"name": "projects/sample1/locations/sample2/gateways/sample3"} + sample_request = { + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" + } # get truthy value for each flattened field mock_args = dict( @@ -27417,26 +28014,25 @@ def test_get_gateway_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = gateway.Gateway.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_gateway(**mock_args) + client.delete_wasm_plugin_version(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/gateways/*}" % client.transport._host, + "%s/v1/{name=projects/*/locations/*/wasmPlugins/*/versions/*}" + % client.transport._host, args[1], ) -def test_get_gateway_rest_flattened_error(transport: str = "rest"): +def test_delete_wasm_plugin_version_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -27445,13 +28041,13 @@ def test_get_gateway_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_gateway( - gateway.GetGatewayRequest(), + client.delete_wasm_plugin_version( + extensibility.DeleteWasmPluginVersionRequest(), name="name_value", ) -def test_create_gateway_rest_use_cached_wrapped_rpc(): +def test_list_wasm_plugins_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -27465,40 +28061,37 @@ def test_create_gateway_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_gateway in client._transport._wrapped_methods + assert client._transport.list_wasm_plugins in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_gateway] = mock_rpc + client._transport._wrapped_methods[client._transport.list_wasm_plugins] = ( + mock_rpc + ) request = {} - client.create_gateway(request) + client.list_wasm_plugins(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_gateway(request) + client.list_wasm_plugins(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_gateway_rest_required_fields( - request_type=gcn_gateway.CreateGatewayRequest, +def test_list_wasm_plugins_rest_required_fields( + request_type=extensibility.ListWasmPluginsRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" - request_init["gateway_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -27506,32 +28099,31 @@ def test_create_gateway_rest_required_fields( ) # verify fields with default values are dropped - assert "gatewayId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_gateway._get_unset_required_fields(jsonified_request) + ).list_wasm_plugins._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "gatewayId" in jsonified_request - assert jsonified_request["gatewayId"] == request_init["gateway_id"] jsonified_request["parent"] = "parent_value" - jsonified_request["gatewayId"] = "gateway_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_gateway._get_unset_required_fields(jsonified_request) + ).list_wasm_plugins._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("gateway_id",)) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "gatewayId" in jsonified_request - assert jsonified_request["gatewayId"] == "gateway_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27540,7 +28132,7 @@ def test_create_gateway_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = extensibility.ListWasmPluginsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -27552,52 +28144,47 @@ def test_create_gateway_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = extensibility.ListWasmPluginsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_gateway(request) + response = client.list_wasm_plugins(request) - expected_params = [ - ( - "gatewayId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_gateway_rest_unset_required_fields(): +def test_list_wasm_plugins_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_gateway._get_unset_required_fields({}) + unset_fields = transport.list_wasm_plugins._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("gatewayId",)) - & set( + set( ( - "parent", - "gatewayId", - "gateway", + "pageSize", + "pageToken", ) ) + & set(("parent",)) ) -def test_create_gateway_rest_flattened(): +def test_list_wasm_plugins_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -27606,7 +28193,7 @@ def test_create_gateway_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = extensibility.ListWasmPluginsResponse() # get arguments that satisfy an http rule for this method sample_request = {"parent": "projects/sample1/locations/sample2"} @@ -27614,32 +28201,33 @@ def test_create_gateway_rest_flattened(): # get truthy value for each flattened field mock_args = dict( parent="parent_value", - gateway=gcn_gateway.Gateway(name="name_value"), - gateway_id="gateway_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = extensibility.ListWasmPluginsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_gateway(**mock_args) + client.list_wasm_plugins(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/gateways" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/wasmPlugins" + % client.transport._host, args[1], ) -def test_create_gateway_rest_flattened_error(transport: str = "rest"): +def test_list_wasm_plugins_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -27648,15 +28236,76 @@ def test_create_gateway_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_gateway( - gcn_gateway.CreateGatewayRequest(), + client.list_wasm_plugins( + extensibility.ListWasmPluginsRequest(), parent="parent_value", - gateway=gcn_gateway.Gateway(name="name_value"), - gateway_id="gateway_id_value", ) -def test_update_gateway_rest_use_cached_wrapped_rpc(): +def test_list_wasm_plugins_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + extensibility.ListWasmPluginsResponse( + wasm_plugins=[ + extensibility.WasmPlugin(), + extensibility.WasmPlugin(), + extensibility.WasmPlugin(), + ], + next_page_token="abc", + ), + extensibility.ListWasmPluginsResponse( + wasm_plugins=[], + next_page_token="def", + ), + extensibility.ListWasmPluginsResponse( + wasm_plugins=[ + extensibility.WasmPlugin(), + ], + next_page_token="ghi", + ), + extensibility.ListWasmPluginsResponse( + wasm_plugins=[ + extensibility.WasmPlugin(), + extensibility.WasmPlugin(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + extensibility.ListWasmPluginsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_wasm_plugins(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, extensibility.WasmPlugin) for i in results) + + pages = list(client.list_wasm_plugins(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_wasm_plugin_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -27670,38 +28319,35 @@ def test_update_gateway_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_gateway in client._transport._wrapped_methods + assert client._transport.get_wasm_plugin in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_gateway] = mock_rpc + client._transport._wrapped_methods[client._transport.get_wasm_plugin] = mock_rpc request = {} - client.update_gateway(request) + client.get_wasm_plugin(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_gateway(request) + client.get_wasm_plugin(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_gateway_rest_required_fields( - request_type=gcn_gateway.UpdateGatewayRequest, +def test_get_wasm_plugin_rest_required_fields( + request_type=extensibility.GetWasmPluginRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -27712,19 +28358,23 @@ def test_update_gateway_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_gateway._get_unset_required_fields(jsonified_request) + ).get_wasm_plugin._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_gateway._get_unset_required_fields(jsonified_request) + ).get_wasm_plugin._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + assert not set(unset_fields) - set(("view",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27733,7 +28383,7 @@ def test_update_gateway_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = extensibility.WasmPlugin() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -27745,37 +28395,39 @@ def test_update_gateway_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = extensibility.WasmPlugin.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_gateway(request) + response = client.get_wasm_plugin(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_update_gateway_rest_unset_required_fields(): +def test_get_wasm_plugin_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_gateway._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("gateway",))) + unset_fields = transport.get_wasm_plugin._get_unset_required_fields({}) + assert set(unset_fields) == (set(("view",)) & set(("name",))) -def test_update_gateway_rest_flattened(): +def test_get_wasm_plugin_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -27784,42 +28436,43 @@ def test_update_gateway_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = extensibility.WasmPlugin() # get arguments that satisfy an http rule for this method sample_request = { - "gateway": {"name": "projects/sample1/locations/sample2/gateways/sample3"} + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" } # get truthy value for each flattened field mock_args = dict( - gateway=gcn_gateway.Gateway(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = extensibility.WasmPlugin.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_gateway(**mock_args) + client.get_wasm_plugin(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{gateway.name=projects/*/locations/*/gateways/*}" + "%s/v1/{name=projects/*/locations/*/wasmPlugins/*}" % client.transport._host, args[1], ) -def test_update_gateway_rest_flattened_error(transport: str = "rest"): +def test_get_wasm_plugin_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -27828,14 +28481,13 @@ def test_update_gateway_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_gateway( - gcn_gateway.UpdateGatewayRequest(), - gateway=gcn_gateway.Gateway(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_wasm_plugin( + extensibility.GetWasmPluginRequest(), + name="name_value", ) -def test_delete_gateway_rest_use_cached_wrapped_rpc(): +def test_create_wasm_plugin_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -27849,17 +28501,21 @@ def test_delete_gateway_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_gateway in client._transport._wrapped_methods + assert ( + client._transport.create_wasm_plugin in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_gateway] = mock_rpc + client._transport._wrapped_methods[client._transport.create_wasm_plugin] = ( + mock_rpc + ) request = {} - client.delete_gateway(request) + client.create_wasm_plugin(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -27868,18 +28524,21 @@ def test_delete_gateway_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_gateway(request) + client.create_wasm_plugin(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_gateway_rest_required_fields(request_type=gateway.DeleteGatewayRequest): +def test_create_wasm_plugin_rest_required_fields( + request_type=extensibility.CreateWasmPluginRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["wasm_plugin_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -27887,24 +28546,32 @@ def test_delete_gateway_rest_required_fields(request_type=gateway.DeleteGatewayR ) # verify fields with default values are dropped + assert "wasmPluginId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_gateway._get_unset_required_fields(jsonified_request) + ).create_wasm_plugin._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "wasmPluginId" in jsonified_request + assert jsonified_request["wasmPluginId"] == request_init["wasm_plugin_id"] - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["wasmPluginId"] = "wasm_plugin_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_gateway._get_unset_required_fields(jsonified_request) + ).create_wasm_plugin._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("wasm_plugin_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "wasmPluginId" in jsonified_request + assert jsonified_request["wasmPluginId"] == "wasm_plugin_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27925,9 +28592,10 @@ def test_delete_gateway_rest_required_fields(request_type=gateway.DeleteGatewayR pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -27938,23 +28606,38 @@ def test_delete_gateway_rest_required_fields(request_type=gateway.DeleteGatewayR req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_gateway(request) + response = client.create_wasm_plugin(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "wasmPluginId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_gateway_rest_unset_required_fields(): +def test_create_wasm_plugin_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_gateway._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_wasm_plugin._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("wasmPluginId",)) + & set( + ( + "parent", + "wasmPluginId", + "wasmPlugin", + ) + ) + ) -def test_delete_gateway_rest_flattened(): +def test_create_wasm_plugin_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -27966,11 +28649,13 @@ def test_delete_gateway_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"name": "projects/sample1/locations/sample2/gateways/sample3"} + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + wasm_plugin=extensibility.WasmPlugin(name="name_value"), + wasm_plugin_id="wasm_plugin_id_value", ) mock_args.update(sample_request) @@ -27982,19 +28667,20 @@ def test_delete_gateway_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_gateway(**mock_args) + client.create_wasm_plugin(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/gateways/*}" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/wasmPlugins" + % client.transport._host, args[1], ) -def test_delete_gateway_rest_flattened_error(transport: str = "rest"): +def test_create_wasm_plugin_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -28003,13 +28689,15 @@ def test_delete_gateway_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_gateway( - gateway.DeleteGatewayRequest(), - name="name_value", + client.create_wasm_plugin( + extensibility.CreateWasmPluginRequest(), + parent="parent_value", + wasm_plugin=extensibility.WasmPlugin(name="name_value"), + wasm_plugin_id="wasm_plugin_id_value", ) -def test_list_grpc_routes_rest_use_cached_wrapped_rpc(): +def test_update_wasm_plugin_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -28023,37 +28711,42 @@ def test_list_grpc_routes_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_grpc_routes in client._transport._wrapped_methods + assert ( + client._transport.update_wasm_plugin in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_grpc_routes] = ( + client._transport._wrapped_methods[client._transport.update_wasm_plugin] = ( mock_rpc ) request = {} - client.list_grpc_routes(request) + client.update_wasm_plugin(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_grpc_routes(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_wasm_plugin(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_grpc_routes_rest_required_fields( - request_type=grpc_route.ListGrpcRoutesRequest, +def test_update_wasm_plugin_rest_required_fields( + request_type=extensibility.UpdateWasmPluginRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -28064,29 +28757,19 @@ def test_list_grpc_routes_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_grpc_routes._get_unset_required_fields(jsonified_request) + ).update_wasm_plugin._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_grpc_routes._get_unset_required_fields(jsonified_request) + ).update_wasm_plugin._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - "return_partial_success", - ) - ) + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -28095,7 +28778,7 @@ def test_list_grpc_routes_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = grpc_route.ListGrpcRoutesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -28107,48 +28790,37 @@ def test_list_grpc_routes_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = grpc_route.ListGrpcRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_grpc_routes(request) + response = client.update_wasm_plugin(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_grpc_routes_rest_unset_required_fields(): +def test_update_wasm_plugin_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_grpc_routes._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - "returnPartialSuccess", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.update_wasm_plugin._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("wasmPlugin",))) -def test_list_grpc_routes_rest_flattened(): +def test_update_wasm_plugin_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -28157,40 +28829,44 @@ def test_list_grpc_routes_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = grpc_route.ListGrpcRoutesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "wasm_plugin": { + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" + } + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + wasm_plugin=extensibility.WasmPlugin(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = grpc_route.ListGrpcRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_grpc_routes(**mock_args) + client.update_wasm_plugin(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/grpcRoutes" % client.transport._host, + "%s/v1/{wasm_plugin.name=projects/*/locations/*/wasmPlugins/*}" + % client.transport._host, args[1], ) -def test_list_grpc_routes_rest_flattened_error(transport: str = "rest"): +def test_update_wasm_plugin_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -28199,80 +28875,20 @@ def test_list_grpc_routes_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_grpc_routes( - grpc_route.ListGrpcRoutesRequest(), - parent="parent_value", + client.update_wasm_plugin( + extensibility.UpdateWasmPluginRequest(), + wasm_plugin=extensibility.WasmPlugin(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_list_grpc_routes_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - grpc_route.ListGrpcRoutesResponse( - grpc_routes=[ - grpc_route.GrpcRoute(), - grpc_route.GrpcRoute(), - grpc_route.GrpcRoute(), - ], - next_page_token="abc", - ), - grpc_route.ListGrpcRoutesResponse( - grpc_routes=[], - next_page_token="def", - ), - grpc_route.ListGrpcRoutesResponse( - grpc_routes=[ - grpc_route.GrpcRoute(), - ], - next_page_token="ghi", - ), - grpc_route.ListGrpcRoutesResponse( - grpc_routes=[ - grpc_route.GrpcRoute(), - grpc_route.GrpcRoute(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(grpc_route.ListGrpcRoutesResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_grpc_routes(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, grpc_route.GrpcRoute) for i in results) - - pages = list(client.list_grpc_routes(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -def test_get_grpc_route_rest_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", +def test_delete_wasm_plugin_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Should wrap all calls on client creation @@ -28280,30 +28896,38 @@ def test_get_grpc_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_grpc_route in client._transport._wrapped_methods + assert ( + client._transport.delete_wasm_plugin in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_grpc_route] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_wasm_plugin] = ( + mock_rpc + ) request = {} - client.get_grpc_route(request) + client.delete_wasm_plugin(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_grpc_route(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_wasm_plugin(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_grpc_route_rest_required_fields( - request_type=grpc_route.GetGrpcRouteRequest, +def test_delete_wasm_plugin_rest_required_fields( + request_type=extensibility.DeleteWasmPluginRequest, ): transport_class = transports.NetworkServicesRestTransport @@ -28319,7 +28943,7 @@ def test_get_grpc_route_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_grpc_route._get_unset_required_fields(jsonified_request) + ).delete_wasm_plugin._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -28328,7 +28952,7 @@ def test_get_grpc_route_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_grpc_route._get_unset_required_fields(jsonified_request) + ).delete_wasm_plugin._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -28342,7 +28966,7 @@ def test_get_grpc_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = grpc_route.GrpcRoute() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -28354,39 +28978,36 @@ def test_get_grpc_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "delete", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = grpc_route.GrpcRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_grpc_route(request) + response = client.delete_wasm_plugin(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_grpc_route_rest_unset_required_fields(): +def test_delete_wasm_plugin_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_grpc_route._get_unset_required_fields({}) + unset_fields = transport.delete_wasm_plugin._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_grpc_route_rest_flattened(): +def test_delete_wasm_plugin_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -28395,11 +29016,11 @@ def test_get_grpc_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = grpc_route.GrpcRoute() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/grpcRoutes/sample3" + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" } # get truthy value for each flattened field @@ -28411,26 +29032,25 @@ def test_get_grpc_route_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = grpc_route.GrpcRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_grpc_route(**mock_args) + client.delete_wasm_plugin(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/grpcRoutes/*}" % client.transport._host, + "%s/v1/{name=projects/*/locations/*/wasmPlugins/*}" + % client.transport._host, args[1], ) -def test_get_grpc_route_rest_flattened_error(transport: str = "rest"): +def test_delete_wasm_plugin_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -28439,13 +29059,13 @@ def test_get_grpc_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_grpc_route( - grpc_route.GetGrpcRouteRequest(), + client.delete_wasm_plugin( + extensibility.DeleteWasmPluginRequest(), name="name_value", ) -def test_create_grpc_route_rest_use_cached_wrapped_rpc(): +def test_list_gateways_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -28459,42 +29079,33 @@ def test_create_grpc_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_grpc_route in client._transport._wrapped_methods + assert client._transport.list_gateways in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_grpc_route] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.list_gateways] = mock_rpc request = {} - client.create_grpc_route(request) + client.list_gateways(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_grpc_route(request) + client.list_gateways(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_grpc_route_rest_required_fields( - request_type=gcn_grpc_route.CreateGrpcRouteRequest, -): +def test_list_gateways_rest_required_fields(request_type=gateway.ListGatewaysRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" - request_init["grpc_route_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -28502,32 +29113,31 @@ def test_create_grpc_route_rest_required_fields( ) # verify fields with default values are dropped - assert "grpcRouteId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_grpc_route._get_unset_required_fields(jsonified_request) + ).list_gateways._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "grpcRouteId" in jsonified_request - assert jsonified_request["grpcRouteId"] == request_init["grpc_route_id"] jsonified_request["parent"] = "parent_value" - jsonified_request["grpcRouteId"] = "grpc_route_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_grpc_route._get_unset_required_fields(jsonified_request) + ).list_gateways._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("grpc_route_id",)) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "grpcRouteId" in jsonified_request - assert jsonified_request["grpcRouteId"] == "grpc_route_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -28536,7 +29146,7 @@ def test_create_grpc_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = gateway.ListGatewaysResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -28548,52 +29158,47 @@ def test_create_grpc_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = gateway.ListGatewaysResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_grpc_route(request) + response = client.list_gateways(request) - expected_params = [ - ( - "grpcRouteId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_grpc_route_rest_unset_required_fields(): +def test_list_gateways_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_grpc_route._get_unset_required_fields({}) + unset_fields = transport.list_gateways._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("grpcRouteId",)) - & set( + set( ( - "parent", - "grpcRouteId", - "grpcRoute", + "pageSize", + "pageToken", ) ) + & set(("parent",)) ) -def test_create_grpc_route_rest_flattened(): +def test_list_gateways_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -28602,7 +29207,7 @@ def test_create_grpc_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = gateway.ListGatewaysResponse() # get arguments that satisfy an http rule for this method sample_request = {"parent": "projects/sample1/locations/sample2"} @@ -28610,32 +29215,32 @@ def test_create_grpc_route_rest_flattened(): # get truthy value for each flattened field mock_args = dict( parent="parent_value", - grpc_route=gcn_grpc_route.GrpcRoute(name="name_value"), - grpc_route_id="grpc_route_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = gateway.ListGatewaysResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_grpc_route(**mock_args) + client.list_gateways(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/grpcRoutes" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/gateways" % client.transport._host, args[1], ) -def test_create_grpc_route_rest_flattened_error(transport: str = "rest"): +def test_list_gateways_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -28644,15 +29249,74 @@ def test_create_grpc_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_grpc_route( - gcn_grpc_route.CreateGrpcRouteRequest(), + client.list_gateways( + gateway.ListGatewaysRequest(), parent="parent_value", - grpc_route=gcn_grpc_route.GrpcRoute(name="name_value"), - grpc_route_id="grpc_route_id_value", ) -def test_update_grpc_route_rest_use_cached_wrapped_rpc(): +def test_list_gateways_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + gateway.ListGatewaysResponse( + gateways=[ + gateway.Gateway(), + gateway.Gateway(), + gateway.Gateway(), + ], + next_page_token="abc", + ), + gateway.ListGatewaysResponse( + gateways=[], + next_page_token="def", + ), + gateway.ListGatewaysResponse( + gateways=[ + gateway.Gateway(), + ], + next_page_token="ghi", + ), + gateway.ListGatewaysResponse( + gateways=[ + gateway.Gateway(), + gateway.Gateway(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(gateway.ListGatewaysResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_gateways(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, gateway.Gateway) for i in results) + + pages = list(client.list_gateways(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_gateway_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -28666,40 +29330,33 @@ def test_update_grpc_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_grpc_route in client._transport._wrapped_methods + assert client._transport.get_gateway in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_grpc_route] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.get_gateway] = mock_rpc request = {} - client.update_grpc_route(request) + client.get_gateway(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_grpc_route(request) + client.get_gateway(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_grpc_route_rest_required_fields( - request_type=gcn_grpc_route.UpdateGrpcRouteRequest, -): +def test_get_gateway_rest_required_fields(request_type=gateway.GetGatewayRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -28710,19 +29367,21 @@ def test_update_grpc_route_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_grpc_route._get_unset_required_fields(jsonified_request) + ).get_gateway._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_grpc_route._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + ).get_gateway._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -28731,7 +29390,7 @@ def test_update_grpc_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = gateway.Gateway() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -28743,37 +29402,39 @@ def test_update_grpc_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = gateway.Gateway.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_grpc_route(request) + response = client.get_gateway(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_update_grpc_route_rest_unset_required_fields(): +def test_get_gateway_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_grpc_route._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("grpcRoute",))) + unset_fields = transport.get_gateway._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_update_grpc_route_rest_flattened(): +def test_get_gateway_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -28782,44 +29443,40 @@ def test_update_grpc_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = gateway.Gateway() # get arguments that satisfy an http rule for this method - sample_request = { - "grpc_route": { - "name": "projects/sample1/locations/sample2/grpcRoutes/sample3" - } - } + sample_request = {"name": "projects/sample1/locations/sample2/gateways/sample3"} # get truthy value for each flattened field mock_args = dict( - grpc_route=gcn_grpc_route.GrpcRoute(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = gateway.Gateway.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_grpc_route(**mock_args) + client.get_gateway(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{grpc_route.name=projects/*/locations/*/grpcRoutes/*}" - % client.transport._host, + "%s/v1/{name=projects/*/locations/*/gateways/*}" % client.transport._host, args[1], ) -def test_update_grpc_route_rest_flattened_error(transport: str = "rest"): +def test_get_gateway_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -28828,14 +29485,13 @@ def test_update_grpc_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_grpc_route( - gcn_grpc_route.UpdateGrpcRouteRequest(), - grpc_route=gcn_grpc_route.GrpcRoute(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_gateway( + gateway.GetGatewayRequest(), + name="name_value", ) -def test_delete_grpc_route_rest_use_cached_wrapped_rpc(): +def test_create_gateway_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -28849,19 +29505,17 @@ def test_delete_grpc_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_grpc_route in client._transport._wrapped_methods + assert client._transport.create_gateway in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_grpc_route] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.create_gateway] = mock_rpc request = {} - client.delete_grpc_route(request) + client.create_gateway(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -28870,20 +29524,21 @@ def test_delete_grpc_route_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_grpc_route(request) + client.create_gateway(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_grpc_route_rest_required_fields( - request_type=grpc_route.DeleteGrpcRouteRequest, +def test_create_gateway_rest_required_fields( + request_type=gcn_gateway.CreateGatewayRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["gateway_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -28891,24 +29546,32 @@ def test_delete_grpc_route_rest_required_fields( ) # verify fields with default values are dropped + assert "gatewayId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_grpc_route._get_unset_required_fields(jsonified_request) + ).create_gateway._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "gatewayId" in jsonified_request + assert jsonified_request["gatewayId"] == request_init["gateway_id"] - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["gatewayId"] = "gateway_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_grpc_route._get_unset_required_fields(jsonified_request) + ).create_gateway._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("gateway_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "gatewayId" in jsonified_request + assert jsonified_request["gatewayId"] == "gateway_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -28929,9 +29592,10 @@ def test_delete_grpc_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -28942,23 +29606,38 @@ def test_delete_grpc_route_rest_required_fields( req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_grpc_route(request) + response = client.create_gateway(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "gatewayId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_grpc_route_rest_unset_required_fields(): +def test_create_gateway_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_grpc_route._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_gateway._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("gatewayId",)) + & set( + ( + "parent", + "gatewayId", + "gateway", + ) + ) + ) -def test_delete_grpc_route_rest_flattened(): +def test_create_gateway_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -28970,13 +29649,13 @@ def test_delete_grpc_route_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/grpcRoutes/sample3" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + gateway=gcn_gateway.Gateway(name="name_value"), + gateway_id="gateway_id_value", ) mock_args.update(sample_request) @@ -28988,19 +29667,19 @@ def test_delete_grpc_route_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_grpc_route(**mock_args) + client.create_gateway(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/grpcRoutes/*}" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/gateways" % client.transport._host, args[1], ) -def test_delete_grpc_route_rest_flattened_error(transport: str = "rest"): +def test_create_gateway_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -29009,13 +29688,15 @@ def test_delete_grpc_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_grpc_route( - grpc_route.DeleteGrpcRouteRequest(), - name="name_value", + client.create_gateway( + gcn_gateway.CreateGatewayRequest(), + parent="parent_value", + gateway=gcn_gateway.Gateway(name="name_value"), + gateway_id="gateway_id_value", ) -def test_list_http_routes_rest_use_cached_wrapped_rpc(): +def test_update_gateway_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -29029,37 +29710,38 @@ def test_list_http_routes_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_http_routes in client._transport._wrapped_methods + assert client._transport.update_gateway in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_http_routes] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.update_gateway] = mock_rpc request = {} - client.list_http_routes(request) + client.update_gateway(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_http_routes(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_gateway(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_http_routes_rest_required_fields( - request_type=http_route.ListHttpRoutesRequest, +def test_update_gateway_rest_required_fields( + request_type=gcn_gateway.UpdateGatewayRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -29070,29 +29752,19 @@ def test_list_http_routes_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_http_routes._get_unset_required_fields(jsonified_request) + ).update_gateway._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_http_routes._get_unset_required_fields(jsonified_request) + ).update_gateway._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - "return_partial_success", - ) - ) + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29101,7 +29773,7 @@ def test_list_http_routes_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = http_route.ListHttpRoutesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -29113,48 +29785,37 @@ def test_list_http_routes_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = http_route.ListHttpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_http_routes(request) + response = client.update_gateway(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_http_routes_rest_unset_required_fields(): +def test_update_gateway_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_http_routes._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - "returnPartialSuccess", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.update_gateway._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("gateway",))) -def test_list_http_routes_rest_flattened(): +def test_update_gateway_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -29163,40 +29824,42 @@ def test_list_http_routes_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = http_route.ListHttpRoutesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "gateway": {"name": "projects/sample1/locations/sample2/gateways/sample3"} + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + gateway=gcn_gateway.Gateway(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = http_route.ListHttpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_http_routes(**mock_args) + client.update_gateway(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/httpRoutes" % client.transport._host, + "%s/v1/{gateway.name=projects/*/locations/*/gateways/*}" + % client.transport._host, args[1], ) -def test_list_http_routes_rest_flattened_error(transport: str = "rest"): +def test_update_gateway_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -29205,112 +29868,54 @@ def test_list_http_routes_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_http_routes( - http_route.ListHttpRoutesRequest(), - parent="parent_value", + client.update_gateway( + gcn_gateway.UpdateGatewayRequest(), + gateway=gcn_gateway.Gateway(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_list_http_routes_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - http_route.ListHttpRoutesResponse( - http_routes=[ - http_route.HttpRoute(), - http_route.HttpRoute(), - http_route.HttpRoute(), - ], - next_page_token="abc", - ), - http_route.ListHttpRoutesResponse( - http_routes=[], - next_page_token="def", - ), - http_route.ListHttpRoutesResponse( - http_routes=[ - http_route.HttpRoute(), - ], - next_page_token="ghi", - ), - http_route.ListHttpRoutesResponse( - http_routes=[ - http_route.HttpRoute(), - http_route.HttpRoute(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(http_route.ListHttpRoutesResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_http_routes(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, http_route.HttpRoute) for i in results) - - pages = list(client.list_http_routes(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -def test_get_http_route_rest_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) +def test_delete_gateway_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) # Should wrap all calls on client creation assert wrapper_fn.call_count > 0 wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_http_route in client._transport._wrapped_methods + assert client._transport.delete_gateway in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_http_route] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_gateway] = mock_rpc request = {} - client.get_http_route(request) + client.delete_gateway(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_http_route(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_gateway(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_http_route_rest_required_fields( - request_type=http_route.GetHttpRouteRequest, -): +def test_delete_gateway_rest_required_fields(request_type=gateway.DeleteGatewayRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} @@ -29325,7 +29930,7 @@ def test_get_http_route_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_http_route._get_unset_required_fields(jsonified_request) + ).delete_gateway._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -29334,7 +29939,7 @@ def test_get_http_route_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_http_route._get_unset_required_fields(jsonified_request) + ).delete_gateway._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -29348,7 +29953,7 @@ def test_get_http_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = http_route.HttpRoute() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -29360,39 +29965,36 @@ def test_get_http_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "delete", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = http_route.HttpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_http_route(request) + response = client.delete_gateway(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_http_route_rest_unset_required_fields(): +def test_delete_gateway_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_http_route._get_unset_required_fields({}) + unset_fields = transport.delete_gateway._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_http_route_rest_flattened(): +def test_delete_gateway_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -29401,12 +30003,10 @@ def test_get_http_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = http_route.HttpRoute() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/httpRoutes/sample3" - } + sample_request = {"name": "projects/sample1/locations/sample2/gateways/sample3"} # get truthy value for each flattened field mock_args = dict( @@ -29417,26 +30017,24 @@ def test_get_http_route_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = http_route.HttpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_http_route(**mock_args) + client.delete_gateway(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/httpRoutes/*}" % client.transport._host, + "%s/v1/{name=projects/*/locations/*/gateways/*}" % client.transport._host, args[1], ) -def test_get_http_route_rest_flattened_error(transport: str = "rest"): +def test_delete_gateway_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -29445,13 +30043,13 @@ def test_get_http_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_http_route( - http_route.GetHttpRouteRequest(), + client.delete_gateway( + gateway.DeleteGatewayRequest(), name="name_value", ) -def test_create_http_route_rest_use_cached_wrapped_rpc(): +def test_list_grpc_routes_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -29465,42 +30063,37 @@ def test_create_http_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_http_route in client._transport._wrapped_methods + assert client._transport.list_grpc_routes in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_http_route] = ( + client._transport._wrapped_methods[client._transport.list_grpc_routes] = ( mock_rpc ) request = {} - client.create_http_route(request) + client.list_grpc_routes(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_http_route(request) + client.list_grpc_routes(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_http_route_rest_required_fields( - request_type=gcn_http_route.CreateHttpRouteRequest, +def test_list_grpc_routes_rest_required_fields( + request_type=grpc_route.ListGrpcRoutesRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" - request_init["http_route_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -29508,32 +30101,32 @@ def test_create_http_route_rest_required_fields( ) # verify fields with default values are dropped - assert "httpRouteId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_http_route._get_unset_required_fields(jsonified_request) + ).list_grpc_routes._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "httpRouteId" in jsonified_request - assert jsonified_request["httpRouteId"] == request_init["http_route_id"] jsonified_request["parent"] = "parent_value" - jsonified_request["httpRouteId"] = "http_route_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_http_route._get_unset_required_fields(jsonified_request) + ).list_grpc_routes._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("http_route_id",)) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + "return_partial_success", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "httpRouteId" in jsonified_request - assert jsonified_request["httpRouteId"] == "http_route_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29542,7 +30135,7 @@ def test_create_http_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = grpc_route.ListGrpcRoutesResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -29554,52 +30147,48 @@ def test_create_http_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = grpc_route.ListGrpcRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_http_route(request) + response = client.list_grpc_routes(request) - expected_params = [ - ( - "httpRouteId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_http_route_rest_unset_required_fields(): +def test_list_grpc_routes_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_http_route._get_unset_required_fields({}) + unset_fields = transport.list_grpc_routes._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("httpRouteId",)) - & set( + set( ( - "parent", - "httpRouteId", - "httpRoute", + "pageSize", + "pageToken", + "returnPartialSuccess", ) ) + & set(("parent",)) ) -def test_create_http_route_rest_flattened(): +def test_list_grpc_routes_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -29608,7 +30197,7 @@ def test_create_http_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = grpc_route.ListGrpcRoutesResponse() # get arguments that satisfy an http rule for this method sample_request = {"parent": "projects/sample1/locations/sample2"} @@ -29616,32 +30205,32 @@ def test_create_http_route_rest_flattened(): # get truthy value for each flattened field mock_args = dict( parent="parent_value", - http_route=gcn_http_route.HttpRoute(name="name_value"), - http_route_id="http_route_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = grpc_route.ListGrpcRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_http_route(**mock_args) + client.list_grpc_routes(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/httpRoutes" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/grpcRoutes" % client.transport._host, args[1], ) -def test_create_http_route_rest_flattened_error(transport: str = "rest"): +def test_list_grpc_routes_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -29650,15 +30239,74 @@ def test_create_http_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_http_route( - gcn_http_route.CreateHttpRouteRequest(), + client.list_grpc_routes( + grpc_route.ListGrpcRoutesRequest(), parent="parent_value", - http_route=gcn_http_route.HttpRoute(name="name_value"), - http_route_id="http_route_id_value", ) -def test_update_http_route_rest_use_cached_wrapped_rpc(): +def test_list_grpc_routes_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + grpc_route.ListGrpcRoutesResponse( + grpc_routes=[ + grpc_route.GrpcRoute(), + grpc_route.GrpcRoute(), + grpc_route.GrpcRoute(), + ], + next_page_token="abc", + ), + grpc_route.ListGrpcRoutesResponse( + grpc_routes=[], + next_page_token="def", + ), + grpc_route.ListGrpcRoutesResponse( + grpc_routes=[ + grpc_route.GrpcRoute(), + ], + next_page_token="ghi", + ), + grpc_route.ListGrpcRoutesResponse( + grpc_routes=[ + grpc_route.GrpcRoute(), + grpc_route.GrpcRoute(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(grpc_route.ListGrpcRoutesResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_grpc_routes(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, grpc_route.GrpcRoute) for i in results) + + pages = list(client.list_grpc_routes(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_grpc_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -29672,40 +30320,35 @@ def test_update_http_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_http_route in client._transport._wrapped_methods + assert client._transport.get_grpc_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_http_route] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.get_grpc_route] = mock_rpc request = {} - client.update_http_route(request) + client.get_grpc_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_http_route(request) + client.get_grpc_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_http_route_rest_required_fields( - request_type=gcn_http_route.UpdateHttpRouteRequest, +def test_get_grpc_route_rest_required_fields( + request_type=grpc_route.GetGrpcRouteRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -29716,19 +30359,21 @@ def test_update_http_route_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_http_route._get_unset_required_fields(jsonified_request) + ).get_grpc_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_http_route._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + ).get_grpc_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29737,7 +30382,7 @@ def test_update_http_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = grpc_route.GrpcRoute() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -29749,37 +30394,39 @@ def test_update_http_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = grpc_route.GrpcRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_http_route(request) + response = client.get_grpc_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_update_http_route_rest_unset_required_fields(): +def test_get_grpc_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_http_route._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("httpRoute",))) + unset_fields = transport.get_grpc_route._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_update_http_route_rest_flattened(): +def test_get_grpc_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -29788,44 +30435,42 @@ def test_update_http_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = grpc_route.GrpcRoute() # get arguments that satisfy an http rule for this method sample_request = { - "http_route": { - "name": "projects/sample1/locations/sample2/httpRoutes/sample3" - } + "name": "projects/sample1/locations/sample2/grpcRoutes/sample3" } # get truthy value for each flattened field mock_args = dict( - http_route=gcn_http_route.HttpRoute(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = grpc_route.GrpcRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_http_route(**mock_args) + client.get_grpc_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{http_route.name=projects/*/locations/*/httpRoutes/*}" - % client.transport._host, + "%s/v1/{name=projects/*/locations/*/grpcRoutes/*}" % client.transport._host, args[1], ) -def test_update_http_route_rest_flattened_error(transport: str = "rest"): +def test_get_grpc_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -29834,14 +30479,13 @@ def test_update_http_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_http_route( - gcn_http_route.UpdateHttpRouteRequest(), - http_route=gcn_http_route.HttpRoute(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_grpc_route( + grpc_route.GetGrpcRouteRequest(), + name="name_value", ) -def test_delete_http_route_rest_use_cached_wrapped_rpc(): +def test_create_grpc_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -29855,19 +30499,19 @@ def test_delete_http_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_http_route in client._transport._wrapped_methods + assert client._transport.create_grpc_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_http_route] = ( + client._transport._wrapped_methods[client._transport.create_grpc_route] = ( mock_rpc ) request = {} - client.delete_http_route(request) + client.create_grpc_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -29876,20 +30520,21 @@ def test_delete_http_route_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_http_route(request) + client.create_grpc_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_http_route_rest_required_fields( - request_type=http_route.DeleteHttpRouteRequest, +def test_create_grpc_route_rest_required_fields( + request_type=gcn_grpc_route.CreateGrpcRouteRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["grpc_route_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -29897,24 +30542,32 @@ def test_delete_http_route_rest_required_fields( ) # verify fields with default values are dropped + assert "grpcRouteId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_http_route._get_unset_required_fields(jsonified_request) + ).create_grpc_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "grpcRouteId" in jsonified_request + assert jsonified_request["grpcRouteId"] == request_init["grpc_route_id"] - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["grpcRouteId"] = "grpc_route_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_http_route._get_unset_required_fields(jsonified_request) + ).create_grpc_route._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("grpc_route_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "grpcRouteId" in jsonified_request + assert jsonified_request["grpcRouteId"] == "grpc_route_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29935,9 +30588,10 @@ def test_delete_http_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -29948,23 +30602,38 @@ def test_delete_http_route_rest_required_fields( req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_http_route(request) + response = client.create_grpc_route(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "grpcRouteId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_http_route_rest_unset_required_fields(): +def test_create_grpc_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_http_route._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_grpc_route._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("grpcRouteId",)) + & set( + ( + "parent", + "grpcRouteId", + "grpcRoute", + ) + ) + ) -def test_delete_http_route_rest_flattened(): +def test_create_grpc_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -29976,13 +30645,13 @@ def test_delete_http_route_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/httpRoutes/sample3" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + grpc_route=gcn_grpc_route.GrpcRoute(name="name_value"), + grpc_route_id="grpc_route_id_value", ) mock_args.update(sample_request) @@ -29994,19 +30663,19 @@ def test_delete_http_route_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_http_route(**mock_args) + client.create_grpc_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/httpRoutes/*}" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/grpcRoutes" % client.transport._host, args[1], ) -def test_delete_http_route_rest_flattened_error(transport: str = "rest"): +def test_create_grpc_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -30015,13 +30684,15 @@ def test_delete_http_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_http_route( - http_route.DeleteHttpRouteRequest(), - name="name_value", + client.create_grpc_route( + gcn_grpc_route.CreateGrpcRouteRequest(), + parent="parent_value", + grpc_route=gcn_grpc_route.GrpcRoute(name="name_value"), + grpc_route_id="grpc_route_id_value", ) -def test_list_tcp_routes_rest_use_cached_wrapped_rpc(): +def test_update_grpc_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -30035,35 +30706,40 @@ def test_list_tcp_routes_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_tcp_routes in client._transport._wrapped_methods + assert client._transport.update_grpc_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_tcp_routes] = mock_rpc + client._transport._wrapped_methods[client._transport.update_grpc_route] = ( + mock_rpc + ) request = {} - client.list_tcp_routes(request) + client.update_grpc_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_tcp_routes(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_grpc_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_tcp_routes_rest_required_fields( - request_type=tcp_route.ListTcpRoutesRequest, +def test_update_grpc_route_rest_required_fields( + request_type=gcn_grpc_route.UpdateGrpcRouteRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -30074,29 +30750,19 @@ def test_list_tcp_routes_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_tcp_routes._get_unset_required_fields(jsonified_request) + ).update_grpc_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_tcp_routes._get_unset_required_fields(jsonified_request) + ).update_grpc_route._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - "return_partial_success", - ) - ) + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30105,7 +30771,7 @@ def test_list_tcp_routes_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = tcp_route.ListTcpRoutesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -30117,48 +30783,37 @@ def test_list_tcp_routes_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = tcp_route.ListTcpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_tcp_routes(request) + response = client.update_grpc_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_tcp_routes_rest_unset_required_fields(): +def test_update_grpc_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_tcp_routes._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - "returnPartialSuccess", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.update_grpc_route._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("grpcRoute",))) -def test_list_tcp_routes_rest_flattened(): +def test_update_grpc_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -30167,40 +30822,44 @@ def test_list_tcp_routes_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = tcp_route.ListTcpRoutesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "grpc_route": { + "name": "projects/sample1/locations/sample2/grpcRoutes/sample3" + } + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + grpc_route=gcn_grpc_route.GrpcRoute(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = tcp_route.ListTcpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_tcp_routes(**mock_args) + client.update_grpc_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/tcpRoutes" % client.transport._host, + "%s/v1/{grpc_route.name=projects/*/locations/*/grpcRoutes/*}" + % client.transport._host, args[1], ) -def test_list_tcp_routes_rest_flattened_error(transport: str = "rest"): +def test_update_grpc_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -30209,74 +30868,14 @@ def test_list_tcp_routes_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_tcp_routes( - tcp_route.ListTcpRoutesRequest(), - parent="parent_value", + client.update_grpc_route( + gcn_grpc_route.UpdateGrpcRouteRequest(), + grpc_route=gcn_grpc_route.GrpcRoute(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_list_tcp_routes_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - tcp_route.ListTcpRoutesResponse( - tcp_routes=[ - tcp_route.TcpRoute(), - tcp_route.TcpRoute(), - tcp_route.TcpRoute(), - ], - next_page_token="abc", - ), - tcp_route.ListTcpRoutesResponse( - tcp_routes=[], - next_page_token="def", - ), - tcp_route.ListTcpRoutesResponse( - tcp_routes=[ - tcp_route.TcpRoute(), - ], - next_page_token="ghi", - ), - tcp_route.ListTcpRoutesResponse( - tcp_routes=[ - tcp_route.TcpRoute(), - tcp_route.TcpRoute(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(tcp_route.ListTcpRoutesResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_tcp_routes(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, tcp_route.TcpRoute) for i in results) - - pages = list(client.list_tcp_routes(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -def test_get_tcp_route_rest_use_cached_wrapped_rpc(): +def test_delete_grpc_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -30290,29 +30889,37 @@ def test_get_tcp_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_tcp_route in client._transport._wrapped_methods + assert client._transport.delete_grpc_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_tcp_route] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_grpc_route] = ( + mock_rpc + ) request = {} - client.get_tcp_route(request) + client.delete_grpc_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_tcp_route(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_grpc_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_tcp_route_rest_required_fields(request_type=tcp_route.GetTcpRouteRequest): +def test_delete_grpc_route_rest_required_fields( + request_type=grpc_route.DeleteGrpcRouteRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} @@ -30327,7 +30934,7 @@ def test_get_tcp_route_rest_required_fields(request_type=tcp_route.GetTcpRouteRe unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_tcp_route._get_unset_required_fields(jsonified_request) + ).delete_grpc_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -30336,7 +30943,7 @@ def test_get_tcp_route_rest_required_fields(request_type=tcp_route.GetTcpRouteRe unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_tcp_route._get_unset_required_fields(jsonified_request) + ).delete_grpc_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -30350,7 +30957,7 @@ def test_get_tcp_route_rest_required_fields(request_type=tcp_route.GetTcpRouteRe request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = tcp_route.TcpRoute() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -30362,39 +30969,36 @@ def test_get_tcp_route_rest_required_fields(request_type=tcp_route.GetTcpRouteRe pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "delete", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = tcp_route.TcpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_tcp_route(request) + response = client.delete_grpc_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_tcp_route_rest_unset_required_fields(): +def test_delete_grpc_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_tcp_route._get_unset_required_fields({}) + unset_fields = transport.delete_grpc_route._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_tcp_route_rest_flattened(): +def test_delete_grpc_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -30403,11 +31007,11 @@ def test_get_tcp_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = tcp_route.TcpRoute() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/tcpRoutes/sample3" + "name": "projects/sample1/locations/sample2/grpcRoutes/sample3" } # get truthy value for each flattened field @@ -30419,26 +31023,24 @@ def test_get_tcp_route_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = tcp_route.TcpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_tcp_route(**mock_args) + client.delete_grpc_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/tcpRoutes/*}" % client.transport._host, + "%s/v1/{name=projects/*/locations/*/grpcRoutes/*}" % client.transport._host, args[1], ) -def test_get_tcp_route_rest_flattened_error(transport: str = "rest"): +def test_delete_grpc_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -30447,13 +31049,13 @@ def test_get_tcp_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_tcp_route( - tcp_route.GetTcpRouteRequest(), + client.delete_grpc_route( + grpc_route.DeleteGrpcRouteRequest(), name="name_value", ) -def test_create_tcp_route_rest_use_cached_wrapped_rpc(): +def test_list_http_routes_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -30467,42 +31069,37 @@ def test_create_tcp_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_tcp_route in client._transport._wrapped_methods + assert client._transport.list_http_routes in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_tcp_route] = ( + client._transport._wrapped_methods[client._transport.list_http_routes] = ( mock_rpc ) request = {} - client.create_tcp_route(request) + client.list_http_routes(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_tcp_route(request) + client.list_http_routes(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_tcp_route_rest_required_fields( - request_type=gcn_tcp_route.CreateTcpRouteRequest, +def test_list_http_routes_rest_required_fields( + request_type=http_route.ListHttpRoutesRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" - request_init["tcp_route_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -30510,32 +31107,33 @@ def test_create_tcp_route_rest_required_fields( ) # verify fields with default values are dropped - assert "tcpRouteId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_tcp_route._get_unset_required_fields(jsonified_request) + ).list_http_routes._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "tcpRouteId" in jsonified_request - assert jsonified_request["tcpRouteId"] == request_init["tcp_route_id"] jsonified_request["parent"] = "parent_value" - jsonified_request["tcpRouteId"] = "tcp_route_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_tcp_route._get_unset_required_fields(jsonified_request) + ).list_http_routes._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("tcp_route_id",)) + assert not set(unset_fields) - set( + ( + "filter", + "page_size", + "page_token", + "return_partial_success", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "tcpRouteId" in jsonified_request - assert jsonified_request["tcpRouteId"] == "tcp_route_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30544,7 +31142,7 @@ def test_create_tcp_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = http_route.ListHttpRoutesResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -30556,52 +31154,49 @@ def test_create_tcp_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = http_route.ListHttpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_tcp_route(request) + response = client.list_http_routes(request) - expected_params = [ - ( - "tcpRouteId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_tcp_route_rest_unset_required_fields(): +def test_list_http_routes_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_tcp_route._get_unset_required_fields({}) + unset_fields = transport.list_http_routes._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("tcpRouteId",)) - & set( + set( ( - "parent", - "tcpRouteId", - "tcpRoute", + "filter", + "pageSize", + "pageToken", + "returnPartialSuccess", ) ) + & set(("parent",)) ) -def test_create_tcp_route_rest_flattened(): +def test_list_http_routes_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -30610,7 +31205,7 @@ def test_create_tcp_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = http_route.ListHttpRoutesResponse() # get arguments that satisfy an http rule for this method sample_request = {"parent": "projects/sample1/locations/sample2"} @@ -30618,32 +31213,32 @@ def test_create_tcp_route_rest_flattened(): # get truthy value for each flattened field mock_args = dict( parent="parent_value", - tcp_route=gcn_tcp_route.TcpRoute(name="name_value"), - tcp_route_id="tcp_route_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = http_route.ListHttpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_tcp_route(**mock_args) + client.list_http_routes(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/tcpRoutes" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/httpRoutes" % client.transport._host, args[1], ) -def test_create_tcp_route_rest_flattened_error(transport: str = "rest"): +def test_list_http_routes_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -30652,15 +31247,74 @@ def test_create_tcp_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_tcp_route( - gcn_tcp_route.CreateTcpRouteRequest(), + client.list_http_routes( + http_route.ListHttpRoutesRequest(), parent="parent_value", - tcp_route=gcn_tcp_route.TcpRoute(name="name_value"), - tcp_route_id="tcp_route_id_value", ) -def test_update_tcp_route_rest_use_cached_wrapped_rpc(): +def test_list_http_routes_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + http_route.ListHttpRoutesResponse( + http_routes=[ + http_route.HttpRoute(), + http_route.HttpRoute(), + http_route.HttpRoute(), + ], + next_page_token="abc", + ), + http_route.ListHttpRoutesResponse( + http_routes=[], + next_page_token="def", + ), + http_route.ListHttpRoutesResponse( + http_routes=[ + http_route.HttpRoute(), + ], + next_page_token="ghi", + ), + http_route.ListHttpRoutesResponse( + http_routes=[ + http_route.HttpRoute(), + http_route.HttpRoute(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(http_route.ListHttpRoutesResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_http_routes(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, http_route.HttpRoute) for i in results) + + pages = list(client.list_http_routes(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_http_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -30674,40 +31328,35 @@ def test_update_tcp_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_tcp_route in client._transport._wrapped_methods + assert client._transport.get_http_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_tcp_route] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.get_http_route] = mock_rpc request = {} - client.update_tcp_route(request) + client.get_http_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_tcp_route(request) + client.get_http_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_tcp_route_rest_required_fields( - request_type=gcn_tcp_route.UpdateTcpRouteRequest, +def test_get_http_route_rest_required_fields( + request_type=http_route.GetHttpRouteRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -30718,19 +31367,21 @@ def test_update_tcp_route_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_tcp_route._get_unset_required_fields(jsonified_request) + ).get_http_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_tcp_route._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + ).get_http_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30739,7 +31390,7 @@ def test_update_tcp_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = http_route.HttpRoute() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -30751,37 +31402,39 @@ def test_update_tcp_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = http_route.HttpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_tcp_route(request) + response = client.get_http_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_update_tcp_route_rest_unset_required_fields(): +def test_get_http_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_tcp_route._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("tcpRoute",))) + unset_fields = transport.get_http_route._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_update_tcp_route_rest_flattened(): +def test_get_http_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -30790,44 +31443,42 @@ def test_update_tcp_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = http_route.HttpRoute() # get arguments that satisfy an http rule for this method sample_request = { - "tcp_route": { - "name": "projects/sample1/locations/sample2/tcpRoutes/sample3" - } + "name": "projects/sample1/locations/sample2/httpRoutes/sample3" } # get truthy value for each flattened field mock_args = dict( - tcp_route=gcn_tcp_route.TcpRoute(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = http_route.HttpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_tcp_route(**mock_args) + client.get_http_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{tcp_route.name=projects/*/locations/*/tcpRoutes/*}" - % client.transport._host, + "%s/v1/{name=projects/*/locations/*/httpRoutes/*}" % client.transport._host, args[1], ) -def test_update_tcp_route_rest_flattened_error(transport: str = "rest"): +def test_get_http_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -30836,14 +31487,13 @@ def test_update_tcp_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_tcp_route( - gcn_tcp_route.UpdateTcpRouteRequest(), - tcp_route=gcn_tcp_route.TcpRoute(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_http_route( + http_route.GetHttpRouteRequest(), + name="name_value", ) -def test_delete_tcp_route_rest_use_cached_wrapped_rpc(): +def test_create_http_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -30857,19 +31507,19 @@ def test_delete_tcp_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_tcp_route in client._transport._wrapped_methods + assert client._transport.create_http_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_tcp_route] = ( + client._transport._wrapped_methods[client._transport.create_http_route] = ( mock_rpc ) request = {} - client.delete_tcp_route(request) + client.create_http_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -30878,20 +31528,21 @@ def test_delete_tcp_route_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_tcp_route(request) + client.create_http_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_tcp_route_rest_required_fields( - request_type=tcp_route.DeleteTcpRouteRequest, +def test_create_http_route_rest_required_fields( + request_type=gcn_http_route.CreateHttpRouteRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["http_route_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -30899,24 +31550,37 @@ def test_delete_tcp_route_rest_required_fields( ) # verify fields with default values are dropped + assert "httpRouteId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_tcp_route._get_unset_required_fields(jsonified_request) + ).create_http_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "httpRouteId" in jsonified_request + assert jsonified_request["httpRouteId"] == request_init["http_route_id"] - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["httpRouteId"] = "http_route_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_tcp_route._get_unset_required_fields(jsonified_request) + ).create_http_route._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "http_route_id", + "request_id", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "httpRouteId" in jsonified_request + assert jsonified_request["httpRouteId"] == "http_route_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30937,9 +31601,10 @@ def test_delete_tcp_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -30950,23 +31615,43 @@ def test_delete_tcp_route_rest_required_fields( req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_tcp_route(request) + response = client.create_http_route(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "httpRouteId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_tcp_route_rest_unset_required_fields(): +def test_create_http_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_tcp_route._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_http_route._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "httpRouteId", + "requestId", + ) + ) + & set( + ( + "parent", + "httpRouteId", + "httpRoute", + ) + ) + ) -def test_delete_tcp_route_rest_flattened(): +def test_create_http_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -30978,13 +31663,13 @@ def test_delete_tcp_route_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/tcpRoutes/sample3" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + http_route=gcn_http_route.HttpRoute(name="name_value"), + http_route_id="http_route_id_value", ) mock_args.update(sample_request) @@ -30996,19 +31681,19 @@ def test_delete_tcp_route_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_tcp_route(**mock_args) + client.create_http_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/tcpRoutes/*}" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/httpRoutes" % client.transport._host, args[1], ) -def test_delete_tcp_route_rest_flattened_error(transport: str = "rest"): +def test_create_http_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -31017,13 +31702,15 @@ def test_delete_tcp_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_tcp_route( - tcp_route.DeleteTcpRouteRequest(), - name="name_value", + client.create_http_route( + gcn_http_route.CreateHttpRouteRequest(), + parent="parent_value", + http_route=gcn_http_route.HttpRoute(name="name_value"), + http_route_id="http_route_id_value", ) -def test_list_tls_routes_rest_use_cached_wrapped_rpc(): +def test_update_http_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -31037,35 +31724,40 @@ def test_list_tls_routes_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_tls_routes in client._transport._wrapped_methods + assert client._transport.update_http_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_tls_routes] = mock_rpc + client._transport._wrapped_methods[client._transport.update_http_route] = ( + mock_rpc + ) request = {} - client.list_tls_routes(request) + client.update_http_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_tls_routes(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_http_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_tls_routes_rest_required_fields( - request_type=tls_route.ListTlsRoutesRequest, +def test_update_http_route_rest_required_fields( + request_type=gcn_http_route.UpdateHttpRouteRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -31076,29 +31768,19 @@ def test_list_tls_routes_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_tls_routes._get_unset_required_fields(jsonified_request) + ).update_http_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_tls_routes._get_unset_required_fields(jsonified_request) + ).update_http_route._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - "return_partial_success", - ) - ) + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31107,7 +31789,7 @@ def test_list_tls_routes_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = tls_route.ListTlsRoutesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -31119,48 +31801,37 @@ def test_list_tls_routes_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = tls_route.ListTlsRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_tls_routes(request) + response = client.update_http_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_tls_routes_rest_unset_required_fields(): +def test_update_http_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_tls_routes._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - "returnPartialSuccess", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.update_http_route._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("httpRoute",))) -def test_list_tls_routes_rest_flattened(): +def test_update_http_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -31169,40 +31840,44 @@ def test_list_tls_routes_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = tls_route.ListTlsRoutesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "http_route": { + "name": "projects/sample1/locations/sample2/httpRoutes/sample3" + } + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + http_route=gcn_http_route.HttpRoute(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = tls_route.ListTlsRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_tls_routes(**mock_args) + client.update_http_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/tlsRoutes" % client.transport._host, + "%s/v1/{http_route.name=projects/*/locations/*/httpRoutes/*}" + % client.transport._host, args[1], ) -def test_list_tls_routes_rest_flattened_error(transport: str = "rest"): +def test_update_http_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -31211,74 +31886,14 @@ def test_list_tls_routes_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_tls_routes( - tls_route.ListTlsRoutesRequest(), - parent="parent_value", - ) - - -def test_list_tls_routes_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - tls_route.ListTlsRoutesResponse( - tls_routes=[ - tls_route.TlsRoute(), - tls_route.TlsRoute(), - tls_route.TlsRoute(), - ], - next_page_token="abc", - ), - tls_route.ListTlsRoutesResponse( - tls_routes=[], - next_page_token="def", - ), - tls_route.ListTlsRoutesResponse( - tls_routes=[ - tls_route.TlsRoute(), - ], - next_page_token="ghi", - ), - tls_route.ListTlsRoutesResponse( - tls_routes=[ - tls_route.TlsRoute(), - tls_route.TlsRoute(), - ], - ), + client.update_http_route( + gcn_http_route.UpdateHttpRouteRequest(), + http_route=gcn_http_route.HttpRoute(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(tls_route.ListTlsRoutesResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_tls_routes(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, tls_route.TlsRoute) for i in results) - - pages = list(client.list_tls_routes(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_get_tls_route_rest_use_cached_wrapped_rpc(): +def test_delete_http_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -31292,29 +31907,37 @@ def test_get_tls_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_tls_route in client._transport._wrapped_methods + assert client._transport.delete_http_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_tls_route] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_http_route] = ( + mock_rpc + ) request = {} - client.get_tls_route(request) + client.delete_http_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_tls_route(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_http_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_tls_route_rest_required_fields(request_type=tls_route.GetTlsRouteRequest): +def test_delete_http_route_rest_required_fields( + request_type=http_route.DeleteHttpRouteRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} @@ -31329,7 +31952,7 @@ def test_get_tls_route_rest_required_fields(request_type=tls_route.GetTlsRouteRe unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_tls_route._get_unset_required_fields(jsonified_request) + ).delete_http_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -31338,7 +31961,7 @@ def test_get_tls_route_rest_required_fields(request_type=tls_route.GetTlsRouteRe unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_tls_route._get_unset_required_fields(jsonified_request) + ).delete_http_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -31352,7 +31975,7 @@ def test_get_tls_route_rest_required_fields(request_type=tls_route.GetTlsRouteRe request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = tls_route.TlsRoute() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -31364,39 +31987,36 @@ def test_get_tls_route_rest_required_fields(request_type=tls_route.GetTlsRouteRe pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "delete", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = tls_route.TlsRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_tls_route(request) + response = client.delete_http_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_tls_route_rest_unset_required_fields(): +def test_delete_http_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_tls_route._get_unset_required_fields({}) + unset_fields = transport.delete_http_route._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_tls_route_rest_flattened(): +def test_delete_http_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -31405,11 +32025,11 @@ def test_get_tls_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = tls_route.TlsRoute() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/tlsRoutes/sample3" + "name": "projects/sample1/locations/sample2/httpRoutes/sample3" } # get truthy value for each flattened field @@ -31421,26 +32041,24 @@ def test_get_tls_route_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = tls_route.TlsRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_tls_route(**mock_args) + client.delete_http_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/tlsRoutes/*}" % client.transport._host, + "%s/v1/{name=projects/*/locations/*/httpRoutes/*}" % client.transport._host, args[1], ) -def test_get_tls_route_rest_flattened_error(transport: str = "rest"): +def test_delete_http_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -31449,13 +32067,13 @@ def test_get_tls_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_tls_route( - tls_route.GetTlsRouteRequest(), + client.delete_http_route( + http_route.DeleteHttpRouteRequest(), name="name_value", ) -def test_create_tls_route_rest_use_cached_wrapped_rpc(): +def test_list_tcp_routes_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -31469,42 +32087,35 @@ def test_create_tls_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_tls_route in client._transport._wrapped_methods + assert client._transport.list_tcp_routes in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_tls_route] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.list_tcp_routes] = mock_rpc request = {} - client.create_tls_route(request) + client.list_tcp_routes(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_tls_route(request) + client.list_tcp_routes(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_tls_route_rest_required_fields( - request_type=gcn_tls_route.CreateTlsRouteRequest, +def test_list_tcp_routes_rest_required_fields( + request_type=tcp_route.ListTcpRoutesRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" - request_init["tls_route_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -31512,32 +32123,32 @@ def test_create_tls_route_rest_required_fields( ) # verify fields with default values are dropped - assert "tlsRouteId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_tls_route._get_unset_required_fields(jsonified_request) + ).list_tcp_routes._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "tlsRouteId" in jsonified_request - assert jsonified_request["tlsRouteId"] == request_init["tls_route_id"] jsonified_request["parent"] = "parent_value" - jsonified_request["tlsRouteId"] = "tls_route_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_tls_route._get_unset_required_fields(jsonified_request) + ).list_tcp_routes._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("tls_route_id",)) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + "return_partial_success", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "tlsRouteId" in jsonified_request - assert jsonified_request["tlsRouteId"] == "tls_route_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31546,7 +32157,7 @@ def test_create_tls_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = tcp_route.ListTcpRoutesResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -31558,52 +32169,48 @@ def test_create_tls_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = tcp_route.ListTcpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_tls_route(request) + response = client.list_tcp_routes(request) - expected_params = [ - ( - "tlsRouteId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_tls_route_rest_unset_required_fields(): +def test_list_tcp_routes_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_tls_route._get_unset_required_fields({}) + unset_fields = transport.list_tcp_routes._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("tlsRouteId",)) - & set( + set( ( - "parent", - "tlsRouteId", - "tlsRoute", + "pageSize", + "pageToken", + "returnPartialSuccess", ) ) + & set(("parent",)) ) -def test_create_tls_route_rest_flattened(): +def test_list_tcp_routes_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -31612,7 +32219,7 @@ def test_create_tls_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = tcp_route.ListTcpRoutesResponse() # get arguments that satisfy an http rule for this method sample_request = {"parent": "projects/sample1/locations/sample2"} @@ -31620,32 +32227,32 @@ def test_create_tls_route_rest_flattened(): # get truthy value for each flattened field mock_args = dict( parent="parent_value", - tls_route=gcn_tls_route.TlsRoute(name="name_value"), - tls_route_id="tls_route_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = tcp_route.ListTcpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_tls_route(**mock_args) + client.list_tcp_routes(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/tlsRoutes" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/tcpRoutes" % client.transport._host, args[1], ) -def test_create_tls_route_rest_flattened_error(transport: str = "rest"): +def test_list_tcp_routes_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -31654,15 +32261,74 @@ def test_create_tls_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_tls_route( - gcn_tls_route.CreateTlsRouteRequest(), + client.list_tcp_routes( + tcp_route.ListTcpRoutesRequest(), parent="parent_value", - tls_route=gcn_tls_route.TlsRoute(name="name_value"), - tls_route_id="tls_route_id_value", ) -def test_update_tls_route_rest_use_cached_wrapped_rpc(): +def test_list_tcp_routes_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + tcp_route.ListTcpRoutesResponse( + tcp_routes=[ + tcp_route.TcpRoute(), + tcp_route.TcpRoute(), + tcp_route.TcpRoute(), + ], + next_page_token="abc", + ), + tcp_route.ListTcpRoutesResponse( + tcp_routes=[], + next_page_token="def", + ), + tcp_route.ListTcpRoutesResponse( + tcp_routes=[ + tcp_route.TcpRoute(), + ], + next_page_token="ghi", + ), + tcp_route.ListTcpRoutesResponse( + tcp_routes=[ + tcp_route.TcpRoute(), + tcp_route.TcpRoute(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(tcp_route.ListTcpRoutesResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_tcp_routes(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, tcp_route.TcpRoute) for i in results) + + pages = list(client.list_tcp_routes(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_tcp_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -31676,40 +32342,33 @@ def test_update_tls_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_tls_route in client._transport._wrapped_methods + assert client._transport.get_tcp_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_tls_route] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.get_tcp_route] = mock_rpc request = {} - client.update_tls_route(request) + client.get_tcp_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_tls_route(request) + client.get_tcp_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_tls_route_rest_required_fields( - request_type=gcn_tls_route.UpdateTlsRouteRequest, -): +def test_get_tcp_route_rest_required_fields(request_type=tcp_route.GetTcpRouteRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -31720,19 +32379,21 @@ def test_update_tls_route_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_tls_route._get_unset_required_fields(jsonified_request) + ).get_tcp_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_tls_route._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + ).get_tcp_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31741,7 +32402,7 @@ def test_update_tls_route_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = tcp_route.TcpRoute() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -31753,37 +32414,39 @@ def test_update_tls_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = tcp_route.TcpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_tls_route(request) + response = client.get_tcp_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_update_tls_route_rest_unset_required_fields(): +def test_get_tcp_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_tls_route._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("tlsRoute",))) + unset_fields = transport.get_tcp_route._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_update_tls_route_rest_flattened(): +def test_get_tcp_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -31792,44 +32455,42 @@ def test_update_tls_route_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = tcp_route.TcpRoute() # get arguments that satisfy an http rule for this method sample_request = { - "tls_route": { - "name": "projects/sample1/locations/sample2/tlsRoutes/sample3" - } + "name": "projects/sample1/locations/sample2/tcpRoutes/sample3" } # get truthy value for each flattened field mock_args = dict( - tls_route=gcn_tls_route.TlsRoute(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = tcp_route.TcpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_tls_route(**mock_args) + client.get_tcp_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{tls_route.name=projects/*/locations/*/tlsRoutes/*}" - % client.transport._host, + "%s/v1/{name=projects/*/locations/*/tcpRoutes/*}" % client.transport._host, args[1], ) -def test_update_tls_route_rest_flattened_error(transport: str = "rest"): +def test_get_tcp_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -31838,14 +32499,13 @@ def test_update_tls_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_tls_route( - gcn_tls_route.UpdateTlsRouteRequest(), - tls_route=gcn_tls_route.TlsRoute(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_tcp_route( + tcp_route.GetTcpRouteRequest(), + name="name_value", ) -def test_delete_tls_route_rest_use_cached_wrapped_rpc(): +def test_create_tcp_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -31859,19 +32519,19 @@ def test_delete_tls_route_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_tls_route in client._transport._wrapped_methods + assert client._transport.create_tcp_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_tls_route] = ( + client._transport._wrapped_methods[client._transport.create_tcp_route] = ( mock_rpc ) request = {} - client.delete_tls_route(request) + client.create_tcp_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -31880,20 +32540,21 @@ def test_delete_tls_route_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_tls_route(request) + client.create_tcp_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_tls_route_rest_required_fields( - request_type=tls_route.DeleteTlsRouteRequest, +def test_create_tcp_route_rest_required_fields( + request_type=gcn_tcp_route.CreateTcpRouteRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["tcp_route_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -31901,24 +32562,32 @@ def test_delete_tls_route_rest_required_fields( ) # verify fields with default values are dropped + assert "tcpRouteId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_tls_route._get_unset_required_fields(jsonified_request) + ).create_tcp_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "tcpRouteId" in jsonified_request + assert jsonified_request["tcpRouteId"] == request_init["tcp_route_id"] - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["tcpRouteId"] = "tcp_route_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_tls_route._get_unset_required_fields(jsonified_request) + ).create_tcp_route._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("tcp_route_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "tcpRouteId" in jsonified_request + assert jsonified_request["tcpRouteId"] == "tcp_route_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31939,9 +32608,10 @@ def test_delete_tls_route_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -31952,23 +32622,38 @@ def test_delete_tls_route_rest_required_fields( req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_tls_route(request) + response = client.create_tcp_route(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "tcpRouteId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_tls_route_rest_unset_required_fields(): +def test_create_tcp_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_tls_route._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_tcp_route._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("tcpRouteId",)) + & set( + ( + "parent", + "tcpRouteId", + "tcpRoute", + ) + ) + ) -def test_delete_tls_route_rest_flattened(): +def test_create_tcp_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -31980,13 +32665,13 @@ def test_delete_tls_route_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/tlsRoutes/sample3" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + tcp_route=gcn_tcp_route.TcpRoute(name="name_value"), + tcp_route_id="tcp_route_id_value", ) mock_args.update(sample_request) @@ -31998,19 +32683,19 @@ def test_delete_tls_route_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_tls_route(**mock_args) + client.create_tcp_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/tlsRoutes/*}" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/tcpRoutes" % client.transport._host, args[1], ) -def test_delete_tls_route_rest_flattened_error(transport: str = "rest"): +def test_create_tcp_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -32019,13 +32704,15 @@ def test_delete_tls_route_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_tls_route( - tls_route.DeleteTlsRouteRequest(), - name="name_value", + client.create_tcp_route( + gcn_tcp_route.CreateTcpRouteRequest(), + parent="parent_value", + tcp_route=gcn_tcp_route.TcpRoute(name="name_value"), + tcp_route_id="tcp_route_id_value", ) -def test_list_service_bindings_rest_use_cached_wrapped_rpc(): +def test_update_tcp_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -32039,40 +32726,40 @@ def test_list_service_bindings_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.list_service_bindings - in client._transport._wrapped_methods - ) + assert client._transport.update_tcp_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_service_bindings] = ( + client._transport._wrapped_methods[client._transport.update_tcp_route] = ( mock_rpc ) request = {} - client.list_service_bindings(request) + client.update_tcp_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_service_bindings(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_tcp_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_service_bindings_rest_required_fields( - request_type=service_binding.ListServiceBindingsRequest, +def test_update_tcp_route_rest_required_fields( + request_type=gcn_tcp_route.UpdateTcpRouteRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -32083,28 +32770,19 @@ def test_list_service_bindings_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_service_bindings._get_unset_required_fields(jsonified_request) + ).update_tcp_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_service_bindings._get_unset_required_fields(jsonified_request) + ).update_tcp_route._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -32113,7 +32791,7 @@ def test_list_service_bindings_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = service_binding.ListServiceBindingsResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -32125,47 +32803,37 @@ def test_list_service_bindings_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = service_binding.ListServiceBindingsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_service_bindings(request) + response = client.update_tcp_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_service_bindings_rest_unset_required_fields(): +def test_update_tcp_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_service_bindings._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.update_tcp_route._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("tcpRoute",))) -def test_list_service_bindings_rest_flattened(): +def test_update_tcp_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -32174,41 +32842,44 @@ def test_list_service_bindings_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service_binding.ListServiceBindingsResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "tcp_route": { + "name": "projects/sample1/locations/sample2/tcpRoutes/sample3" + } + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + tcp_route=gcn_tcp_route.TcpRoute(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = service_binding.ListServiceBindingsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_service_bindings(**mock_args) + client.update_tcp_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/serviceBindings" + "%s/v1/{tcp_route.name=projects/*/locations/*/tcpRoutes/*}" % client.transport._host, args[1], ) -def test_list_service_bindings_rest_flattened_error(transport: str = "rest"): +def test_update_tcp_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -32217,76 +32888,14 @@ def test_list_service_bindings_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_service_bindings( - service_binding.ListServiceBindingsRequest(), - parent="parent_value", - ) - - -def test_list_service_bindings_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - service_binding.ListServiceBindingsResponse( - service_bindings=[ - service_binding.ServiceBinding(), - service_binding.ServiceBinding(), - service_binding.ServiceBinding(), - ], - next_page_token="abc", - ), - service_binding.ListServiceBindingsResponse( - service_bindings=[], - next_page_token="def", - ), - service_binding.ListServiceBindingsResponse( - service_bindings=[ - service_binding.ServiceBinding(), - ], - next_page_token="ghi", - ), - service_binding.ListServiceBindingsResponse( - service_bindings=[ - service_binding.ServiceBinding(), - service_binding.ServiceBinding(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple( - service_binding.ListServiceBindingsResponse.to_json(x) for x in response + client.update_tcp_route( + gcn_tcp_route.UpdateTcpRouteRequest(), + tcp_route=gcn_tcp_route.TcpRoute(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_service_bindings(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, service_binding.ServiceBinding) for i in results) - - pages = list(client.list_service_bindings(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_get_service_binding_rest_use_cached_wrapped_rpc(): +def test_delete_tcp_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -32300,34 +32909,36 @@ def test_get_service_binding_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.get_service_binding in client._transport._wrapped_methods - ) + assert client._transport.delete_tcp_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_service_binding] = ( + client._transport._wrapped_methods[client._transport.delete_tcp_route] = ( mock_rpc ) request = {} - client.get_service_binding(request) + client.delete_tcp_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_service_binding(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_tcp_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_service_binding_rest_required_fields( - request_type=service_binding.GetServiceBindingRequest, +def test_delete_tcp_route_rest_required_fields( + request_type=tcp_route.DeleteTcpRouteRequest, ): transport_class = transports.NetworkServicesRestTransport @@ -32343,7 +32954,7 @@ def test_get_service_binding_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_service_binding._get_unset_required_fields(jsonified_request) + ).delete_tcp_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -32352,7 +32963,7 @@ def test_get_service_binding_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_service_binding._get_unset_required_fields(jsonified_request) + ).delete_tcp_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -32366,7 +32977,7 @@ def test_get_service_binding_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = service_binding.ServiceBinding() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -32378,39 +32989,36 @@ def test_get_service_binding_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "delete", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = service_binding.ServiceBinding.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_service_binding(request) + response = client.delete_tcp_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_service_binding_rest_unset_required_fields(): +def test_delete_tcp_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_service_binding._get_unset_required_fields({}) + unset_fields = transport.delete_tcp_route._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_service_binding_rest_flattened(): +def test_delete_tcp_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -32419,11 +33027,11 @@ def test_get_service_binding_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service_binding.ServiceBinding() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3" + "name": "projects/sample1/locations/sample2/tcpRoutes/sample3" } # get truthy value for each flattened field @@ -32435,27 +33043,24 @@ def test_get_service_binding_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = service_binding.ServiceBinding.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_service_binding(**mock_args) + client.delete_tcp_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/serviceBindings/*}" - % client.transport._host, + "%s/v1/{name=projects/*/locations/*/tcpRoutes/*}" % client.transport._host, args[1], ) -def test_get_service_binding_rest_flattened_error(transport: str = "rest"): +def test_delete_tcp_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -32464,13 +33069,13 @@ def test_get_service_binding_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_service_binding( - service_binding.GetServiceBindingRequest(), + client.delete_tcp_route( + tcp_route.DeleteTcpRouteRequest(), name="name_value", ) -def test_create_service_binding_rest_use_cached_wrapped_rpc(): +def test_list_tls_routes_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -32484,45 +33089,35 @@ def test_create_service_binding_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.create_service_binding - in client._transport._wrapped_methods - ) + assert client._transport.list_tls_routes in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_service_binding] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.list_tls_routes] = mock_rpc request = {} - client.create_service_binding(request) + client.list_tls_routes(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_service_binding(request) + client.list_tls_routes(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_service_binding_rest_required_fields( - request_type=gcn_service_binding.CreateServiceBindingRequest, +def test_list_tls_routes_rest_required_fields( + request_type=tls_route.ListTlsRoutesRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" - request_init["service_binding_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -32530,32 +33125,32 @@ def test_create_service_binding_rest_required_fields( ) # verify fields with default values are dropped - assert "serviceBindingId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_service_binding._get_unset_required_fields(jsonified_request) + ).list_tls_routes._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "serviceBindingId" in jsonified_request - assert jsonified_request["serviceBindingId"] == request_init["service_binding_id"] jsonified_request["parent"] = "parent_value" - jsonified_request["serviceBindingId"] = "service_binding_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_service_binding._get_unset_required_fields(jsonified_request) + ).list_tls_routes._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("service_binding_id",)) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + "return_partial_success", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "serviceBindingId" in jsonified_request - assert jsonified_request["serviceBindingId"] == "service_binding_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -32564,7 +33159,7 @@ def test_create_service_binding_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = tls_route.ListTlsRoutesResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -32576,52 +33171,48 @@ def test_create_service_binding_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = tls_route.ListTlsRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_service_binding(request) + response = client.list_tls_routes(request) - expected_params = [ - ( - "serviceBindingId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_service_binding_rest_unset_required_fields(): +def test_list_tls_routes_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_service_binding._get_unset_required_fields({}) + unset_fields = transport.list_tls_routes._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("serviceBindingId",)) - & set( + set( ( - "parent", - "serviceBindingId", - "serviceBinding", + "pageSize", + "pageToken", + "returnPartialSuccess", ) ) + & set(("parent",)) ) -def test_create_service_binding_rest_flattened(): +def test_list_tls_routes_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -32630,7 +33221,7 @@ def test_create_service_binding_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = tls_route.ListTlsRoutesResponse() # get arguments that satisfy an http rule for this method sample_request = {"parent": "projects/sample1/locations/sample2"} @@ -32638,33 +33229,32 @@ def test_create_service_binding_rest_flattened(): # get truthy value for each flattened field mock_args = dict( parent="parent_value", - service_binding=gcn_service_binding.ServiceBinding(name="name_value"), - service_binding_id="service_binding_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = tls_route.ListTlsRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_service_binding(**mock_args) + client.list_tls_routes(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/serviceBindings" - % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/tlsRoutes" % client.transport._host, args[1], ) -def test_create_service_binding_rest_flattened_error(transport: str = "rest"): +def test_list_tls_routes_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -32673,15 +33263,74 @@ def test_create_service_binding_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_service_binding( - gcn_service_binding.CreateServiceBindingRequest(), + client.list_tls_routes( + tls_route.ListTlsRoutesRequest(), parent="parent_value", - service_binding=gcn_service_binding.ServiceBinding(name="name_value"), - service_binding_id="service_binding_id_value", ) -def test_update_service_binding_rest_use_cached_wrapped_rpc(): +def test_list_tls_routes_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + tls_route.ListTlsRoutesResponse( + tls_routes=[ + tls_route.TlsRoute(), + tls_route.TlsRoute(), + tls_route.TlsRoute(), + ], + next_page_token="abc", + ), + tls_route.ListTlsRoutesResponse( + tls_routes=[], + next_page_token="def", + ), + tls_route.ListTlsRoutesResponse( + tls_routes=[ + tls_route.TlsRoute(), + ], + next_page_token="ghi", + ), + tls_route.ListTlsRoutesResponse( + tls_routes=[ + tls_route.TlsRoute(), + tls_route.TlsRoute(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(tls_route.ListTlsRoutesResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_tls_routes(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, tls_route.TlsRoute) for i in results) + + pages = list(client.list_tls_routes(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_tls_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -32695,43 +33344,33 @@ def test_update_service_binding_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.update_service_binding - in client._transport._wrapped_methods - ) + assert client._transport.get_tls_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_service_binding] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.get_tls_route] = mock_rpc request = {} - client.update_service_binding(request) + client.get_tls_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_service_binding(request) + client.get_tls_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_service_binding_rest_required_fields( - request_type=gcn_service_binding.UpdateServiceBindingRequest, -): +def test_get_tls_route_rest_required_fields(request_type=tls_route.GetTlsRouteRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -32742,19 +33381,21 @@ def test_update_service_binding_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_service_binding._get_unset_required_fields(jsonified_request) + ).get_tls_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_service_binding._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + ).get_tls_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -32763,7 +33404,7 @@ def test_update_service_binding_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = tls_route.TlsRoute() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -32775,37 +33416,39 @@ def test_update_service_binding_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = tls_route.TlsRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_service_binding(request) + response = client.get_tls_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_update_service_binding_rest_unset_required_fields(): +def test_get_tls_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_service_binding._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("serviceBinding",))) + unset_fields = transport.get_tls_route._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_update_service_binding_rest_flattened(): +def test_get_tls_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -32814,44 +33457,42 @@ def test_update_service_binding_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = tls_route.TlsRoute() # get arguments that satisfy an http rule for this method sample_request = { - "service_binding": { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3" - } + "name": "projects/sample1/locations/sample2/tlsRoutes/sample3" } # get truthy value for each flattened field mock_args = dict( - service_binding=gcn_service_binding.ServiceBinding(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = tls_route.TlsRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_service_binding(**mock_args) + client.get_tls_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{service_binding.name=projects/*/locations/*/serviceBindings/*}" - % client.transport._host, + "%s/v1/{name=projects/*/locations/*/tlsRoutes/*}" % client.transport._host, args[1], ) -def test_update_service_binding_rest_flattened_error(transport: str = "rest"): +def test_get_tls_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -32860,14 +33501,13 @@ def test_update_service_binding_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_service_binding( - gcn_service_binding.UpdateServiceBindingRequest(), - service_binding=gcn_service_binding.ServiceBinding(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_tls_route( + tls_route.GetTlsRouteRequest(), + name="name_value", ) -def test_delete_service_binding_rest_use_cached_wrapped_rpc(): +def test_create_tls_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -32881,22 +33521,19 @@ def test_delete_service_binding_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.delete_service_binding - in client._transport._wrapped_methods - ) + assert client._transport.create_tls_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_service_binding] = ( + client._transport._wrapped_methods[client._transport.create_tls_route] = ( mock_rpc ) request = {} - client.delete_service_binding(request) + client.create_tls_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -32905,20 +33542,21 @@ def test_delete_service_binding_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_service_binding(request) + client.create_tls_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_service_binding_rest_required_fields( - request_type=service_binding.DeleteServiceBindingRequest, +def test_create_tls_route_rest_required_fields( + request_type=gcn_tls_route.CreateTlsRouteRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["tls_route_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -32926,24 +33564,32 @@ def test_delete_service_binding_rest_required_fields( ) # verify fields with default values are dropped + assert "tlsRouteId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_service_binding._get_unset_required_fields(jsonified_request) + ).create_tls_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "tlsRouteId" in jsonified_request + assert jsonified_request["tlsRouteId"] == request_init["tls_route_id"] - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["tlsRouteId"] = "tls_route_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_service_binding._get_unset_required_fields(jsonified_request) + ).create_tls_route._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("tls_route_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "tlsRouteId" in jsonified_request + assert jsonified_request["tlsRouteId"] == "tls_route_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -32964,9 +33610,10 @@ def test_delete_service_binding_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -32977,23 +33624,38 @@ def test_delete_service_binding_rest_required_fields( req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_service_binding(request) + response = client.create_tls_route(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "tlsRouteId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_service_binding_rest_unset_required_fields(): +def test_create_tls_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_service_binding._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_tls_route._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("tlsRouteId",)) + & set( + ( + "parent", + "tlsRouteId", + "tlsRoute", + ) + ) + ) -def test_delete_service_binding_rest_flattened(): +def test_create_tls_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -33005,13 +33667,13 @@ def test_delete_service_binding_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + tls_route=gcn_tls_route.TlsRoute(name="name_value"), + tls_route_id="tls_route_id_value", ) mock_args.update(sample_request) @@ -33023,20 +33685,19 @@ def test_delete_service_binding_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_service_binding(**mock_args) + client.create_tls_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/serviceBindings/*}" - % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/tlsRoutes" % client.transport._host, args[1], ) -def test_delete_service_binding_rest_flattened_error(transport: str = "rest"): +def test_create_tls_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -33045,13 +33706,15 @@ def test_delete_service_binding_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_service_binding( - service_binding.DeleteServiceBindingRequest(), - name="name_value", + client.create_tls_route( + gcn_tls_route.CreateTlsRouteRequest(), + parent="parent_value", + tls_route=gcn_tls_route.TlsRoute(name="name_value"), + tls_route_id="tls_route_id_value", ) -def test_list_meshes_rest_use_cached_wrapped_rpc(): +def test_update_tls_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -33065,33 +33728,40 @@ def test_list_meshes_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_meshes in client._transport._wrapped_methods + assert client._transport.update_tls_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_meshes] = mock_rpc + client._transport._wrapped_methods[client._transport.update_tls_route] = ( + mock_rpc + ) request = {} - client.list_meshes(request) + client.update_tls_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_meshes(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_tls_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_meshes_rest_required_fields(request_type=mesh.ListMeshesRequest): +def test_update_tls_route_rest_required_fields( + request_type=gcn_tls_route.UpdateTlsRouteRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -33102,29 +33772,19 @@ def test_list_meshes_rest_required_fields(request_type=mesh.ListMeshesRequest): unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_meshes._get_unset_required_fields(jsonified_request) + ).update_tls_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_meshes._get_unset_required_fields(jsonified_request) + ).update_tls_route._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - "return_partial_success", - ) - ) + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33133,7 +33793,7 @@ def test_list_meshes_rest_required_fields(request_type=mesh.ListMeshesRequest): request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = mesh.ListMeshesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -33145,48 +33805,37 @@ def test_list_meshes_rest_required_fields(request_type=mesh.ListMeshesRequest): pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = mesh.ListMeshesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_meshes(request) + response = client.update_tls_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_meshes_rest_unset_required_fields(): +def test_update_tls_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_meshes._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - "returnPartialSuccess", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.update_tls_route._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("tlsRoute",))) -def test_list_meshes_rest_flattened(): +def test_update_tls_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -33195,40 +33844,44 @@ def test_list_meshes_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = mesh.ListMeshesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "tls_route": { + "name": "projects/sample1/locations/sample2/tlsRoutes/sample3" + } + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + tls_route=gcn_tls_route.TlsRoute(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = mesh.ListMeshesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_meshes(**mock_args) + client.update_tls_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/meshes" % client.transport._host, + "%s/v1/{tls_route.name=projects/*/locations/*/tlsRoutes/*}" + % client.transport._host, args[1], ) -def test_list_meshes_rest_flattened_error(transport: str = "rest"): +def test_update_tls_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -33237,74 +33890,14 @@ def test_list_meshes_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_meshes( - mesh.ListMeshesRequest(), - parent="parent_value", - ) - - -def test_list_meshes_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - mesh.ListMeshesResponse( - meshes=[ - mesh.Mesh(), - mesh.Mesh(), - mesh.Mesh(), - ], - next_page_token="abc", - ), - mesh.ListMeshesResponse( - meshes=[], - next_page_token="def", - ), - mesh.ListMeshesResponse( - meshes=[ - mesh.Mesh(), - ], - next_page_token="ghi", - ), - mesh.ListMeshesResponse( - meshes=[ - mesh.Mesh(), - mesh.Mesh(), - ], - ), + client.update_tls_route( + gcn_tls_route.UpdateTlsRouteRequest(), + tls_route=gcn_tls_route.TlsRoute(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(mesh.ListMeshesResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_meshes(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, mesh.Mesh) for i in results) - - pages = list(client.list_meshes(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_get_mesh_rest_use_cached_wrapped_rpc(): +def test_delete_tls_route_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -33318,29 +33911,37 @@ def test_get_mesh_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_mesh in client._transport._wrapped_methods + assert client._transport.delete_tls_route in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_mesh] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_tls_route] = ( + mock_rpc + ) request = {} - client.get_mesh(request) + client.delete_tls_route(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_mesh(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_tls_route(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_mesh_rest_required_fields(request_type=mesh.GetMeshRequest): +def test_delete_tls_route_rest_required_fields( + request_type=tls_route.DeleteTlsRouteRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} @@ -33355,7 +33956,7 @@ def test_get_mesh_rest_required_fields(request_type=mesh.GetMeshRequest): unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_mesh._get_unset_required_fields(jsonified_request) + ).delete_tls_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -33364,7 +33965,7 @@ def test_get_mesh_rest_required_fields(request_type=mesh.GetMeshRequest): unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_mesh._get_unset_required_fields(jsonified_request) + ).delete_tls_route._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -33378,7 +33979,7 @@ def test_get_mesh_rest_required_fields(request_type=mesh.GetMeshRequest): request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = mesh.Mesh() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -33390,39 +33991,36 @@ def test_get_mesh_rest_required_fields(request_type=mesh.GetMeshRequest): pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "delete", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = mesh.Mesh.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_mesh(request) + response = client.delete_tls_route(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_mesh_rest_unset_required_fields(): +def test_delete_tls_route_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_mesh._get_unset_required_fields({}) + unset_fields = transport.delete_tls_route._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_mesh_rest_flattened(): +def test_delete_tls_route_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -33431,10 +34029,12 @@ def test_get_mesh_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = mesh.Mesh() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"name": "projects/sample1/locations/sample2/meshes/sample3"} + sample_request = { + "name": "projects/sample1/locations/sample2/tlsRoutes/sample3" + } # get truthy value for each flattened field mock_args = dict( @@ -33445,26 +34045,24 @@ def test_get_mesh_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = mesh.Mesh.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_mesh(**mock_args) + client.delete_tls_route(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/meshes/*}" % client.transport._host, + "%s/v1/{name=projects/*/locations/*/tlsRoutes/*}" % client.transport._host, args[1], ) -def test_get_mesh_rest_flattened_error(transport: str = "rest"): +def test_delete_tls_route_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -33473,13 +34071,13 @@ def test_get_mesh_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_mesh( - mesh.GetMeshRequest(), + client.delete_tls_route( + tls_route.DeleteTlsRouteRequest(), name="name_value", ) -def test_create_mesh_rest_use_cached_wrapped_rpc(): +def test_list_service_bindings_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -33493,38 +34091,40 @@ def test_create_mesh_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_mesh in client._transport._wrapped_methods + assert ( + client._transport.list_service_bindings + in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_mesh] = mock_rpc + client._transport._wrapped_methods[client._transport.list_service_bindings] = ( + mock_rpc + ) request = {} - client.create_mesh(request) + client.list_service_bindings(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_mesh(request) + client.list_service_bindings(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_mesh_rest_required_fields(request_type=gcn_mesh.CreateMeshRequest): +def test_list_service_bindings_rest_required_fields( + request_type=service_binding.ListServiceBindingsRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" - request_init["mesh_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -33532,32 +34132,31 @@ def test_create_mesh_rest_required_fields(request_type=gcn_mesh.CreateMeshReques ) # verify fields with default values are dropped - assert "meshId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_mesh._get_unset_required_fields(jsonified_request) + ).list_service_bindings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "meshId" in jsonified_request - assert jsonified_request["meshId"] == request_init["mesh_id"] jsonified_request["parent"] = "parent_value" - jsonified_request["meshId"] = "mesh_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_mesh._get_unset_required_fields(jsonified_request) + ).list_service_bindings._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("mesh_id",)) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "meshId" in jsonified_request - assert jsonified_request["meshId"] == "mesh_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33566,7 +34165,7 @@ def test_create_mesh_rest_required_fields(request_type=gcn_mesh.CreateMeshReques request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service_binding.ListServiceBindingsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -33578,52 +34177,47 @@ def test_create_mesh_rest_required_fields(request_type=gcn_mesh.CreateMeshReques pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = service_binding.ListServiceBindingsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_mesh(request) + response = client.list_service_bindings(request) - expected_params = [ - ( - "meshId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_mesh_rest_unset_required_fields(): +def test_list_service_bindings_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_mesh._get_unset_required_fields({}) + unset_fields = transport.list_service_bindings._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("meshId",)) - & set( + set( ( - "parent", - "meshId", - "mesh", + "pageSize", + "pageToken", ) ) + & set(("parent",)) ) -def test_create_mesh_rest_flattened(): +def test_list_service_bindings_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -33632,7 +34226,7 @@ def test_create_mesh_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service_binding.ListServiceBindingsResponse() # get arguments that satisfy an http rule for this method sample_request = {"parent": "projects/sample1/locations/sample2"} @@ -33640,32 +34234,33 @@ def test_create_mesh_rest_flattened(): # get truthy value for each flattened field mock_args = dict( parent="parent_value", - mesh=gcn_mesh.Mesh(name="name_value"), - mesh_id="mesh_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service_binding.ListServiceBindingsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_mesh(**mock_args) + client.list_service_bindings(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/meshes" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/serviceBindings" + % client.transport._host, args[1], ) -def test_create_mesh_rest_flattened_error(transport: str = "rest"): +def test_list_service_bindings_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -33674,15 +34269,76 @@ def test_create_mesh_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_mesh( - gcn_mesh.CreateMeshRequest(), + client.list_service_bindings( + service_binding.ListServiceBindingsRequest(), parent="parent_value", - mesh=gcn_mesh.Mesh(name="name_value"), - mesh_id="mesh_id_value", ) -def test_update_mesh_rest_use_cached_wrapped_rpc(): +def test_list_service_bindings_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + service_binding.ListServiceBindingsResponse( + service_bindings=[ + service_binding.ServiceBinding(), + service_binding.ServiceBinding(), + service_binding.ServiceBinding(), + ], + next_page_token="abc", + ), + service_binding.ListServiceBindingsResponse( + service_bindings=[], + next_page_token="def", + ), + service_binding.ListServiceBindingsResponse( + service_bindings=[ + service_binding.ServiceBinding(), + ], + next_page_token="ghi", + ), + service_binding.ListServiceBindingsResponse( + service_bindings=[ + service_binding.ServiceBinding(), + service_binding.ServiceBinding(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + service_binding.ListServiceBindingsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_service_bindings(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, service_binding.ServiceBinding) for i in results) + + pages = list(client.list_service_bindings(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_service_binding_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -33696,36 +34352,39 @@ def test_update_mesh_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_mesh in client._transport._wrapped_methods + assert ( + client._transport.get_service_binding in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_mesh] = mock_rpc + client._transport._wrapped_methods[client._transport.get_service_binding] = ( + mock_rpc + ) request = {} - client.update_mesh(request) + client.get_service_binding(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_mesh(request) + client.get_service_binding(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_mesh_rest_required_fields(request_type=gcn_mesh.UpdateMeshRequest): +def test_get_service_binding_rest_required_fields( + request_type=service_binding.GetServiceBindingRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -33736,19 +34395,21 @@ def test_update_mesh_rest_required_fields(request_type=gcn_mesh.UpdateMeshReques unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_mesh._get_unset_required_fields(jsonified_request) + ).get_service_binding._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_mesh._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + ).get_service_binding._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33757,7 +34418,7 @@ def test_update_mesh_rest_required_fields(request_type=gcn_mesh.UpdateMeshReques request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service_binding.ServiceBinding() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -33769,37 +34430,39 @@ def test_update_mesh_rest_required_fields(request_type=gcn_mesh.UpdateMeshReques pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = service_binding.ServiceBinding.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_mesh(request) + response = client.get_service_binding(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_update_mesh_rest_unset_required_fields(): +def test_get_service_binding_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_mesh._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("mesh",))) + unset_fields = transport.get_service_binding._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_update_mesh_rest_flattened(): +def test_get_service_binding_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -33808,42 +34471,43 @@ def test_update_mesh_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service_binding.ServiceBinding() # get arguments that satisfy an http rule for this method sample_request = { - "mesh": {"name": "projects/sample1/locations/sample2/meshes/sample3"} + "name": "projects/sample1/locations/sample2/serviceBindings/sample3" } # get truthy value for each flattened field mock_args = dict( - mesh=gcn_mesh.Mesh(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service_binding.ServiceBinding.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_mesh(**mock_args) + client.get_service_binding(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{mesh.name=projects/*/locations/*/meshes/*}" + "%s/v1/{name=projects/*/locations/*/serviceBindings/*}" % client.transport._host, args[1], ) -def test_update_mesh_rest_flattened_error(transport: str = "rest"): +def test_get_service_binding_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -33852,14 +34516,13 @@ def test_update_mesh_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_mesh( - gcn_mesh.UpdateMeshRequest(), - mesh=gcn_mesh.Mesh(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_service_binding( + service_binding.GetServiceBindingRequest(), + name="name_value", ) -def test_delete_mesh_rest_use_cached_wrapped_rpc(): +def test_create_service_binding_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -33873,17 +34536,22 @@ def test_delete_mesh_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_mesh in client._transport._wrapped_methods + assert ( + client._transport.create_service_binding + in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_mesh] = mock_rpc + client._transport._wrapped_methods[client._transport.create_service_binding] = ( + mock_rpc + ) request = {} - client.delete_mesh(request) + client.create_service_binding(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -33892,18 +34560,21 @@ def test_delete_mesh_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_mesh(request) + client.create_service_binding(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_mesh_rest_required_fields(request_type=mesh.DeleteMeshRequest): +def test_create_service_binding_rest_required_fields( + request_type=gcn_service_binding.CreateServiceBindingRequest, +): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["service_binding_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -33911,24 +34582,32 @@ def test_delete_mesh_rest_required_fields(request_type=mesh.DeleteMeshRequest): ) # verify fields with default values are dropped + assert "serviceBindingId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_mesh._get_unset_required_fields(jsonified_request) + ).create_service_binding._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "serviceBindingId" in jsonified_request + assert jsonified_request["serviceBindingId"] == request_init["service_binding_id"] - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["serviceBindingId"] = "service_binding_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_mesh._get_unset_required_fields(jsonified_request) + ).create_service_binding._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("service_binding_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "serviceBindingId" in jsonified_request + assert jsonified_request["serviceBindingId"] == "service_binding_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33949,9 +34628,10 @@ def test_delete_mesh_rest_required_fields(request_type=mesh.DeleteMeshRequest): pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -33962,23 +34642,38 @@ def test_delete_mesh_rest_required_fields(request_type=mesh.DeleteMeshRequest): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_mesh(request) + response = client.create_service_binding(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "serviceBindingId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_mesh_rest_unset_required_fields(): +def test_create_service_binding_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_mesh._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_service_binding._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("serviceBindingId",)) + & set( + ( + "parent", + "serviceBindingId", + "serviceBinding", + ) + ) + ) -def test_delete_mesh_rest_flattened(): +def test_create_service_binding_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -33990,11 +34685,13 @@ def test_delete_mesh_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"name": "projects/sample1/locations/sample2/meshes/sample3"} + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + service_binding=gcn_service_binding.ServiceBinding(name="name_value"), + service_binding_id="service_binding_id_value", ) mock_args.update(sample_request) @@ -34006,19 +34703,20 @@ def test_delete_mesh_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_mesh(**mock_args) + client.create_service_binding(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/meshes/*}" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/serviceBindings" + % client.transport._host, args[1], ) -def test_delete_mesh_rest_flattened_error(transport: str = "rest"): +def test_create_service_binding_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -34027,13 +34725,15 @@ def test_delete_mesh_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_mesh( - mesh.DeleteMeshRequest(), - name="name_value", + client.create_service_binding( + gcn_service_binding.CreateServiceBindingRequest(), + parent="parent_value", + service_binding=gcn_service_binding.ServiceBinding(name="name_value"), + service_binding_id="service_binding_id_value", ) -def test_list_service_lb_policies_rest_use_cached_wrapped_rpc(): +def test_update_service_binding_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -34048,7 +34748,7 @@ def test_list_service_lb_policies_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.list_service_lb_policies + client._transport.update_service_binding in client._transport._wrapped_methods ) @@ -34057,30 +34757,33 @@ def test_list_service_lb_policies_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_service_lb_policies - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_service_binding] = ( + mock_rpc + ) request = {} - client.list_service_lb_policies(request) + client.update_service_binding(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_service_lb_policies(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_service_binding(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_service_lb_policies_rest_required_fields( - request_type=service_lb_policy.ListServiceLbPoliciesRequest, +def test_update_service_binding_rest_required_fields( + request_type=gcn_service_binding.UpdateServiceBindingRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -34091,28 +34794,19 @@ def test_list_service_lb_policies_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_service_lb_policies._get_unset_required_fields(jsonified_request) + ).update_service_binding._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_service_lb_policies._get_unset_required_fields(jsonified_request) + ).update_service_binding._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34121,7 +34815,7 @@ def test_list_service_lb_policies_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = service_lb_policy.ListServiceLbPoliciesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -34133,49 +34827,37 @@ def test_list_service_lb_policies_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = service_lb_policy.ListServiceLbPoliciesResponse.pb( - return_value - ) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_service_lb_policies(request) + response = client.update_service_binding(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_service_lb_policies_rest_unset_required_fields(): +def test_update_service_binding_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_service_lb_policies._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.update_service_binding._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("serviceBinding",))) -def test_list_service_lb_policies_rest_flattened(): +def test_update_service_binding_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -34184,41 +34866,44 @@ def test_list_service_lb_policies_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service_lb_policy.ListServiceLbPoliciesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "service_binding": { + "name": "projects/sample1/locations/sample2/serviceBindings/sample3" + } + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + service_binding=gcn_service_binding.ServiceBinding(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = service_lb_policy.ListServiceLbPoliciesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_service_lb_policies(**mock_args) + client.update_service_binding(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/serviceLbPolicies" + "%s/v1/{service_binding.name=projects/*/locations/*/serviceBindings/*}" % client.transport._host, args[1], ) -def test_list_service_lb_policies_rest_flattened_error(transport: str = "rest"): +def test_update_service_binding_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -34227,76 +34912,14 @@ def test_list_service_lb_policies_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_service_lb_policies( - service_lb_policy.ListServiceLbPoliciesRequest(), - parent="parent_value", - ) - - -def test_list_service_lb_policies_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - service_lb_policy.ListServiceLbPoliciesResponse( - service_lb_policies=[ - service_lb_policy.ServiceLbPolicy(), - service_lb_policy.ServiceLbPolicy(), - service_lb_policy.ServiceLbPolicy(), - ], - next_page_token="abc", - ), - service_lb_policy.ListServiceLbPoliciesResponse( - service_lb_policies=[], - next_page_token="def", - ), - service_lb_policy.ListServiceLbPoliciesResponse( - service_lb_policies=[ - service_lb_policy.ServiceLbPolicy(), - ], - next_page_token="ghi", - ), - service_lb_policy.ListServiceLbPoliciesResponse( - service_lb_policies=[ - service_lb_policy.ServiceLbPolicy(), - service_lb_policy.ServiceLbPolicy(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple( - service_lb_policy.ListServiceLbPoliciesResponse.to_json(x) for x in response + client.update_service_binding( + gcn_service_binding.UpdateServiceBindingRequest(), + service_binding=gcn_service_binding.ServiceBinding(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_service_lb_policies(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, service_lb_policy.ServiceLbPolicy) for i in results) - - pages = list(client.list_service_lb_policies(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_get_service_lb_policy_rest_use_cached_wrapped_rpc(): +def test_delete_service_binding_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -34311,7 +34934,7 @@ def test_get_service_lb_policy_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.get_service_lb_policy + client._transport.delete_service_binding in client._transport._wrapped_methods ) @@ -34320,25 +34943,29 @@ def test_get_service_lb_policy_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_service_lb_policy] = ( + client._transport._wrapped_methods[client._transport.delete_service_binding] = ( mock_rpc ) request = {} - client.get_service_lb_policy(request) + client.delete_service_binding(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_service_lb_policy(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_service_binding(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_service_lb_policy_rest_required_fields( - request_type=service_lb_policy.GetServiceLbPolicyRequest, +def test_delete_service_binding_rest_required_fields( + request_type=service_binding.DeleteServiceBindingRequest, ): transport_class = transports.NetworkServicesRestTransport @@ -34354,7 +34981,7 @@ def test_get_service_lb_policy_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_service_lb_policy._get_unset_required_fields(jsonified_request) + ).delete_service_binding._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -34363,7 +34990,7 @@ def test_get_service_lb_policy_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_service_lb_policy._get_unset_required_fields(jsonified_request) + ).delete_service_binding._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -34377,7 +35004,7 @@ def test_get_service_lb_policy_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = service_lb_policy.ServiceLbPolicy() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -34389,39 +35016,36 @@ def test_get_service_lb_policy_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "delete", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = service_lb_policy.ServiceLbPolicy.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_service_lb_policy(request) + response = client.delete_service_binding(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_service_lb_policy_rest_unset_required_fields(): +def test_delete_service_binding_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_service_lb_policy._get_unset_required_fields({}) + unset_fields = transport.delete_service_binding._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_service_lb_policy_rest_flattened(): +def test_delete_service_binding_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -34430,11 +35054,11 @@ def test_get_service_lb_policy_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service_lb_policy.ServiceLbPolicy() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + "name": "projects/sample1/locations/sample2/serviceBindings/sample3" } # get truthy value for each flattened field @@ -34446,27 +35070,25 @@ def test_get_service_lb_policy_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = service_lb_policy.ServiceLbPolicy.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_service_lb_policy(**mock_args) + client.delete_service_binding(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/serviceLbPolicies/*}" + "%s/v1/{name=projects/*/locations/*/serviceBindings/*}" % client.transport._host, args[1], ) -def test_get_service_lb_policy_rest_flattened_error(transport: str = "rest"): +def test_delete_service_binding_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -34475,13 +35097,13 @@ def test_get_service_lb_policy_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_service_lb_policy( - service_lb_policy.GetServiceLbPolicyRequest(), + client.delete_service_binding( + service_binding.DeleteServiceBindingRequest(), name="name_value", ) -def test_create_service_lb_policy_rest_use_cached_wrapped_rpc(): +def test_list_meshes_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -34495,45 +35117,33 @@ def test_create_service_lb_policy_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.create_service_lb_policy - in client._transport._wrapped_methods - ) + assert client._transport.list_meshes in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_service_lb_policy - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_meshes] = mock_rpc request = {} - client.create_service_lb_policy(request) + client.list_meshes(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_service_lb_policy(request) + client.list_meshes(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_service_lb_policy_rest_required_fields( - request_type=gcn_service_lb_policy.CreateServiceLbPolicyRequest, -): +def test_list_meshes_rest_required_fields(request_type=mesh.ListMeshesRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} request_init["parent"] = "" - request_init["service_lb_policy_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -34541,34 +35151,32 @@ def test_create_service_lb_policy_rest_required_fields( ) # verify fields with default values are dropped - assert "serviceLbPolicyId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_service_lb_policy._get_unset_required_fields(jsonified_request) + ).list_meshes._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "serviceLbPolicyId" in jsonified_request - assert ( - jsonified_request["serviceLbPolicyId"] == request_init["service_lb_policy_id"] - ) jsonified_request["parent"] = "parent_value" - jsonified_request["serviceLbPolicyId"] = "service_lb_policy_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_service_lb_policy._get_unset_required_fields(jsonified_request) + ).list_meshes._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("service_lb_policy_id",)) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + "return_partial_success", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "serviceLbPolicyId" in jsonified_request - assert jsonified_request["serviceLbPolicyId"] == "service_lb_policy_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34577,7 +35185,7 @@ def test_create_service_lb_policy_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = mesh.ListMeshesResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -34589,52 +35197,48 @@ def test_create_service_lb_policy_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = mesh.ListMeshesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_service_lb_policy(request) + response = client.list_meshes(request) - expected_params = [ - ( - "serviceLbPolicyId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_create_service_lb_policy_rest_unset_required_fields(): +def test_list_meshes_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_service_lb_policy._get_unset_required_fields({}) + unset_fields = transport.list_meshes._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("serviceLbPolicyId",)) - & set( + set( ( - "parent", - "serviceLbPolicyId", - "serviceLbPolicy", + "pageSize", + "pageToken", + "returnPartialSuccess", ) ) + & set(("parent",)) ) -def test_create_service_lb_policy_rest_flattened(): +def test_list_meshes_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -34643,7 +35247,7 @@ def test_create_service_lb_policy_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = mesh.ListMeshesResponse() # get arguments that satisfy an http rule for this method sample_request = {"parent": "projects/sample1/locations/sample2"} @@ -34651,33 +35255,32 @@ def test_create_service_lb_policy_rest_flattened(): # get truthy value for each flattened field mock_args = dict( parent="parent_value", - service_lb_policy=gcn_service_lb_policy.ServiceLbPolicy(name="name_value"), - service_lb_policy_id="service_lb_policy_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = mesh.ListMeshesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_service_lb_policy(**mock_args) + client.list_meshes(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/serviceLbPolicies" - % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/meshes" % client.transport._host, args[1], ) -def test_create_service_lb_policy_rest_flattened_error(transport: str = "rest"): +def test_list_meshes_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -34686,15 +35289,74 @@ def test_create_service_lb_policy_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_service_lb_policy( - gcn_service_lb_policy.CreateServiceLbPolicyRequest(), + client.list_meshes( + mesh.ListMeshesRequest(), parent="parent_value", - service_lb_policy=gcn_service_lb_policy.ServiceLbPolicy(name="name_value"), - service_lb_policy_id="service_lb_policy_id_value", ) -def test_update_service_lb_policy_rest_use_cached_wrapped_rpc(): +def test_list_meshes_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + mesh.ListMeshesResponse( + meshes=[ + mesh.Mesh(), + mesh.Mesh(), + mesh.Mesh(), + ], + next_page_token="abc", + ), + mesh.ListMeshesResponse( + meshes=[], + next_page_token="def", + ), + mesh.ListMeshesResponse( + meshes=[ + mesh.Mesh(), + ], + next_page_token="ghi", + ), + mesh.ListMeshesResponse( + meshes=[ + mesh.Mesh(), + mesh.Mesh(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(mesh.ListMeshesResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_meshes(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, mesh.Mesh) for i in results) + + pages = list(client.list_meshes(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_mesh_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -34708,43 +35370,33 @@ def test_update_service_lb_policy_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.update_service_lb_policy - in client._transport._wrapped_methods - ) + assert client._transport.get_mesh in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.update_service_lb_policy - ] = mock_rpc + client._transport._wrapped_methods[client._transport.get_mesh] = mock_rpc request = {} - client.update_service_lb_policy(request) + client.get_mesh(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_service_lb_policy(request) + client.get_mesh(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_service_lb_policy_rest_required_fields( - request_type=gcn_service_lb_policy.UpdateServiceLbPolicyRequest, -): +def test_get_mesh_rest_required_fields(request_type=mesh.GetMeshRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -34755,19 +35407,21 @@ def test_update_service_lb_policy_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_service_lb_policy._get_unset_required_fields(jsonified_request) + ).get_mesh._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_service_lb_policy._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + ).get_mesh._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34776,7 +35430,7 @@ def test_update_service_lb_policy_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = mesh.Mesh() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -34788,37 +35442,39 @@ def test_update_service_lb_policy_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = mesh.Mesh.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_service_lb_policy(request) + response = client.get_mesh(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_update_service_lb_policy_rest_unset_required_fields(): +def test_get_mesh_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_service_lb_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("serviceLbPolicy",))) + unset_fields = transport.get_mesh._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_update_service_lb_policy_rest_flattened(): +def test_get_mesh_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -34827,44 +35483,40 @@ def test_update_service_lb_policy_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = mesh.Mesh() # get arguments that satisfy an http rule for this method - sample_request = { - "service_lb_policy": { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" - } - } + sample_request = {"name": "projects/sample1/locations/sample2/meshes/sample3"} # get truthy value for each flattened field mock_args = dict( - service_lb_policy=gcn_service_lb_policy.ServiceLbPolicy(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = mesh.Mesh.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_service_lb_policy(**mock_args) + client.get_mesh(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{service_lb_policy.name=projects/*/locations/*/serviceLbPolicies/*}" - % client.transport._host, + "%s/v1/{name=projects/*/locations/*/meshes/*}" % client.transport._host, args[1], ) -def test_update_service_lb_policy_rest_flattened_error(transport: str = "rest"): +def test_get_mesh_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -34873,14 +35525,13 @@ def test_update_service_lb_policy_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_service_lb_policy( - gcn_service_lb_policy.UpdateServiceLbPolicyRequest(), - service_lb_policy=gcn_service_lb_policy.ServiceLbPolicy(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_mesh( + mesh.GetMeshRequest(), + name="name_value", ) -def test_delete_service_lb_policy_rest_use_cached_wrapped_rpc(): +def test_create_mesh_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -34894,22 +35545,17 @@ def test_delete_service_lb_policy_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.delete_service_lb_policy - in client._transport._wrapped_methods - ) + assert client._transport.create_mesh in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_service_lb_policy - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_mesh] = mock_rpc request = {} - client.delete_service_lb_policy(request) + client.create_mesh(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -34918,20 +35564,19 @@ def test_delete_service_lb_policy_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_service_lb_policy(request) + client.create_mesh(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_service_lb_policy_rest_required_fields( - request_type=service_lb_policy.DeleteServiceLbPolicyRequest, -): +def test_create_mesh_rest_required_fields(request_type=gcn_mesh.CreateMeshRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["mesh_id"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -34939,24 +35584,32 @@ def test_delete_service_lb_policy_rest_required_fields( ) # verify fields with default values are dropped + assert "meshId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_service_lb_policy._get_unset_required_fields(jsonified_request) + ).create_mesh._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "meshId" in jsonified_request + assert jsonified_request["meshId"] == request_init["mesh_id"] - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["meshId"] = "mesh_id_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_service_lb_policy._get_unset_required_fields(jsonified_request) + ).create_mesh._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("mesh_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "meshId" in jsonified_request + assert jsonified_request["meshId"] == "mesh_id_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34977,9 +35630,10 @@ def test_delete_service_lb_policy_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -34990,23 +35644,38 @@ def test_delete_service_lb_policy_rest_required_fields( req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_service_lb_policy(request) + response = client.create_mesh(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "meshId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_delete_service_lb_policy_rest_unset_required_fields(): +def test_create_mesh_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_service_lb_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_mesh._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("meshId",)) + & set( + ( + "parent", + "meshId", + "mesh", + ) + ) + ) -def test_delete_service_lb_policy_rest_flattened(): +def test_create_mesh_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -35018,13 +35687,13 @@ def test_delete_service_lb_policy_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + mesh=gcn_mesh.Mesh(name="name_value"), + mesh_id="mesh_id_value", ) mock_args.update(sample_request) @@ -35036,20 +35705,19 @@ def test_delete_service_lb_policy_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_service_lb_policy(**mock_args) + client.create_mesh(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/serviceLbPolicies/*}" - % client.transport._host, + "%s/v1/{parent=projects/*/locations/*}/meshes" % client.transport._host, args[1], ) -def test_delete_service_lb_policy_rest_flattened_error(transport: str = "rest"): +def test_create_mesh_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -35058,13 +35726,15 @@ def test_delete_service_lb_policy_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_service_lb_policy( - service_lb_policy.DeleteServiceLbPolicyRequest(), - name="name_value", + client.create_mesh( + gcn_mesh.CreateMeshRequest(), + parent="parent_value", + mesh=gcn_mesh.Mesh(name="name_value"), + mesh_id="mesh_id_value", ) -def test_get_gateway_route_view_rest_use_cached_wrapped_rpc(): +def test_update_mesh_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -35078,40 +35748,36 @@ def test_get_gateway_route_view_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.get_gateway_route_view - in client._transport._wrapped_methods - ) + assert client._transport.update_mesh in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_gateway_route_view] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.update_mesh] = mock_rpc request = {} - client.get_gateway_route_view(request) + client.update_mesh(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_gateway_route_view(request) - - # Establish that a new wrapper was not created for this call + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_mesh(request) + + # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_gateway_route_view_rest_required_fields( - request_type=route_view.GetGatewayRouteViewRequest, -): +def test_update_mesh_rest_required_fields(request_type=gcn_mesh.UpdateMeshRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -35122,21 +35788,19 @@ def test_get_gateway_route_view_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_gateway_route_view._get_unset_required_fields(jsonified_request) + ).update_mesh._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_gateway_route_view._get_unset_required_fields(jsonified_request) + ).update_mesh._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -35145,7 +35809,7 @@ def test_get_gateway_route_view_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = route_view.GatewayRouteView() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -35157,39 +35821,37 @@ def test_get_gateway_route_view_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = route_view.GatewayRouteView.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_gateway_route_view(request) + response = client.update_mesh(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_gateway_route_view_rest_unset_required_fields(): +def test_update_mesh_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_gateway_route_view._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.update_mesh._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("mesh",))) -def test_get_gateway_route_view_rest_flattened(): +def test_update_mesh_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -35198,43 +35860,42 @@ def test_get_gateway_route_view_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = route_view.GatewayRouteView() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/gateways/sample3/routeViews/sample4" + "mesh": {"name": "projects/sample1/locations/sample2/meshes/sample3"} } # get truthy value for each flattened field mock_args = dict( - name="name_value", + mesh=gcn_mesh.Mesh(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = route_view.GatewayRouteView.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_gateway_route_view(**mock_args) + client.update_mesh(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/gateways/*/routeViews/*}" + "%s/v1/{mesh.name=projects/*/locations/*/meshes/*}" % client.transport._host, args[1], ) -def test_get_gateway_route_view_rest_flattened_error(transport: str = "rest"): +def test_update_mesh_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -35243,13 +35904,14 @@ def test_get_gateway_route_view_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_gateway_route_view( - route_view.GetGatewayRouteViewRequest(), - name="name_value", + client.update_mesh( + gcn_mesh.UpdateMeshRequest(), + mesh=gcn_mesh.Mesh(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_get_mesh_route_view_rest_use_cached_wrapped_rpc(): +def test_delete_mesh_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -35263,35 +35925,33 @@ def test_get_mesh_route_view_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.get_mesh_route_view in client._transport._wrapped_methods - ) + assert client._transport.delete_mesh in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_mesh_route_view] = ( - mock_rpc - ) + client._transport._wrapped_methods[client._transport.delete_mesh] = mock_rpc request = {} - client.get_mesh_route_view(request) + client.delete_mesh(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_mesh_route_view(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_mesh(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_mesh_route_view_rest_required_fields( - request_type=route_view.GetMeshRouteViewRequest, -): +def test_delete_mesh_rest_required_fields(request_type=mesh.DeleteMeshRequest): transport_class = transports.NetworkServicesRestTransport request_init = {} @@ -35306,7 +35966,7 @@ def test_get_mesh_route_view_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_mesh_route_view._get_unset_required_fields(jsonified_request) + ).delete_mesh._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -35315,7 +35975,7 @@ def test_get_mesh_route_view_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_mesh_route_view._get_unset_required_fields(jsonified_request) + ).delete_mesh._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -35329,7 +35989,7 @@ def test_get_mesh_route_view_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = route_view.MeshRouteView() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -35341,39 +36001,36 @@ def test_get_mesh_route_view_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "delete", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = route_view.MeshRouteView.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_mesh_route_view(request) + response = client.delete_mesh(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_get_mesh_route_view_rest_unset_required_fields(): +def test_delete_mesh_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_mesh_route_view._get_unset_required_fields({}) + unset_fields = transport.delete_mesh._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_mesh_route_view_rest_flattened(): +def test_delete_mesh_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -35382,12 +36039,10 @@ def test_get_mesh_route_view_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = route_view.MeshRouteView() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/meshes/sample3/routeViews/sample4" - } + sample_request = {"name": "projects/sample1/locations/sample2/meshes/sample3"} # get truthy value for each flattened field mock_args = dict( @@ -35398,27 +36053,24 @@ def test_get_mesh_route_view_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = route_view.MeshRouteView.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_mesh_route_view(**mock_args) + client.delete_mesh(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/meshes/*/routeViews/*}" - % client.transport._host, + "%s/v1/{name=projects/*/locations/*/meshes/*}" % client.transport._host, args[1], ) -def test_get_mesh_route_view_rest_flattened_error(transport: str = "rest"): +def test_delete_mesh_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -35427,13 +36079,13 @@ def test_get_mesh_route_view_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_mesh_route_view( - route_view.GetMeshRouteViewRequest(), + client.delete_mesh( + mesh.DeleteMeshRequest(), name="name_value", ) -def test_list_gateway_route_views_rest_use_cached_wrapped_rpc(): +def test_list_service_lb_policies_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -35448,7 +36100,7 @@ def test_list_gateway_route_views_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.list_gateway_route_views + client._transport.list_service_lb_policies in client._transport._wrapped_methods ) @@ -35458,24 +36110,24 @@ def test_list_gateway_route_views_rest_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.list_gateway_route_views + client._transport.list_service_lb_policies ] = mock_rpc request = {} - client.list_gateway_route_views(request) + client.list_service_lb_policies(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_gateway_route_views(request) + client.list_service_lb_policies(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_gateway_route_views_rest_required_fields( - request_type=route_view.ListGatewayRouteViewsRequest, +def test_list_service_lb_policies_rest_required_fields( + request_type=service_lb_policy.ListServiceLbPoliciesRequest, ): transport_class = transports.NetworkServicesRestTransport @@ -35491,7 +36143,7 @@ def test_list_gateway_route_views_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_gateway_route_views._get_unset_required_fields(jsonified_request) + ).list_service_lb_policies._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -35500,7 +36152,7 @@ def test_list_gateway_route_views_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_gateway_route_views._get_unset_required_fields(jsonified_request) + ).list_service_lb_policies._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( @@ -35521,7 +36173,7 @@ def test_list_gateway_route_views_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = route_view.ListGatewayRouteViewsResponse() + return_value = service_lb_policy.ListServiceLbPoliciesResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -35542,26 +36194,28 @@ def test_list_gateway_route_views_rest_required_fields( response_value.status_code = 200 # Convert return value to protobuf type - return_value = route_view.ListGatewayRouteViewsResponse.pb(return_value) + return_value = service_lb_policy.ListServiceLbPoliciesResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_gateway_route_views(request) + response = client.list_service_lb_policies(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_gateway_route_views_rest_unset_required_fields(): +def test_list_service_lb_policies_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_gateway_route_views._get_unset_required_fields({}) + unset_fields = transport.list_service_lb_policies._get_unset_required_fields({}) assert set(unset_fields) == ( set( ( @@ -35573,7 +36227,7 @@ def test_list_gateway_route_views_rest_unset_required_fields(): ) -def test_list_gateway_route_views_rest_flattened(): +def test_list_service_lb_policies_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -35582,12 +36236,10 @@ def test_list_gateway_route_views_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = route_view.ListGatewayRouteViewsResponse() + return_value = service_lb_policy.ListServiceLbPoliciesResponse() # get arguments that satisfy an http rule for this method - sample_request = { - "parent": "projects/sample1/locations/sample2/gateways/sample3" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( @@ -35599,26 +36251,26 @@ def test_list_gateway_route_views_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = route_view.ListGatewayRouteViewsResponse.pb(return_value) + return_value = service_lb_policy.ListServiceLbPoliciesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_gateway_route_views(**mock_args) + client.list_service_lb_policies(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*/gateways/*}/routeViews" + "%s/v1/{parent=projects/*/locations/*}/serviceLbPolicies" % client.transport._host, args[1], ) -def test_list_gateway_route_views_rest_flattened_error(transport: str = "rest"): +def test_list_service_lb_policies_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -35627,13 +36279,13 @@ def test_list_gateway_route_views_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_gateway_route_views( - route_view.ListGatewayRouteViewsRequest(), + client.list_service_lb_policies( + service_lb_policy.ListServiceLbPoliciesRequest(), parent="parent_value", ) -def test_list_gateway_route_views_rest_pager(transport: str = "rest"): +def test_list_service_lb_policies_rest_pager(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -35645,28 +36297,28 @@ def test_list_gateway_route_views_rest_pager(transport: str = "rest"): # with mock.patch.object(path_template, 'transcode') as transcode: # Set the response as a series of pages response = ( - route_view.ListGatewayRouteViewsResponse( - gateway_route_views=[ - route_view.GatewayRouteView(), - route_view.GatewayRouteView(), - route_view.GatewayRouteView(), + service_lb_policy.ListServiceLbPoliciesResponse( + service_lb_policies=[ + service_lb_policy.ServiceLbPolicy(), + service_lb_policy.ServiceLbPolicy(), + service_lb_policy.ServiceLbPolicy(), ], next_page_token="abc", ), - route_view.ListGatewayRouteViewsResponse( - gateway_route_views=[], + service_lb_policy.ListServiceLbPoliciesResponse( + service_lb_policies=[], next_page_token="def", ), - route_view.ListGatewayRouteViewsResponse( - gateway_route_views=[ - route_view.GatewayRouteView(), + service_lb_policy.ListServiceLbPoliciesResponse( + service_lb_policies=[ + service_lb_policy.ServiceLbPolicy(), ], next_page_token="ghi", ), - route_view.ListGatewayRouteViewsResponse( - gateway_route_views=[ - route_view.GatewayRouteView(), - route_view.GatewayRouteView(), + service_lb_policy.ListServiceLbPoliciesResponse( + service_lb_policies=[ + service_lb_policy.ServiceLbPolicy(), + service_lb_policy.ServiceLbPolicy(), ], ), ) @@ -35675,7 +36327,7 @@ def test_list_gateway_route_views_rest_pager(transport: str = "rest"): # Wrap the values into proper Response objs response = tuple( - route_view.ListGatewayRouteViewsResponse.to_json(x) for x in response + service_lb_policy.ListServiceLbPoliciesResponse.to_json(x) for x in response ) return_values = tuple(Response() for i in response) for return_val, response_val in zip(return_values, response): @@ -35683,22 +36335,20 @@ def test_list_gateway_route_views_rest_pager(transport: str = "rest"): return_val.status_code = 200 req.side_effect = return_values - sample_request = { - "parent": "projects/sample1/locations/sample2/gateways/sample3" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} - pager = client.list_gateway_route_views(request=sample_request) + pager = client.list_service_lb_policies(request=sample_request) results = list(pager) assert len(results) == 6 - assert all(isinstance(i, route_view.GatewayRouteView) for i in results) + assert all(isinstance(i, service_lb_policy.ServiceLbPolicy) for i in results) - pages = list(client.list_gateway_route_views(request=sample_request).pages) + pages = list(client.list_service_lb_policies(request=sample_request).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_list_mesh_route_views_rest_use_cached_wrapped_rpc(): +def test_get_service_lb_policy_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -35713,7 +36363,7 @@ def test_list_mesh_route_views_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.list_mesh_route_views + client._transport.get_service_lb_policy in client._transport._wrapped_methods ) @@ -35722,30 +36372,30 @@ def test_list_mesh_route_views_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_mesh_route_views] = ( + client._transport._wrapped_methods[client._transport.get_service_lb_policy] = ( mock_rpc ) request = {} - client.list_mesh_route_views(request) + client.get_service_lb_policy(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_mesh_route_views(request) + client.get_service_lb_policy(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_mesh_route_views_rest_required_fields( - request_type=route_view.ListMeshRouteViewsRequest, +def test_get_service_lb_policy_rest_required_fields( + request_type=service_lb_policy.GetServiceLbPolicyRequest, ): transport_class = transports.NetworkServicesRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -35756,28 +36406,21 @@ def test_list_mesh_route_views_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_mesh_route_views._get_unset_required_fields(jsonified_request) + ).get_service_lb_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_mesh_route_views._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + ).get_service_lb_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -35786,7 +36429,7 @@ def test_list_mesh_route_views_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = route_view.ListMeshRouteViewsResponse() + return_value = service_lb_policy.ServiceLbPolicy() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -35807,38 +36450,30 @@ def test_list_mesh_route_views_rest_required_fields( response_value.status_code = 200 # Convert return value to protobuf type - return_value = route_view.ListMeshRouteViewsResponse.pb(return_value) + return_value = service_lb_policy.ServiceLbPolicy.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_mesh_route_views(request) + response = client.get_service_lb_policy(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert sorted(expected_params) == sorted(actual_params) -def test_list_mesh_route_views_rest_unset_required_fields(): +def test_get_service_lb_policy_rest_unset_required_fields(): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_mesh_route_views._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.get_service_lb_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_list_mesh_route_views_rest_flattened(): +def test_get_service_lb_policy_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -35847,14 +36482,16 @@ def test_list_mesh_route_views_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = route_view.ListMeshRouteViewsResponse() + return_value = service_lb_policy.ServiceLbPolicy() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2/meshes/sample3"} + sample_request = { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + name="name_value", ) mock_args.update(sample_request) @@ -35862,26 +36499,26 @@ def test_list_mesh_route_views_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = route_view.ListMeshRouteViewsResponse.pb(return_value) + return_value = service_lb_policy.ServiceLbPolicy.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_mesh_route_views(**mock_args) + client.get_service_lb_policy(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*/meshes/*}/routeViews" + "%s/v1/{name=projects/*/locations/*/serviceLbPolicies/*}" % client.transport._host, args[1], ) -def test_list_mesh_route_views_rest_flattened_error(transport: str = "rest"): +def test_get_service_lb_policy_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -35890,3019 +36527,6588 @@ def test_list_mesh_route_views_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_mesh_route_views( - route_view.ListMeshRouteViewsRequest(), - parent="parent_value", - ) - - -def test_list_mesh_route_views_rest_pager(transport: str = "rest"): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - route_view.ListMeshRouteViewsResponse( - mesh_route_views=[ - route_view.MeshRouteView(), - route_view.MeshRouteView(), - route_view.MeshRouteView(), - ], - next_page_token="abc", - ), - route_view.ListMeshRouteViewsResponse( - mesh_route_views=[], - next_page_token="def", - ), - route_view.ListMeshRouteViewsResponse( - mesh_route_views=[ - route_view.MeshRouteView(), - ], - next_page_token="ghi", - ), - route_view.ListMeshRouteViewsResponse( - mesh_route_views=[ - route_view.MeshRouteView(), - route_view.MeshRouteView(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple( - route_view.ListMeshRouteViewsResponse.to_json(x) for x in response + client.get_service_lb_policy( + service_lb_policy.GetServiceLbPolicyRequest(), + name="name_value", ) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2/meshes/sample3"} - - pager = client.list_mesh_route_views(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, route_view.MeshRouteView) for i in results) - - pages = list(client.list_mesh_route_views(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.NetworkServicesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): +def test_create_service_lb_policy_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + transport="rest", ) - # It is an error to provide a credentials file and a transport instance. - transport = transports.NetworkServicesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = NetworkServicesClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # It is an error to provide an api_key and a transport instance. - transport = transports.NetworkServicesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = NetworkServicesClient( - client_options=options, - transport=transport, + # Ensure method has been cached + assert ( + client._transport.create_service_lb_policy + in client._transport._wrapped_methods ) - # It is an error to provide an api_key and a credential. - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = NetworkServicesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. ) + client._transport._wrapped_methods[ + client._transport.create_service_lb_policy + ] = mock_rpc - # It is an error to provide scopes and a transport instance. - transport = transports.NetworkServicesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = NetworkServicesClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) + request = {} + client.create_service_lb_policy(request) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.NetworkServicesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = NetworkServicesClient(transport=transport) - assert client.transport is transport + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + client.create_service_lb_policy(request) -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.NetworkServicesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 - transport = transports.NetworkServicesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel +def test_create_service_lb_policy_rest_required_fields( + request_type=gcn_service_lb_policy.CreateServiceLbPolicyRequest, +): + transport_class = transports.NetworkServicesRestTransport -@pytest.mark.parametrize( - "transport_class", - [ - transports.NetworkServicesGrpcTransport, - transports.NetworkServicesGrpcAsyncIOTransport, - transports.NetworkServicesRestTransport, - ], -) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() + request_init = {} + request_init["parent"] = "" + request_init["service_lb_policy_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + # verify fields with default values are dropped + assert "serviceLbPolicyId" not in jsonified_request -def test_transport_kind_grpc(): - transport = NetworkServicesClient.get_transport_class("grpc")( + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() + ).create_service_lb_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "serviceLbPolicyId" in jsonified_request + assert ( + jsonified_request["serviceLbPolicyId"] == request_init["service_lb_policy_id"] ) - assert transport.kind == "grpc" + jsonified_request["parent"] = "parent_value" + jsonified_request["serviceLbPolicyId"] = "service_lb_policy_id_value" -def test_initialize_client_w_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc" - ) - assert client is not None + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_service_lb_policy._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("service_lb_policy_id",)) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "serviceLbPolicyId" in jsonified_request + assert jsonified_request["serviceLbPolicyId"] == "service_lb_policy_id_value" -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_endpoint_policies_empty_call_grpc(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_endpoint_policies), "__call__" - ) as call: - call.return_value = endpoint_policy.ListEndpointPoliciesResponse() - client.list_endpoint_policies(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = endpoint_policy.ListEndpointPoliciesRequest() - assert args[0] == request_msg + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_endpoint_policy_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_endpoint_policy), "__call__" - ) as call: - call.return_value = endpoint_policy.EndpointPolicy() - client.get_endpoint_policy(request=None) + response = client.create_service_lb_policy(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = endpoint_policy.GetEndpointPolicyRequest() - assert args[0] == request_msg + expected_params = [ + ( + "serviceLbPolicyId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_endpoint_policy_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", +def test_create_service_lb_policy_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_endpoint_policy), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_endpoint_policy(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_endpoint_policy.CreateEndpointPolicyRequest() - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_endpoint_policy_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + unset_fields = transport.create_service_lb_policy._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("serviceLbPolicyId",)) + & set( + ( + "parent", + "serviceLbPolicyId", + "serviceLbPolicy", + ) + ) ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_endpoint_policy), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_endpoint_policy(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_endpoint_policy.UpdateEndpointPolicyRequest() - assert args[0] == request_msg - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_endpoint_policy_empty_call_grpc(): +def test_create_service_lb_policy_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_endpoint_policy), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_endpoint_policy(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = endpoint_policy.DeleteEndpointPolicyRequest() - assert args[0] == request_msg + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + service_lb_policy=gcn_service_lb_policy.ServiceLbPolicy(name="name_value"), + service_lb_policy_id="service_lb_policy_id_value", + ) + mock_args.update(sample_request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_wasm_plugin_versions_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_wasm_plugin_versions), "__call__" - ) as call: - call.return_value = extensibility.ListWasmPluginVersionsResponse() - client.list_wasm_plugin_versions(request=None) + client.create_service_lb_policy(**mock_args) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.ListWasmPluginVersionsRequest() - assert args[0] == request_msg + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/serviceLbPolicies" + % client.transport._host, + args[1], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_wasm_plugin_version_empty_call_grpc(): +def test_create_service_lb_policy_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_wasm_plugin_version), "__call__" - ) as call: - call.return_value = extensibility.WasmPluginVersion() - client.get_wasm_plugin_version(request=None) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_service_lb_policy( + gcn_service_lb_policy.CreateServiceLbPolicyRequest(), + parent="parent_value", + service_lb_policy=gcn_service_lb_policy.ServiceLbPolicy(name="name_value"), + service_lb_policy_id="service_lb_policy_id_value", + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.GetWasmPluginVersionRequest() - assert args[0] == request_msg +def test_update_service_lb_policy_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_wasm_plugin_version_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_wasm_plugin_version), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_wasm_plugin_version(request=None) + # Ensure method has been cached + assert ( + client._transport.update_service_lb_policy + in client._transport._wrapped_methods + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.CreateWasmPluginVersionRequest() - assert args[0] == request_msg + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_service_lb_policy + ] = mock_rpc + request = {} + client.update_service_lb_policy(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_wasm_plugin_version_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_wasm_plugin_version), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_wasm_plugin_version(request=None) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.DeleteWasmPluginVersionRequest() - assert args[0] == request_msg + client.update_service_lb_policy(request) + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_wasm_plugins_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_wasm_plugins), "__call__" - ) as call: - call.return_value = extensibility.ListWasmPluginsResponse() - client.list_wasm_plugins(request=None) +def test_update_service_lb_policy_rest_required_fields( + request_type=gcn_service_lb_policy.UpdateServiceLbPolicyRequest, +): + transport_class = transports.NetworkServicesRestTransport - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.ListWasmPluginsRequest() - assert args[0] == request_msg + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + # verify fields with default values are dropped -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_wasm_plugin_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_service_lb_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_wasm_plugin), "__call__") as call: - call.return_value = extensibility.WasmPlugin() - client.get_wasm_plugin(request=None) + # verify required fields with default values are now present - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.GetWasmPluginRequest() - assert args[0] == request_msg + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_service_lb_policy._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_wasm_plugin_empty_call_grpc(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_wasm_plugin), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_wasm_plugin(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.CreateWasmPluginRequest() - assert args[0] == request_msg + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "patch", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_wasm_plugin_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_wasm_plugin), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_wasm_plugin(request=None) + response = client.update_service_lb_policy(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.UpdateWasmPluginRequest() - assert args[0] == request_msg + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_wasm_plugin_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", +def test_update_service_lb_policy_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_wasm_plugin), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_wasm_plugin(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.DeleteWasmPluginRequest() - assert args[0] == request_msg + unset_fields = transport.update_service_lb_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("serviceLbPolicy",))) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_gateways_empty_call_grpc(): +def test_update_service_lb_policy_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_gateways), "__call__") as call: - call.return_value = gateway.ListGatewaysResponse() - client.list_gateways(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gateway.ListGatewaysRequest() - assert args[0] == request_msg + # get arguments that satisfy an http rule for this method + sample_request = { + "service_lb_policy": { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + } + } + # get truthy value for each flattened field + mock_args = dict( + service_lb_policy=gcn_service_lb_policy.ServiceLbPolicy(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + mock_args.update(sample_request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_gateway_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_gateway), "__call__") as call: - call.return_value = gateway.Gateway() - client.get_gateway(request=None) + client.update_service_lb_policy(**mock_args) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gateway.GetGatewayRequest() - assert args[0] == request_msg + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{service_lb_policy.name=projects/*/locations/*/serviceLbPolicies/*}" + % client.transport._host, + args[1], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_gateway_empty_call_grpc(): +def test_update_service_lb_policy_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_gateway), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_gateway(request=None) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_service_lb_policy( + gcn_service_lb_policy.UpdateServiceLbPolicyRequest(), + service_lb_policy=gcn_service_lb_policy.ServiceLbPolicy(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_gateway.CreateGatewayRequest() - assert args[0] == request_msg +def test_delete_service_lb_policy_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_gateway_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_gateway), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_gateway(request=None) + # Ensure method has been cached + assert ( + client._transport.delete_service_lb_policy + in client._transport._wrapped_methods + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_gateway.UpdateGatewayRequest() - assert args[0] == request_msg + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_service_lb_policy + ] = mock_rpc + request = {} + client.delete_service_lb_policy(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_gateway_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_gateway), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_gateway(request=None) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gateway.DeleteGatewayRequest() - assert args[0] == request_msg + client.delete_service_lb_policy(request) + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_grpc_routes_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_grpc_routes), "__call__") as call: - call.return_value = grpc_route.ListGrpcRoutesResponse() - client.list_grpc_routes(request=None) +def test_delete_service_lb_policy_rest_required_fields( + request_type=service_lb_policy.DeleteServiceLbPolicyRequest, +): + transport_class = transports.NetworkServicesRestTransport - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = grpc_route.ListGrpcRoutesRequest() - assert args[0] == request_msg + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + # verify fields with default values are dropped -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_grpc_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_service_lb_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_grpc_route), "__call__") as call: - call.return_value = grpc_route.GrpcRoute() - client.get_grpc_route(request=None) + # verify required fields with default values are now present - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = grpc_route.GetGrpcRouteRequest() - assert args[0] == request_msg + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_service_lb_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_grpc_route_empty_call_grpc(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_grpc_route), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_grpc_route(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_grpc_route.CreateGrpcRouteRequest() - assert args[0] == request_msg + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_grpc_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_grpc_route), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_grpc_route(request=None) + response = client.delete_service_lb_policy(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_grpc_route.UpdateGrpcRouteRequest() - assert args[0] == request_msg + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_grpc_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", +def test_delete_service_lb_policy_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_grpc_route), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_grpc_route(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = grpc_route.DeleteGrpcRouteRequest() - assert args[0] == request_msg + unset_fields = transport.delete_service_lb_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_http_routes_empty_call_grpc(): +def test_delete_service_lb_policy_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_http_routes), "__call__") as call: - call.return_value = http_route.ListHttpRoutesResponse() - client.list_http_routes(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = http_route.ListHttpRoutesRequest() - assert args[0] == request_msg + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + } + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_http_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_http_route), "__call__") as call: - call.return_value = http_route.HttpRoute() - client.get_http_route(request=None) + client.delete_service_lb_policy(**mock_args) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = http_route.GetHttpRouteRequest() - assert args[0] == request_msg + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/serviceLbPolicies/*}" + % client.transport._host, + args[1], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_http_route_empty_call_grpc(): +def test_delete_service_lb_policy_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_http_route), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_http_route(request=None) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_service_lb_policy( + service_lb_policy.DeleteServiceLbPolicyRequest(), + name="name_value", + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_http_route.CreateHttpRouteRequest() - assert args[0] == request_msg +def test_get_gateway_route_view_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_http_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_http_route), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_http_route(request=None) + # Ensure method has been cached + assert ( + client._transport.get_gateway_route_view + in client._transport._wrapped_methods + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_http_route.UpdateHttpRouteRequest() - assert args[0] == request_msg + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_gateway_route_view] = ( + mock_rpc + ) + request = {} + client.get_gateway_route_view(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_http_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_http_route), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_http_route(request=None) + client.get_gateway_route_view(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = http_route.DeleteHttpRouteRequest() - assert args[0] == request_msg + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_tcp_routes_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) +def test_get_gateway_route_view_rest_required_fields( + request_type=route_view.GetGatewayRouteViewRequest, +): + transport_class = transports.NetworkServicesRestTransport - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_tcp_routes), "__call__") as call: - call.return_value = tcp_route.ListTcpRoutesResponse() - client.list_tcp_routes(request=None) + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tcp_route.ListTcpRoutesRequest() - assert args[0] == request_msg + # verify fields with default values are dropped + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_gateway_route_view._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_tcp_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # verify required fields with default values are now present - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_tcp_route), "__call__") as call: - call.return_value = tcp_route.TcpRoute() - client.get_tcp_route(request=None) + jsonified_request["name"] = "name_value" - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tcp_route.GetTcpRouteRequest() - assert args[0] == request_msg + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_gateway_route_view._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_tcp_route_empty_call_grpc(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_tcp_route), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_tcp_route(request=None) + # Designate an appropriate value for the returned response. + return_value = route_view.GatewayRouteView() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_tcp_route.CreateTcpRouteRequest() - assert args[0] == request_msg + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = route_view.GatewayRouteView.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_tcp_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_tcp_route), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_tcp_route(request=None) + response = client.get_gateway_route_view(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_tcp_route.UpdateTcpRouteRequest() - assert args[0] == request_msg + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_tcp_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", +def test_get_gateway_route_view_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_tcp_route), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_tcp_route(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tcp_route.DeleteTcpRouteRequest() - assert args[0] == request_msg + unset_fields = transport.get_gateway_route_view._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_tls_routes_empty_call_grpc(): +def test_get_gateway_route_view_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_tls_routes), "__call__") as call: - call.return_value = tls_route.ListTlsRoutesResponse() - client.list_tls_routes(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = route_view.GatewayRouteView() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tls_route.ListTlsRoutesRequest() - assert args[0] == request_msg + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/gateways/sample3/routeViews/sample4" + } + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_tls_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = route_view.GatewayRouteView.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_tls_route), "__call__") as call: - call.return_value = tls_route.TlsRoute() - client.get_tls_route(request=None) + client.get_gateway_route_view(**mock_args) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tls_route.GetTlsRouteRequest() - assert args[0] == request_msg + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/gateways/*/routeViews/*}" + % client.transport._host, + args[1], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_tls_route_empty_call_grpc(): +def test_get_gateway_route_view_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_tls_route), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_tls_route(request=None) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_gateway_route_view( + route_view.GetGatewayRouteViewRequest(), + name="name_value", + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_tls_route.CreateTlsRouteRequest() - assert args[0] == request_msg +def test_get_mesh_route_view_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_tls_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_tls_route), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_tls_route(request=None) + # Ensure method has been cached + assert ( + client._transport.get_mesh_route_view in client._transport._wrapped_methods + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_tls_route.UpdateTlsRouteRequest() - assert args[0] == request_msg + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_mesh_route_view] = ( + mock_rpc + ) + request = {} + client.get_mesh_route_view(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_tls_route_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_tls_route), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_tls_route(request=None) + client.get_mesh_route_view(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tls_route.DeleteTlsRouteRequest() - assert args[0] == request_msg + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_service_bindings_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) +def test_get_mesh_route_view_rest_required_fields( + request_type=route_view.GetMeshRouteViewRequest, +): + transport_class = transports.NetworkServicesRestTransport - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_service_bindings), "__call__" - ) as call: - call.return_value = service_binding.ListServiceBindingsResponse() - client.list_service_bindings(request=None) + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_binding.ListServiceBindingsRequest() - assert args[0] == request_msg + # verify fields with default values are dropped + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_mesh_route_view._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_service_binding_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # verify required fields with default values are now present - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_service_binding), "__call__" - ) as call: - call.return_value = service_binding.ServiceBinding() - client.get_service_binding(request=None) + jsonified_request["name"] = "name_value" - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_binding.GetServiceBindingRequest() - assert args[0] == request_msg + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_mesh_route_view._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_service_binding_empty_call_grpc(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_service_binding), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_service_binding(request=None) + # Designate an appropriate value for the returned response. + return_value = route_view.MeshRouteView() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_service_binding.CreateServiceBindingRequest() - assert args[0] == request_msg + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = route_view.MeshRouteView.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_service_binding_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_service_binding), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_service_binding(request=None) + response = client.get_mesh_route_view(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_service_binding.UpdateServiceBindingRequest() - assert args[0] == request_msg + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_service_binding_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", +def test_get_mesh_route_view_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_service_binding), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_service_binding(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_binding.DeleteServiceBindingRequest() - assert args[0] == request_msg + unset_fields = transport.get_mesh_route_view._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_meshes_empty_call_grpc(): +def test_get_mesh_route_view_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_meshes), "__call__") as call: - call.return_value = mesh.ListMeshesResponse() - client.list_meshes(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = route_view.MeshRouteView() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = mesh.ListMeshesRequest() - assert args[0] == request_msg + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/meshes/sample3/routeViews/sample4" + } + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_mesh_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = route_view.MeshRouteView.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_mesh), "__call__") as call: - call.return_value = mesh.Mesh() - client.get_mesh(request=None) + client.get_mesh_route_view(**mock_args) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = mesh.GetMeshRequest() - assert args[0] == request_msg + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/meshes/*/routeViews/*}" + % client.transport._host, + args[1], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_mesh_empty_call_grpc(): +def test_get_mesh_route_view_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_mesh), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_mesh(request=None) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_mesh_route_view( + route_view.GetMeshRouteViewRequest(), + name="name_value", + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_mesh.CreateMeshRequest() - assert args[0] == request_msg +def test_list_gateway_route_views_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_mesh_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_mesh), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_mesh(request=None) + # Ensure method has been cached + assert ( + client._transport.list_gateway_route_views + in client._transport._wrapped_methods + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_mesh.UpdateMeshRequest() - assert args[0] == request_msg + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_gateway_route_views + ] = mock_rpc + request = {} + client.list_gateway_route_views(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_mesh_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_mesh), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_mesh(request=None) + client.list_gateway_route_views(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = mesh.DeleteMeshRequest() - assert args[0] == request_msg + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_service_lb_policies_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) +def test_list_gateway_route_views_rest_required_fields( + request_type=route_view.ListGatewayRouteViewsRequest, +): + transport_class = transports.NetworkServicesRestTransport - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_service_lb_policies), "__call__" - ) as call: - call.return_value = service_lb_policy.ListServiceLbPoliciesResponse() - client.list_service_lb_policies(request=None) + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_lb_policy.ListServiceLbPoliciesRequest() - assert args[0] == request_msg + # verify fields with default values are dropped + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_gateway_route_views._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_service_lb_policy_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # verify required fields with default values are now present - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_service_lb_policy), "__call__" - ) as call: - call.return_value = service_lb_policy.ServiceLbPolicy() - client.get_service_lb_policy(request=None) + jsonified_request["parent"] = "parent_value" - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_lb_policy.GetServiceLbPolicyRequest() - assert args[0] == request_msg + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_gateway_route_views._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_service_lb_policy_empty_call_grpc(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_service_lb_policy), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_service_lb_policy(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_service_lb_policy.CreateServiceLbPolicyRequest() - assert args[0] == request_msg + # Designate an appropriate value for the returned response. + return_value = route_view.ListGatewayRouteViewsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + response_value = Response() + response_value.status_code = 200 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_service_lb_policy_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Convert return value to protobuf type + return_value = route_view.ListGatewayRouteViewsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_service_lb_policy), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_service_lb_policy(request=None) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_service_lb_policy.UpdateServiceLbPolicyRequest() - assert args[0] == request_msg + response = client.list_gateway_route_views(request) + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_service_lb_policy_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_service_lb_policy), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_service_lb_policy(request=None) +def test_list_gateway_route_views_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_lb_policy.DeleteServiceLbPolicyRequest() - assert args[0] == request_msg + unset_fields = transport.list_gateway_route_views._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_gateway_route_view_empty_call_grpc(): +def test_list_gateway_route_views_rest_flattened(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_gateway_route_view), "__call__" - ) as call: - call.return_value = route_view.GatewayRouteView() - client.get_gateway_route_view(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = route_view.ListGatewayRouteViewsResponse() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = route_view.GetGatewayRouteViewRequest() - assert args[0] == request_msg + # get arguments that satisfy an http rule for this method + sample_request = { + "parent": "projects/sample1/locations/sample2/gateways/sample3" + } + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_mesh_route_view_empty_call_grpc(): - client = NetworkServicesClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = route_view.ListGatewayRouteViewsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_mesh_route_view), "__call__" - ) as call: - call.return_value = route_view.MeshRouteView() - client.get_mesh_route_view(request=None) + client.list_gateway_route_views(**mock_args) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = route_view.GetMeshRouteViewRequest() - assert args[0] == request_msg + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*/gateways/*}/routeViews" + % client.transport._host, + args[1], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_gateway_route_views_empty_call_grpc(): +def test_list_gateway_route_views_rest_flattened_error(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_gateway_route_views), "__call__" - ) as call: - call.return_value = route_view.ListGatewayRouteViewsResponse() - client.list_gateway_route_views(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = route_view.ListGatewayRouteViewsRequest() - assert args[0] == request_msg + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_gateway_route_views( + route_view.ListGatewayRouteViewsRequest(), + parent="parent_value", + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_mesh_route_views_empty_call_grpc(): +def test_list_gateway_route_views_rest_pager(transport: str = "rest"): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_mesh_route_views), "__call__" - ) as call: - call.return_value = route_view.ListMeshRouteViewsResponse() - client.list_mesh_route_views(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + route_view.ListGatewayRouteViewsResponse( + gateway_route_views=[ + route_view.GatewayRouteView(), + route_view.GatewayRouteView(), + route_view.GatewayRouteView(), + ], + next_page_token="abc", + ), + route_view.ListGatewayRouteViewsResponse( + gateway_route_views=[], + next_page_token="def", + ), + route_view.ListGatewayRouteViewsResponse( + gateway_route_views=[ + route_view.GatewayRouteView(), + ], + next_page_token="ghi", + ), + route_view.ListGatewayRouteViewsResponse( + gateway_route_views=[ + route_view.GatewayRouteView(), + route_view.GatewayRouteView(), + ], + ), + ) + # Two responses for two calls + response = response + response - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = route_view.ListMeshRouteViewsRequest() - assert args[0] == request_msg + # Wrap the values into proper Response objs + response = tuple( + route_view.ListGatewayRouteViewsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + sample_request = { + "parent": "projects/sample1/locations/sample2/gateways/sample3" + } -def test_transport_kind_grpc_asyncio(): - transport = NetworkServicesAsyncClient.get_transport_class("grpc_asyncio")( - credentials=async_anonymous_credentials() - ) - assert transport.kind == "grpc_asyncio" + pager = client.list_gateway_route_views(request=sample_request) + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, route_view.GatewayRouteView) for i in results) -def test_initialize_client_w_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), transport="grpc_asyncio" - ) - assert client is not None + pages = list(client.list_gateway_route_views(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_endpoint_policies_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) +def test_list_mesh_route_views_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_endpoint_policies), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - endpoint_policy.ListEndpointPoliciesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_mesh_route_views + in client._transport._wrapped_methods ) - await client.list_endpoint_policies(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = endpoint_policy.ListEndpointPoliciesRequest() - assert args[0] == request_msg + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.list_mesh_route_views] = ( + mock_rpc + ) + request = {} + client.list_mesh_route_views(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_endpoint_policy_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_endpoint_policy), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - endpoint_policy.EndpointPolicy( - name="name_value", - type_=endpoint_policy.EndpointPolicy.EndpointPolicyType.SIDECAR_PROXY, - authorization_policy="authorization_policy_value", - description="description_value", - server_tls_policy="server_tls_policy_value", - client_tls_policy="client_tls_policy_value", - ) - ) - await client.get_endpoint_policy(request=None) + client.list_mesh_route_views(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = endpoint_policy.GetEndpointPolicyRequest() - assert args[0] == request_msg + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_endpoint_policy_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_mesh_route_views_rest_required_fields( + request_type=route_view.ListMeshRouteViewsRequest, +): + transport_class = transports.NetworkServicesRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_endpoint_policy), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_endpoint_policy(request=None) + # verify fields with default values are dropped - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_endpoint_policy.CreateEndpointPolicyRequest() - assert args[0] == request_msg + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_mesh_route_views._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + # verify required fields with default values are now present -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_endpoint_policy_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + jsonified_request["parent"] = "parent_value" - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_endpoint_policy), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_mesh_route_views._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", ) - await client.update_endpoint_policy(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_endpoint_policy.UpdateEndpointPolicyRequest() - assert args[0] == request_msg + ) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_endpoint_policy_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_endpoint_policy), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_endpoint_policy(request=None) + # Designate an appropriate value for the returned response. + return_value = route_view.ListMeshRouteViewsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = endpoint_policy.DeleteEndpointPolicyRequest() - assert args[0] == request_msg + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = route_view.ListMeshRouteViewsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_wasm_plugin_versions_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_mesh_route_views(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) + + +def test_list_mesh_route_views_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_wasm_plugin_versions), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - extensibility.ListWasmPluginVersionsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + unset_fields = transport.list_mesh_route_views._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", ) ) - await client.list_wasm_plugin_versions(request=None) + & set(("parent",)) + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.ListWasmPluginVersionsRequest() - assert args[0] == request_msg +def test_list_mesh_route_views_rest_flattened(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_wasm_plugin_version_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_wasm_plugin_version), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - extensibility.WasmPluginVersion( - name="name_value", - description="description_value", - image_uri="image_uri_value", - image_digest="image_digest_value", - plugin_config_digest="plugin_config_digest_value", - ) - ) - await client.get_wasm_plugin_version(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.GetWasmPluginVersionRequest() - assert args[0] == request_msg - + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = route_view.ListMeshRouteViewsResponse() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_wasm_plugin_version_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2/meshes/sample3"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_wasm_plugin_version), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", ) - await client.create_wasm_plugin_version(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.CreateWasmPluginVersionRequest() - assert args[0] == request_msg + mock_args.update(sample_request) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = route_view.ListMeshRouteViewsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_wasm_plugin_version_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + client.list_mesh_route_views(**mock_args) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_wasm_plugin_version), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*/meshes/*}/routeViews" + % client.transport._host, + args[1], ) - await client.delete_wasm_plugin_version(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.DeleteWasmPluginVersionRequest() - assert args[0] == request_msg -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_wasm_plugins_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_mesh_route_views_rest_flattened_error(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_wasm_plugins), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - extensibility.ListWasmPluginsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_mesh_route_views( + route_view.ListMeshRouteViewsRequest(), + parent="parent_value", ) - await client.list_wasm_plugins(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.ListWasmPluginsRequest() - assert args[0] == request_msg -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_wasm_plugin_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_mesh_route_views_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_wasm_plugin), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - extensibility.WasmPlugin( - name="name_value", - description="description_value", - main_version_id="main_version_id_value", - ) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + route_view.ListMeshRouteViewsResponse( + mesh_route_views=[ + route_view.MeshRouteView(), + route_view.MeshRouteView(), + route_view.MeshRouteView(), + ], + next_page_token="abc", + ), + route_view.ListMeshRouteViewsResponse( + mesh_route_views=[], + next_page_token="def", + ), + route_view.ListMeshRouteViewsResponse( + mesh_route_views=[ + route_view.MeshRouteView(), + ], + next_page_token="ghi", + ), + route_view.ListMeshRouteViewsResponse( + mesh_route_views=[ + route_view.MeshRouteView(), + route_view.MeshRouteView(), + ], + ), ) - await client.get_wasm_plugin(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.GetWasmPluginRequest() - assert args[0] == request_msg + # Two responses for two calls + response = response + response + # Wrap the values into proper Response objs + response = tuple( + route_view.ListMeshRouteViewsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_wasm_plugin_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + sample_request = {"parent": "projects/sample1/locations/sample2/meshes/sample3"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_wasm_plugin), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_wasm_plugin(request=None) + pager = client.list_mesh_route_views(request=sample_request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.CreateWasmPluginRequest() - assert args[0] == request_msg + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, route_view.MeshRouteView) for i in results) + pages = list(client.list_mesh_route_views(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_wasm_plugin_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_wasm_plugin), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") +def test_list_agent_gateways_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) - await client.update_wasm_plugin(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.UpdateWasmPluginRequest() - assert args[0] == request_msg + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_wasm_plugin_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Ensure method has been cached + assert ( + client._transport.list_agent_gateways in client._transport._wrapped_methods + ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_wasm_plugin), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.list_agent_gateways] = ( + mock_rpc ) - await client.delete_wasm_plugin(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = extensibility.DeleteWasmPluginRequest() - assert args[0] == request_msg + request = {} + client.list_agent_gateways(request) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_gateways_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + client.list_agent_gateways(request) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_gateways), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gateway.ListGatewaysResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_gateways(request=None) + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gateway.ListGatewaysRequest() - assert args[0] == request_msg +def test_list_agent_gateways_rest_required_fields( + request_type=agent_gateway.ListAgentGatewaysRequest, +): + transport_class = transports.NetworkServicesRestTransport -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_gateway_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_gateway), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gateway.Gateway( - name="name_value", - self_link="self_link_value", - description="description_value", - type_=gateway.Gateway.Type.OPEN_MESH, - addresses=["addresses_value"], - ports=[568], - scope="scope_value", - server_tls_policy="server_tls_policy_value", - certificate_urls=["certificate_urls_value"], - gateway_security_policy="gateway_security_policy_value", - network="network_value", - subnetwork="subnetwork_value", - ip_version=gateway.Gateway.IpVersion.IPV4, - envoy_headers=common.EnvoyHeaders.NONE, - routing_mode=gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE, - ) - ) - await client.get_gateway(request=None) + # verify fields with default values are dropped - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gateway.GetGatewayRequest() - assert args[0] == request_msg + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_agent_gateways._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + # verify required fields with default values are now present -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_gateway_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + jsonified_request["parent"] = "parent_value" - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_gateway), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_agent_gateways._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + "return_partial_success", ) - await client.create_gateway(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_gateway.CreateGatewayRequest() - assert args[0] == request_msg + ) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_gateway_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_gateway), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_gateway(request=None) + # Designate an appropriate value for the returned response. + return_value = agent_gateway.ListAgentGatewaysResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_gateway.UpdateGatewayRequest() - assert args[0] == request_msg + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = agent_gateway.ListAgentGatewaysResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_gateway_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_gateway), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_gateway(request=None) + response = client.list_agent_gateways(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gateway.DeleteGatewayRequest() - assert args[0] == request_msg + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_grpc_routes_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_agent_gateways_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_grpc_routes), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - grpc_route.ListGrpcRoutesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + unset_fields = transport.list_agent_gateways._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + "returnPartialSuccess", ) ) - await client.list_grpc_routes(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = grpc_route.ListGrpcRoutesRequest() - assert args[0] == request_msg + & set(("parent",)) + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_grpc_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_agent_gateways_rest_flattened(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_grpc_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - grpc_route.GrpcRoute( - name="name_value", - self_link="self_link_value", - description="description_value", - hostnames=["hostnames_value"], - meshes=["meshes_value"], - gateways=["gateways_value"], - ) - ) - await client.get_grpc_route(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = agent_gateway.ListAgentGatewaysResponse() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = grpc_route.GetGrpcRouteRequest() - assert args[0] == request_msg + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_grpc_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = agent_gateway.ListAgentGatewaysResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_grpc_route), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_grpc_route(request=None) + client.list_agent_gateways(**mock_args) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_grpc_route.CreateGrpcRouteRequest() - assert args[0] == request_msg + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/agentGateways" + % client.transport._host, + args[1], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_grpc_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_agent_gateways_rest_flattened_error(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_grpc_route), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_agent_gateways( + agent_gateway.ListAgentGatewaysRequest(), + parent="parent_value", ) - await client.update_grpc_route(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_grpc_route.UpdateGrpcRouteRequest() - assert args[0] == request_msg -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_grpc_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_agent_gateways_rest_pager(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_grpc_route), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + ], + next_page_token="abc", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[], + next_page_token="def", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + ], + next_page_token="ghi", + ), + agent_gateway.ListAgentGatewaysResponse( + agent_gateways=[ + agent_gateway.AgentGateway(), + agent_gateway.AgentGateway(), + ], + ), ) - await client.delete_grpc_route(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = grpc_route.DeleteGrpcRouteRequest() - assert args[0] == request_msg + # Two responses for two calls + response = response + response + # Wrap the values into proper Response objs + response = tuple( + agent_gateway.ListAgentGatewaysResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_http_routes_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + sample_request = {"parent": "projects/sample1/locations/sample2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_http_routes), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - http_route.ListHttpRoutesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_http_routes(request=None) + pager = client.list_agent_gateways(request=sample_request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = http_route.ListHttpRoutesRequest() - assert args[0] == request_msg + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, agent_gateway.AgentGateway) for i in results) + pages = list(client.list_agent_gateways(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_http_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_http_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - http_route.HttpRoute( - name="name_value", - self_link="self_link_value", - description="description_value", - hostnames=["hostnames_value"], - meshes=["meshes_value"], - gateways=["gateways_value"], - ) +def test_get_agent_gateway_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) - await client.get_http_route(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = http_route.GetHttpRouteRequest() - assert args[0] == request_msg + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_http_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Ensure method has been cached + assert client._transport.get_agent_gateway in client._transport._wrapped_methods - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_http_route), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_agent_gateway] = ( + mock_rpc ) - await client.create_http_route(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_http_route.CreateHttpRouteRequest() - assert args[0] == request_msg + request = {} + client.get_agent_gateway(request) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_http_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + client.get_agent_gateway(request) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_http_route), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_http_route(request=None) + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_http_route.UpdateHttpRouteRequest() - assert args[0] == request_msg +def test_get_agent_gateway_rest_required_fields( + request_type=agent_gateway.GetAgentGatewayRequest, +): + transport_class = transports.NetworkServicesRestTransport -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_http_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_http_route), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_http_route(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = http_route.DeleteHttpRouteRequest() - assert args[0] == request_msg + # verify fields with default values are dropped + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_agent_gateway._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_tcp_routes_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # verify required fields with default values are now present - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_tcp_routes), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tcp_route.ListTcpRoutesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_tcp_routes(request=None) + jsonified_request["name"] = "name_value" - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tcp_route.ListTcpRoutesRequest() - assert args[0] == request_msg + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_agent_gateway._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_tcp_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_tcp_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tcp_route.TcpRoute( - name="name_value", - self_link="self_link_value", - description="description_value", - meshes=["meshes_value"], - gateways=["gateways_value"], - ) - ) - await client.get_tcp_route(request=None) + # Designate an appropriate value for the returned response. + return_value = agent_gateway.AgentGateway() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tcp_route.GetTcpRouteRequest() - assert args[0] == request_msg + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = agent_gateway.AgentGateway.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_tcp_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_tcp_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_tcp_route(request=None) + response = client.get_agent_gateway(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_tcp_route.CreateTcpRouteRequest() - assert args[0] == request_msg + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_tcp_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_agent_gateway_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_tcp_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_tcp_route(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_tcp_route.UpdateTcpRouteRequest() - assert args[0] == request_msg + unset_fields = transport.get_agent_gateway._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_tcp_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_agent_gateway_rest_flattened(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_tcp_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_tcp_route(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = agent_gateway.AgentGateway() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tcp_route.DeleteTcpRouteRequest() - assert args[0] == request_msg + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/agentGateways/sample3" + } + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_tls_routes_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = agent_gateway.AgentGateway.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_tls_routes), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tls_route.ListTlsRoutesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_tls_routes(request=None) + client.get_agent_gateway(**mock_args) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tls_route.ListTlsRoutesRequest() - assert args[0] == request_msg + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/agentGateways/*}" + % client.transport._host, + args[1], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_tls_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_agent_gateway_rest_flattened_error(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_tls_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tls_route.TlsRoute( - name="name_value", - self_link="self_link_value", - description="description_value", - meshes=["meshes_value"], - gateways=["gateways_value"], - ) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_agent_gateway( + agent_gateway.GetAgentGatewayRequest(), + name="name_value", ) - await client.get_tls_route(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tls_route.GetTlsRouteRequest() - assert args[0] == request_msg +def test_create_agent_gateway_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_tls_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_tls_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + # Ensure method has been cached + assert ( + client._transport.create_agent_gateway in client._transport._wrapped_methods ) - await client.create_tls_route(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_tls_route.CreateTlsRouteRequest() - assert args[0] == request_msg + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.create_agent_gateway] = ( + mock_rpc + ) + request = {} + client.create_agent_gateway(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_tls_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_tls_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_tls_route(request=None) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_tls_route.UpdateTlsRouteRequest() - assert args[0] == request_msg + client.create_agent_gateway(request) + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_tls_route_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_tls_route), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_tls_route(request=None) +def test_create_agent_gateway_rest_required_fields( + request_type=gcn_agent_gateway.CreateAgentGatewayRequest, +): + transport_class = transports.NetworkServicesRestTransport - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = tls_route.DeleteTlsRouteRequest() - assert args[0] == request_msg + request_init = {} + request_init["parent"] = "" + request_init["agent_gateway_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + # verify fields with default values are dropped + assert "agentGatewayId" not in jsonified_request -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_service_bindings_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_agent_gateway._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_service_bindings), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service_binding.ListServiceBindingsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_service_bindings(request=None) + # verify required fields with default values are now present + assert "agentGatewayId" in jsonified_request + assert jsonified_request["agentGatewayId"] == request_init["agent_gateway_id"] - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_binding.ListServiceBindingsRequest() - assert args[0] == request_msg + jsonified_request["parent"] = "parent_value" + jsonified_request["agentGatewayId"] = "agent_gateway_id_value" + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_agent_gateway._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("agent_gateway_id",)) + jsonified_request.update(unset_fields) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_service_binding_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "agentGatewayId" in jsonified_request + assert jsonified_request["agentGatewayId"] == "agent_gateway_id_value" - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_service_binding), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service_binding.ServiceBinding( - name="name_value", - description="description_value", - service="service_value", - service_id="service_id_value", - ) - ) - await client.get_service_binding(request=None) + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_binding.GetServiceBindingRequest() - assert args[0] == request_msg + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_service_binding_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_service_binding), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_service_binding(request=None) + response = client.create_agent_gateway(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_service_binding.CreateServiceBindingRequest() - assert args[0] == request_msg + expected_params = [ + ( + "agentGatewayId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_service_binding_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_create_agent_gateway_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_service_binding), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + unset_fields = transport.create_agent_gateway._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("agentGatewayId",)) + & set( + ( + "parent", + "agentGatewayId", + "agentGateway", + ) ) - await client.update_service_binding(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_service_binding.UpdateServiceBindingRequest() - assert args[0] == request_msg + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_service_binding_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_create_agent_gateway_rest_flattened(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_service_binding), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_service_binding(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_binding.DeleteServiceBindingRequest() - assert args[0] == request_msg + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + agent_gateway_id="agent_gateway_id_value", + ) + mock_args.update(sample_request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_meshes_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_meshes), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - mesh.ListMeshesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_meshes(request=None) + client.create_agent_gateway(**mock_args) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = mesh.ListMeshesRequest() - assert args[0] == request_msg + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/agentGateways" + % client.transport._host, + args[1], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_mesh_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_create_agent_gateway_rest_flattened_error(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_mesh), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - mesh.Mesh( - name="name_value", - self_link="self_link_value", - description="description_value", - interception_port=1848, - envoy_headers=common.EnvoyHeaders.NONE, - ) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_agent_gateway( + gcn_agent_gateway.CreateAgentGatewayRequest(), + parent="parent_value", + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + agent_gateway_id="agent_gateway_id_value", ) - await client.get_mesh(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = mesh.GetMeshRequest() - assert args[0] == request_msg +def test_update_agent_gateway_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_mesh_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_mesh), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + # Ensure method has been cached + assert ( + client._transport.update_agent_gateway in client._transport._wrapped_methods ) - await client.create_mesh(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_mesh.CreateMeshRequest() - assert args[0] == request_msg + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.update_agent_gateway] = ( + mock_rpc + ) + request = {} + client.update_agent_gateway(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_mesh_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_mesh), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_mesh(request=None) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_mesh.UpdateMeshRequest() - assert args[0] == request_msg + client.update_agent_gateway(request) + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_mesh_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_mesh), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_mesh(request=None) +def test_update_agent_gateway_rest_required_fields( + request_type=gcn_agent_gateway.UpdateAgentGatewayRequest, +): + transport_class = transports.NetworkServicesRestTransport - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = mesh.DeleteMeshRequest() - assert args[0] == request_msg + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + # verify fields with default values are dropped -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_service_lb_policies_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_agent_gateway._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_service_lb_policies), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service_lb_policy.ListServiceLbPoliciesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_service_lb_policies(request=None) + # verify required fields with default values are now present - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_lb_policy.ListServiceLbPoliciesRequest() - assert args[0] == request_msg + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_agent_gateway._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) + jsonified_request.update(unset_fields) + # verify required fields with non-default values are left alone -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_service_lb_policy_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "patch", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.update_agent_gateway(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) + + +def test_update_agent_gateway_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.update_agent_gateway._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("agentGateway",))) + + +def test_update_agent_gateway_rest_flattened(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "agent_gateway": { + "name": "projects/sample1/locations/sample2/agentGateways/sample3" + } + } + + # get truthy value for each flattened field + mock_args = dict( + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.update_agent_gateway(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{agent_gateway.name=projects/*/locations/*/agentGateways/*}" + % client.transport._host, + args[1], + ) + + +def test_update_agent_gateway_rest_flattened_error(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_agent_gateway( + gcn_agent_gateway.UpdateAgentGatewayRequest(), + agent_gateway=gcn_agent_gateway.AgentGateway( + google_managed=gcn_agent_gateway.AgentGateway.GoogleManaged( + governed_access_path=gcn_agent_gateway.AgentGateway.GoogleManaged.GovernedAccessPath.AGENT_TO_ANYWHERE + ) + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +def test_delete_agent_gateway_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_agent_gateway in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.delete_agent_gateway] = ( + mock_rpc + ) + + request = {} + client.delete_agent_gateway(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_agent_gateway(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_delete_agent_gateway_rest_required_fields( + request_type=agent_gateway.DeleteAgentGatewayRequest, +): + transport_class = transports.NetworkServicesRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_agent_gateway._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_agent_gateway._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("etag",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.delete_agent_gateway(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert sorted(expected_params) == sorted(actual_params) + + +def test_delete_agent_gateway_rest_unset_required_fields(): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_agent_gateway._get_unset_required_fields({}) + assert set(unset_fields) == (set(("etag",)) & set(("name",))) + + +def test_delete_agent_gateway_rest_flattened(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/agentGateways/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.delete_agent_gateway(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/agentGateways/*}" + % client.transport._host, + args[1], + ) + + +def test_delete_agent_gateway_rest_flattened_error(transport: str = "rest"): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_agent_gateway( + agent_gateway.DeleteAgentGatewayRequest(), + name="name_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.NetworkServicesGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.NetworkServicesGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = NetworkServicesClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.NetworkServicesGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = NetworkServicesClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = NetworkServicesClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.NetworkServicesGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = NetworkServicesClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.NetworkServicesGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = NetworkServicesClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.NetworkServicesGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.NetworkServicesGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.NetworkServicesGrpcTransport, + transports.NetworkServicesGrpcAsyncIOTransport, + transports.NetworkServicesRestTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +def test_transport_kind_grpc(): + transport = NetworkServicesClient.get_transport_class("grpc")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "grpc" + + +def test_initialize_client_w_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_endpoint_policies_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.get_service_lb_policy), "__call__" + type(client.transport.list_endpoint_policies), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service_lb_policy.ServiceLbPolicy( - name="name_value", - description="description_value", - load_balancing_algorithm=service_lb_policy.ServiceLbPolicy.LoadBalancingAlgorithm.SPRAY_TO_WORLD, - ) - ) - await client.get_service_lb_policy(request=None) + call.return_value = endpoint_policy.ListEndpointPoliciesResponse() + client.list_endpoint_policies(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = endpoint_policy.ListEndpointPoliciesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_endpoint_policy_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_endpoint_policy), "__call__" + ) as call: + call.return_value = endpoint_policy.EndpointPolicy() + client.get_endpoint_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = endpoint_policy.GetEndpointPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_endpoint_policy_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_endpoint_policy), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_endpoint_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_endpoint_policy.CreateEndpointPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_endpoint_policy_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_endpoint_policy), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_endpoint_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_endpoint_policy.UpdateEndpointPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_endpoint_policy_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_endpoint_policy), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_endpoint_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = endpoint_policy.DeleteEndpointPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_wasm_plugin_versions_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_wasm_plugin_versions), "__call__" + ) as call: + call.return_value = extensibility.ListWasmPluginVersionsResponse() + client.list_wasm_plugin_versions(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.ListWasmPluginVersionsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_wasm_plugin_version_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_wasm_plugin_version), "__call__" + ) as call: + call.return_value = extensibility.WasmPluginVersion() + client.get_wasm_plugin_version(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.GetWasmPluginVersionRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_wasm_plugin_version_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_wasm_plugin_version), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_wasm_plugin_version(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.CreateWasmPluginVersionRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_wasm_plugin_version_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_wasm_plugin_version), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_wasm_plugin_version(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.DeleteWasmPluginVersionRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_wasm_plugins_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_wasm_plugins), "__call__" + ) as call: + call.return_value = extensibility.ListWasmPluginsResponse() + client.list_wasm_plugins(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.ListWasmPluginsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_wasm_plugin_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_wasm_plugin), "__call__") as call: + call.return_value = extensibility.WasmPlugin() + client.get_wasm_plugin(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.GetWasmPluginRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_wasm_plugin_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_wasm_plugin), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_wasm_plugin(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.CreateWasmPluginRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_wasm_plugin_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_wasm_plugin), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_wasm_plugin(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.UpdateWasmPluginRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_wasm_plugin_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_wasm_plugin), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_wasm_plugin(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.DeleteWasmPluginRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_gateways_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_gateways), "__call__") as call: + call.return_value = gateway.ListGatewaysResponse() + client.list_gateways(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gateway.ListGatewaysRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_gateway_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_gateway), "__call__") as call: + call.return_value = gateway.Gateway() + client.get_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gateway.GetGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_gateway_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_gateway), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_gateway.CreateGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_gateway_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_gateway), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_gateway.UpdateGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_gateway_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_gateway), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gateway.DeleteGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_grpc_routes_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_grpc_routes), "__call__") as call: + call.return_value = grpc_route.ListGrpcRoutesResponse() + client.list_grpc_routes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = grpc_route.ListGrpcRoutesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_grpc_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_grpc_route), "__call__") as call: + call.return_value = grpc_route.GrpcRoute() + client.get_grpc_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = grpc_route.GetGrpcRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_grpc_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_grpc_route), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_grpc_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_grpc_route.CreateGrpcRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_grpc_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_grpc_route), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_grpc_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_grpc_route.UpdateGrpcRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_grpc_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_grpc_route), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_grpc_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = grpc_route.DeleteGrpcRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_http_routes_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_http_routes), "__call__") as call: + call.return_value = http_route.ListHttpRoutesResponse() + client.list_http_routes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = http_route.ListHttpRoutesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_http_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_http_route), "__call__") as call: + call.return_value = http_route.HttpRoute() + client.get_http_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = http_route.GetHttpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_http_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_http_route), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_http_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_http_route.CreateHttpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_http_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_http_route), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_http_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_http_route.UpdateHttpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_http_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_http_route), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_http_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = http_route.DeleteHttpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_tcp_routes_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_tcp_routes), "__call__") as call: + call.return_value = tcp_route.ListTcpRoutesResponse() + client.list_tcp_routes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tcp_route.ListTcpRoutesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_tcp_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_tcp_route), "__call__") as call: + call.return_value = tcp_route.TcpRoute() + client.get_tcp_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tcp_route.GetTcpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_tcp_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_tcp_route), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_tcp_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_tcp_route.CreateTcpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_tcp_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_tcp_route), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_tcp_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_tcp_route.UpdateTcpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_tcp_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_tcp_route), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_tcp_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tcp_route.DeleteTcpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_tls_routes_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_tls_routes), "__call__") as call: + call.return_value = tls_route.ListTlsRoutesResponse() + client.list_tls_routes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tls_route.ListTlsRoutesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_tls_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_tls_route), "__call__") as call: + call.return_value = tls_route.TlsRoute() + client.get_tls_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tls_route.GetTlsRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_tls_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_tls_route), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_tls_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_tls_route.CreateTlsRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_tls_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_tls_route), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_tls_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_tls_route.UpdateTlsRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_tls_route_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_tls_route), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_tls_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tls_route.DeleteTlsRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_service_bindings_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_service_bindings), "__call__" + ) as call: + call.return_value = service_binding.ListServiceBindingsResponse() + client.list_service_bindings(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_binding.ListServiceBindingsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_service_binding_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_service_binding), "__call__" + ) as call: + call.return_value = service_binding.ServiceBinding() + client.get_service_binding(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_binding.GetServiceBindingRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_service_binding_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_service_binding), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_service_binding(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_service_binding.CreateServiceBindingRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_service_binding_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_service_binding), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_service_binding(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_service_binding.UpdateServiceBindingRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_service_binding_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_service_binding), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_service_binding(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_binding.DeleteServiceBindingRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_meshes_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_meshes), "__call__") as call: + call.return_value = mesh.ListMeshesResponse() + client.list_meshes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = mesh.ListMeshesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_mesh_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_mesh), "__call__") as call: + call.return_value = mesh.Mesh() + client.get_mesh(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = mesh.GetMeshRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_mesh_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_mesh), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_mesh(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_mesh.CreateMeshRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_mesh_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_mesh), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_mesh(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_mesh.UpdateMeshRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_mesh_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_mesh), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_mesh(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = mesh.DeleteMeshRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_service_lb_policies_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_service_lb_policies), "__call__" + ) as call: + call.return_value = service_lb_policy.ListServiceLbPoliciesResponse() + client.list_service_lb_policies(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_lb_policy.ListServiceLbPoliciesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_service_lb_policy_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_service_lb_policy), "__call__" + ) as call: + call.return_value = service_lb_policy.ServiceLbPolicy() + client.get_service_lb_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_lb_policy.GetServiceLbPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_service_lb_policy_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_service_lb_policy), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_service_lb_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_service_lb_policy.CreateServiceLbPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_service_lb_policy_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_service_lb_policy), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_service_lb_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_service_lb_policy.UpdateServiceLbPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_service_lb_policy_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_service_lb_policy), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_service_lb_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_lb_policy.DeleteServiceLbPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_gateway_route_view_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_gateway_route_view), "__call__" + ) as call: + call.return_value = route_view.GatewayRouteView() + client.get_gateway_route_view(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = route_view.GetGatewayRouteViewRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_mesh_route_view_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_mesh_route_view), "__call__" + ) as call: + call.return_value = route_view.MeshRouteView() + client.get_mesh_route_view(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = route_view.GetMeshRouteViewRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_gateway_route_views_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_gateway_route_views), "__call__" + ) as call: + call.return_value = route_view.ListGatewayRouteViewsResponse() + client.list_gateway_route_views(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = route_view.ListGatewayRouteViewsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_mesh_route_views_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_mesh_route_views), "__call__" + ) as call: + call.return_value = route_view.ListMeshRouteViewsResponse() + client.list_mesh_route_views(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = route_view.ListMeshRouteViewsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_agent_gateways_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + call.return_value = agent_gateway.ListAgentGatewaysResponse() + client.list_agent_gateways(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.ListAgentGatewaysRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_agent_gateway_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + call.return_value = agent_gateway.AgentGateway() + client.get_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.GetAgentGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_agent_gateway_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_agent_gateway.CreateAgentGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_agent_gateway_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_agent_gateway.UpdateAgentGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_agent_gateway_empty_call_grpc(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.DeleteAgentGatewayRequest() + assert args[0] == request_msg + + +def test_transport_kind_grpc_asyncio(): + transport = NetworkServicesAsyncClient.get_transport_class("grpc_asyncio")( + credentials=async_anonymous_credentials() + ) + assert transport.kind == "grpc_asyncio" + + +def test_initialize_client_w_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), transport="grpc_asyncio" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_endpoint_policies_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_endpoint_policies), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + endpoint_policy.ListEndpointPoliciesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_endpoint_policies(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = endpoint_policy.ListEndpointPoliciesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_endpoint_policy_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_endpoint_policy), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + endpoint_policy.EndpointPolicy( + name="name_value", + type_=endpoint_policy.EndpointPolicy.EndpointPolicyType.SIDECAR_PROXY, + authorization_policy="authorization_policy_value", + description="description_value", + server_tls_policy="server_tls_policy_value", + client_tls_policy="client_tls_policy_value", + ) + ) + await client.get_endpoint_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = endpoint_policy.GetEndpointPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_endpoint_policy_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_endpoint_policy), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_endpoint_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_endpoint_policy.CreateEndpointPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_endpoint_policy_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_endpoint_policy), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_endpoint_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_endpoint_policy.UpdateEndpointPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_endpoint_policy_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_endpoint_policy), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_endpoint_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = endpoint_policy.DeleteEndpointPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_wasm_plugin_versions_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_wasm_plugin_versions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + extensibility.ListWasmPluginVersionsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_wasm_plugin_versions(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.ListWasmPluginVersionsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_wasm_plugin_version_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_wasm_plugin_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + extensibility.WasmPluginVersion( + name="name_value", + description="description_value", + image_uri="image_uri_value", + image_digest="image_digest_value", + plugin_config_digest="plugin_config_digest_value", + ) + ) + await client.get_wasm_plugin_version(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.GetWasmPluginVersionRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_wasm_plugin_version_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_wasm_plugin_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_wasm_plugin_version(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.CreateWasmPluginVersionRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_wasm_plugin_version_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_wasm_plugin_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_wasm_plugin_version(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.DeleteWasmPluginVersionRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_wasm_plugins_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_wasm_plugins), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + extensibility.ListWasmPluginsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_wasm_plugins(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.ListWasmPluginsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_wasm_plugin_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_wasm_plugin), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + extensibility.WasmPlugin( + name="name_value", + description="description_value", + main_version_id="main_version_id_value", + ) + ) + await client.get_wasm_plugin(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.GetWasmPluginRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_wasm_plugin_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_wasm_plugin), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_wasm_plugin(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.CreateWasmPluginRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_wasm_plugin_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_wasm_plugin), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_wasm_plugin(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.UpdateWasmPluginRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_wasm_plugin_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_wasm_plugin), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_wasm_plugin(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = extensibility.DeleteWasmPluginRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_gateways_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_gateways), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gateway.ListGatewaysResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_gateways(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gateway.ListGatewaysRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_gateway_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_gateway), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gateway.Gateway( + name="name_value", + self_link="self_link_value", + description="description_value", + type_=gateway.Gateway.Type.OPEN_MESH, + addresses=["addresses_value"], + ports=[568], + all_ports=True, + scope="scope_value", + server_tls_policy="server_tls_policy_value", + certificate_urls=["certificate_urls_value"], + gateway_security_policy="gateway_security_policy_value", + network="network_value", + subnetwork="subnetwork_value", + ip_version=gateway.Gateway.IpVersion.IPV4, + envoy_headers=common.EnvoyHeaders.NONE, + routing_mode=gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE, + allow_global_access=True, + ) + ) + await client.get_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gateway.GetGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_gateway_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_gateway), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_gateway.CreateGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_gateway_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_gateway), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_gateway.UpdateGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_gateway_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_gateway), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gateway.DeleteGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_grpc_routes_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_grpc_routes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + grpc_route.ListGrpcRoutesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_grpc_routes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = grpc_route.ListGrpcRoutesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_grpc_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_grpc_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + grpc_route.GrpcRoute( + name="name_value", + self_link="self_link_value", + description="description_value", + hostnames=["hostnames_value"], + meshes=["meshes_value"], + gateways=["gateways_value"], + ) + ) + await client.get_grpc_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = grpc_route.GetGrpcRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_grpc_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_grpc_route), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_grpc_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_grpc_route.CreateGrpcRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_grpc_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_grpc_route), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_grpc_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_grpc_route.UpdateGrpcRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_grpc_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_grpc_route), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_grpc_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = grpc_route.DeleteGrpcRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_http_routes_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_http_routes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + http_route.ListHttpRoutesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_http_routes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = http_route.ListHttpRoutesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_http_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_http_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + http_route.HttpRoute( + name="name_value", + self_link="self_link_value", + description="description_value", + hostnames=["hostnames_value"], + meshes=["meshes_value"], + gateways=["gateways_value"], + ) + ) + await client.get_http_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = http_route.GetHttpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_http_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_http_route), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_http_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_http_route.CreateHttpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_http_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_http_route), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_http_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_http_route.UpdateHttpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_http_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_http_route), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_http_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = http_route.DeleteHttpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_tcp_routes_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_tcp_routes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tcp_route.ListTcpRoutesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_tcp_routes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tcp_route.ListTcpRoutesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_tcp_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_tcp_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tcp_route.TcpRoute( + name="name_value", + self_link="self_link_value", + description="description_value", + meshes=["meshes_value"], + gateways=["gateways_value"], + ) + ) + await client.get_tcp_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tcp_route.GetTcpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_tcp_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_tcp_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_tcp_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_tcp_route.CreateTcpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_tcp_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_tcp_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_tcp_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_tcp_route.UpdateTcpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_tcp_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_tcp_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_tcp_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tcp_route.DeleteTcpRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_tls_routes_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_tls_routes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tls_route.ListTlsRoutesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_tls_routes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tls_route.ListTlsRoutesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_tls_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_tls_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tls_route.TlsRoute( + name="name_value", + self_link="self_link_value", + description="description_value", + meshes=["meshes_value"], + gateways=["gateways_value"], + target_proxies=["target_proxies_value"], + ) + ) + await client.get_tls_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tls_route.GetTlsRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_tls_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_tls_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_tls_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_tls_route.CreateTlsRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_tls_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_tls_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_tls_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_tls_route.UpdateTlsRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_tls_route_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_tls_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_tls_route(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = tls_route.DeleteTlsRouteRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_service_bindings_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_service_bindings), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + service_binding.ListServiceBindingsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_service_bindings(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_binding.ListServiceBindingsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_service_binding_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_service_binding), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + service_binding.ServiceBinding( + name="name_value", + description="description_value", + service="service_value", + service_id="service_id_value", + ) + ) + await client.get_service_binding(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_binding.GetServiceBindingRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_service_binding_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_service_binding), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_service_binding(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_service_binding.CreateServiceBindingRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_service_binding_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_service_binding), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_service_binding(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_service_binding.UpdateServiceBindingRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_service_binding_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_service_binding), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_service_binding(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_binding.DeleteServiceBindingRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_meshes_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_meshes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + mesh.ListMeshesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_meshes(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = mesh.ListMeshesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_mesh_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_mesh), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + mesh.Mesh( + name="name_value", + self_link="self_link_value", + description="description_value", + interception_port=1848, + envoy_headers=common.EnvoyHeaders.NONE, + ) + ) + await client.get_mesh(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = mesh.GetMeshRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_mesh_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_mesh), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_mesh(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_mesh.CreateMeshRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_mesh_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_mesh), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_mesh(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_mesh.UpdateMeshRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_mesh_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_mesh), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_mesh(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = mesh.DeleteMeshRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_service_lb_policies_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_service_lb_policies), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + service_lb_policy.ListServiceLbPoliciesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_service_lb_policies(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_lb_policy.ListServiceLbPoliciesRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_service_lb_policy_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_service_lb_policy), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + service_lb_policy.ServiceLbPolicy( + name="name_value", + description="description_value", + load_balancing_algorithm=service_lb_policy.ServiceLbPolicy.LoadBalancingAlgorithm.SPRAY_TO_WORLD, + ) + ) + await client.get_service_lb_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_lb_policy.GetServiceLbPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_service_lb_policy_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_service_lb_policy), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_service_lb_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_service_lb_policy.CreateServiceLbPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_service_lb_policy_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_service_lb_policy), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_service_lb_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_service_lb_policy.UpdateServiceLbPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_service_lb_policy_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_service_lb_policy), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_service_lb_policy(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = service_lb_policy.DeleteServiceLbPolicyRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_gateway_route_view_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_gateway_route_view), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + route_view.GatewayRouteView( + name="name_value", + route_project_number=2157, + route_location="route_location_value", + route_type="route_type_value", + route_id="route_id_value", + ) + ) + await client.get_gateway_route_view(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = route_view.GetGatewayRouteViewRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_mesh_route_view_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_mesh_route_view), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + route_view.MeshRouteView( + name="name_value", + route_project_number=2157, + route_location="route_location_value", + route_type="route_type_value", + route_id="route_id_value", + ) + ) + await client.get_mesh_route_view(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = route_view.GetMeshRouteViewRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_gateway_route_views_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_gateway_route_views), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + route_view.ListGatewayRouteViewsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_gateway_route_views(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = route_view.ListGatewayRouteViewsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_mesh_route_views_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_mesh_route_views), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + route_view.ListMeshRouteViewsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_mesh_route_views(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = route_view.ListMeshRouteViewsRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_agent_gateways_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + agent_gateway.ListAgentGatewaysResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_agent_gateways(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.ListAgentGatewaysRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_agent_gateway_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + agent_gateway.AgentGateway( + name="name_value", + description="description_value", + etag="etag_value", + protocols=[agent_gateway.AgentGateway.Protocol.MCP], + registries=["registries_value"], + ) + ) + await client.get_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.GetAgentGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_agent_gateway_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_agent_gateway.CreateAgentGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_agent_gateway_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_agent_gateway.UpdateAgentGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_agent_gateway_empty_call_grpc_asyncio(): + client = NetworkServicesAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.DeleteAgentGatewayRequest() + assert args[0] == request_msg + + +def test_transport_kind_rest(): + transport = NetworkServicesClient.get_transport_class("rest")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "rest" + + +def test_list_endpoint_policies_rest_bad_request( + request_type=endpoint_policy.ListEndpointPoliciesRequest, +): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_endpoint_policies(request) + + +@pytest.mark.parametrize( + "request_type", + [ + endpoint_policy.ListEndpointPoliciesRequest, + dict, + ], +) +def test_list_endpoint_policies_rest_call_success(request_type): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = endpoint_policy.ListEndpointPoliciesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = endpoint_policy.ListEndpointPoliciesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_endpoint_policies(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListEndpointPoliciesPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_endpoint_policies_rest_interceptors(null_interceptor): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.NetworkServicesRestInterceptor(), + ) + client = NetworkServicesClient(transport=transport) + + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkServicesRestInterceptor, "post_list_endpoint_policies" + ) as post, + mock.patch.object( + transports.NetworkServicesRestInterceptor, + "post_list_endpoint_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkServicesRestInterceptor, "pre_list_endpoint_policies" + ) as pre, + ): + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = endpoint_policy.ListEndpointPoliciesRequest.pb( + endpoint_policy.ListEndpointPoliciesRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = endpoint_policy.ListEndpointPoliciesResponse.to_json( + endpoint_policy.ListEndpointPoliciesResponse() + ) + req.return_value.content = return_value + + request = endpoint_policy.ListEndpointPoliciesRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = endpoint_policy.ListEndpointPoliciesResponse() + post_with_metadata.return_value = ( + endpoint_policy.ListEndpointPoliciesResponse(), + metadata, + ) + + client.list_endpoint_policies( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_get_endpoint_policy_rest_bad_request( + request_type=endpoint_policy.GetEndpointPolicyRequest, +): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_endpoint_policy(request) + + +@pytest.mark.parametrize( + "request_type", + [ + endpoint_policy.GetEndpointPolicyRequest, + dict, + ], +) +def test_get_endpoint_policy_rest_call_success(request_type): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = endpoint_policy.EndpointPolicy( + name="name_value", + type_=endpoint_policy.EndpointPolicy.EndpointPolicyType.SIDECAR_PROXY, + authorization_policy="authorization_policy_value", + description="description_value", + server_tls_policy="server_tls_policy_value", + client_tls_policy="client_tls_policy_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = endpoint_policy.EndpointPolicy.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_endpoint_policy(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, endpoint_policy.EndpointPolicy) + assert response.name == "name_value" + assert ( + response.type_ + == endpoint_policy.EndpointPolicy.EndpointPolicyType.SIDECAR_PROXY + ) + assert response.authorization_policy == "authorization_policy_value" + assert response.description == "description_value" + assert response.server_tls_policy == "server_tls_policy_value" + assert response.client_tls_policy == "client_tls_policy_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_endpoint_policy_rest_interceptors(null_interceptor): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.NetworkServicesRestInterceptor(), + ) + client = NetworkServicesClient(transport=transport) + + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkServicesRestInterceptor, "post_get_endpoint_policy" + ) as post, + mock.patch.object( + transports.NetworkServicesRestInterceptor, + "post_get_endpoint_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkServicesRestInterceptor, "pre_get_endpoint_policy" + ) as pre, + ): + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = endpoint_policy.GetEndpointPolicyRequest.pb( + endpoint_policy.GetEndpointPolicyRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = endpoint_policy.EndpointPolicy.to_json( + endpoint_policy.EndpointPolicy() + ) + req.return_value.content = return_value + + request = endpoint_policy.GetEndpointPolicyRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = endpoint_policy.EndpointPolicy() + post_with_metadata.return_value = endpoint_policy.EndpointPolicy(), metadata + + client.get_endpoint_policy( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_create_endpoint_policy_rest_bad_request( + request_type=gcn_endpoint_policy.CreateEndpointPolicyRequest, +): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.create_endpoint_policy(request) + + +@pytest.mark.parametrize( + "request_type", + [ + gcn_endpoint_policy.CreateEndpointPolicyRequest, + dict, + ], +) +def test_create_endpoint_policy_rest_call_success(request_type): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["endpoint_policy"] = { + "name": "name_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "labels": {}, + "type_": 1, + "authorization_policy": "authorization_policy_value", + "endpoint_matcher": { + "metadata_label_matcher": { + "metadata_label_match_criteria": 1, + "metadata_labels": [ + { + "label_name": "label_name_value", + "label_value": "label_value_value", + } + ], + } + }, + "traffic_port_selector": {"ports": ["ports_value1", "ports_value2"]}, + "description": "description_value", + "server_tls_policy": "server_tls_policy_value", + "client_tls_policy": "client_tls_policy_value", + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = gcn_endpoint_policy.CreateEndpointPolicyRequest.meta.fields[ + "endpoint_policy" + ] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["endpoint_policy"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["endpoint_policy"][field])): + del request_init["endpoint_policy"][field][i][subfield] + else: + del request_init["endpoint_policy"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.create_endpoint_policy(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_endpoint_policy_rest_interceptors(null_interceptor): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.NetworkServicesRestInterceptor(), + ) + client = NetworkServicesClient(transport=transport) + + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetworkServicesRestInterceptor, "post_create_endpoint_policy" + ) as post, + mock.patch.object( + transports.NetworkServicesRestInterceptor, + "post_create_endpoint_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkServicesRestInterceptor, "pre_create_endpoint_policy" + ) as pre, + ): + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = gcn_endpoint_policy.CreateEndpointPolicyRequest.pb( + gcn_endpoint_policy.CreateEndpointPolicyRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = gcn_endpoint_policy.CreateEndpointPolicyRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.create_endpoint_policy( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_update_endpoint_policy_rest_bad_request( + request_type=gcn_endpoint_policy.UpdateEndpointPolicyRequest, +): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "endpoint_policy": { + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + } + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.update_endpoint_policy(request) + + +@pytest.mark.parametrize( + "request_type", + [ + gcn_endpoint_policy.UpdateEndpointPolicyRequest, + dict, + ], +) +def test_update_endpoint_policy_rest_call_success(request_type): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "endpoint_policy": { + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + } + } + request_init["endpoint_policy"] = { + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "labels": {}, + "type_": 1, + "authorization_policy": "authorization_policy_value", + "endpoint_matcher": { + "metadata_label_matcher": { + "metadata_label_match_criteria": 1, + "metadata_labels": [ + { + "label_name": "label_name_value", + "label_value": "label_value_value", + } + ], + } + }, + "traffic_port_selector": {"ports": ["ports_value1", "ports_value2"]}, + "description": "description_value", + "server_tls_policy": "server_tls_policy_value", + "client_tls_policy": "client_tls_policy_value", + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = gcn_endpoint_policy.UpdateEndpointPolicyRequest.meta.fields[ + "endpoint_policy" + ] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_lb_policy.GetServiceLbPolicyRequest() - assert args[0] == request_msg + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_service_lb_policy_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_service_lb_policy), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_service_lb_policy(request=None) + subfields_not_in_runtime = [] - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_service_lb_policy.CreateServiceLbPolicyRequest() - assert args[0] == request_msg + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["endpoint_policy"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["endpoint_policy"][field])): + del request_init["endpoint_policy"][field][i][subfield] + else: + del request_init["endpoint_policy"][field][subfield] + request = request_type(**request_init) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_service_lb_policy_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_service_lb_policy), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_service_lb_policy(request=None) + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.update_endpoint_policy(request) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = gcn_service_lb_policy.UpdateServiceLbPolicyRequest() - assert args[0] == request_msg + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_service_lb_policy_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_endpoint_policy_rest_interceptors(null_interceptor): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.NetworkServicesRestInterceptor(), ) + client = NetworkServicesClient(transport=transport) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_service_lb_policy), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetworkServicesRestInterceptor, "post_update_endpoint_policy" + ) as post, + mock.patch.object( + transports.NetworkServicesRestInterceptor, + "post_update_endpoint_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkServicesRestInterceptor, "pre_update_endpoint_policy" + ) as pre, + ): + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = gcn_endpoint_policy.UpdateEndpointPolicyRequest.pb( + gcn_endpoint_policy.UpdateEndpointPolicyRequest() ) - await client.delete_service_lb_policy(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = service_lb_policy.DeleteServiceLbPolicyRequest() - assert args[0] == request_msg + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_gateway_route_view_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) + request = gcn_endpoint_policy.UpdateEndpointPolicyRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_gateway_route_view), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - route_view.GatewayRouteView( - name="name_value", - route_project_number=2157, - route_location="route_location_value", - route_type="route_type_value", - route_id="route_id_value", - ) + client.update_endpoint_policy( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], ) - await client.get_gateway_route_view(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = route_view.GetGatewayRouteViewRequest() - assert args[0] == request_msg + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_mesh_route_view_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_delete_endpoint_policy_rest_bad_request( + request_type=endpoint_policy.DeleteEndpointPolicyRequest, +): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + } + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_mesh_route_view), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - route_view.MeshRouteView( - name="name_value", - route_project_number=2157, - route_location="route_location_value", - route_type="route_type_value", - route_id="route_id_value", - ) - ) - await client.get_mesh_route_view(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = route_view.GetMeshRouteViewRequest() - assert args[0] == request_msg + # Mock the http request call within the method and fake a BadRequest error. + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.delete_endpoint_policy(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_gateway_route_views_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +@pytest.mark.parametrize( + "request_type", + [ + endpoint_policy.DeleteEndpointPolicyRequest, + dict, + ], +) +def test_delete_endpoint_policy_rest_call_success(request_type): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_gateway_route_views), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - route_view.ListGatewayRouteViewsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_gateway_route_views(request=None) + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + } + request = request_type(**request_init) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = route_view.ListGatewayRouteViewsRequest() - assert args[0] == request_msg + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.delete_endpoint_policy(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_mesh_route_views_empty_call_grpc_asyncio(): - client = NetworkServicesAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_endpoint_policy_rest_interceptors(null_interceptor): + transport = transports.NetworkServicesRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.NetworkServicesRestInterceptor(), ) + client = NetworkServicesClient(transport=transport) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_mesh_route_views), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - route_view.ListMeshRouteViewsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetworkServicesRestInterceptor, "post_delete_endpoint_policy" + ) as post, + mock.patch.object( + transports.NetworkServicesRestInterceptor, + "post_delete_endpoint_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkServicesRestInterceptor, "pre_delete_endpoint_policy" + ) as pre, + ): + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = endpoint_policy.DeleteEndpointPolicyRequest.pb( + endpoint_policy.DeleteEndpointPolicyRequest() ) - await client.list_mesh_route_views(request=None) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = route_view.ListMeshRouteViewsRequest() - assert args[0] == request_msg + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + request = endpoint_policy.DeleteEndpointPolicyRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata -def test_transport_kind_rest(): - transport = NetworkServicesClient.get_transport_class("rest")( - credentials=ga_credentials.AnonymousCredentials() - ) - assert transport.kind == "rest" + client.delete_endpoint_policy( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() -def test_list_endpoint_policies_rest_bad_request( - request_type=endpoint_policy.ListEndpointPoliciesRequest, + +def test_list_wasm_plugin_versions_rest_bad_request( + request_type=extensibility.ListWasmPluginVersionsRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"parent": "projects/sample1/locations/sample2/wasmPlugins/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -38918,29 +43124,29 @@ def test_list_endpoint_policies_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_endpoint_policies(request) + client.list_wasm_plugin_versions(request) @pytest.mark.parametrize( "request_type", [ - endpoint_policy.ListEndpointPoliciesRequest, + extensibility.ListWasmPluginVersionsRequest, dict, ], ) -def test_list_endpoint_policies_rest_call_success(request_type): +def test_list_wasm_plugin_versions_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"parent": "projects/sample1/locations/sample2/wasmPlugins/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = endpoint_policy.ListEndpointPoliciesResponse( + return_value = extensibility.ListWasmPluginVersionsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) @@ -38950,21 +43156,21 @@ def test_list_endpoint_policies_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = endpoint_policy.ListEndpointPoliciesResponse.pb(return_value) + return_value = extensibility.ListWasmPluginVersionsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_endpoint_policies(request) + response = client.list_wasm_plugin_versions(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListEndpointPoliciesPager) + assert isinstance(response, pagers.ListWasmPluginVersionsPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_endpoint_policies_rest_interceptors(null_interceptor): +def test_list_wasm_plugin_versions_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -38977,21 +43183,21 @@ def test_list_endpoint_policies_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_endpoint_policies" + transports.NetworkServicesRestInterceptor, "post_list_wasm_plugin_versions" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_endpoint_policies_with_metadata", + "post_list_wasm_plugin_versions_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_endpoint_policies" + transports.NetworkServicesRestInterceptor, "pre_list_wasm_plugin_versions" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = endpoint_policy.ListEndpointPoliciesRequest.pb( - endpoint_policy.ListEndpointPoliciesRequest() + pb_message = extensibility.ListWasmPluginVersionsRequest.pb( + extensibility.ListWasmPluginVersionsRequest() ) transcode.return_value = { "method": "post", @@ -39003,24 +43209,24 @@ def test_list_endpoint_policies_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = endpoint_policy.ListEndpointPoliciesResponse.to_json( - endpoint_policy.ListEndpointPoliciesResponse() + return_value = extensibility.ListWasmPluginVersionsResponse.to_json( + extensibility.ListWasmPluginVersionsResponse() ) req.return_value.content = return_value - request = endpoint_policy.ListEndpointPoliciesRequest() + request = extensibility.ListWasmPluginVersionsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = endpoint_policy.ListEndpointPoliciesResponse() + post.return_value = extensibility.ListWasmPluginVersionsResponse() post_with_metadata.return_value = ( - endpoint_policy.ListEndpointPoliciesResponse(), + extensibility.ListWasmPluginVersionsResponse(), metadata, ) - client.list_endpoint_policies( + client.list_wasm_plugin_versions( request, metadata=[ ("key", "val"), @@ -39033,15 +43239,15 @@ def test_list_endpoint_policies_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_endpoint_policy_rest_bad_request( - request_type=endpoint_policy.GetEndpointPolicyRequest, +def test_get_wasm_plugin_version_rest_bad_request( + request_type=extensibility.GetWasmPluginVersionRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" } request = request_type(**request_init) @@ -39058,37 +43264,37 @@ def test_get_endpoint_policy_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_endpoint_policy(request) + client.get_wasm_plugin_version(request) @pytest.mark.parametrize( "request_type", [ - endpoint_policy.GetEndpointPolicyRequest, + extensibility.GetWasmPluginVersionRequest, dict, ], ) -def test_get_endpoint_policy_rest_call_success(request_type): +def test_get_wasm_plugin_version_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = endpoint_policy.EndpointPolicy( + return_value = extensibility.WasmPluginVersion( name="name_value", - type_=endpoint_policy.EndpointPolicy.EndpointPolicyType.SIDECAR_PROXY, - authorization_policy="authorization_policy_value", description="description_value", - server_tls_policy="server_tls_policy_value", - client_tls_policy="client_tls_policy_value", + image_uri="image_uri_value", + image_digest="image_digest_value", + plugin_config_digest="plugin_config_digest_value", + plugin_config_data=b"plugin_config_data_blob", ) # Wrap the value into a proper Response obj @@ -39096,28 +43302,24 @@ def test_get_endpoint_policy_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = endpoint_policy.EndpointPolicy.pb(return_value) + return_value = extensibility.WasmPluginVersion.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_endpoint_policy(request) + response = client.get_wasm_plugin_version(request) # Establish that the response is the type that we expect. - assert isinstance(response, endpoint_policy.EndpointPolicy) + assert isinstance(response, extensibility.WasmPluginVersion) assert response.name == "name_value" - assert ( - response.type_ - == endpoint_policy.EndpointPolicy.EndpointPolicyType.SIDECAR_PROXY - ) - assert response.authorization_policy == "authorization_policy_value" assert response.description == "description_value" - assert response.server_tls_policy == "server_tls_policy_value" - assert response.client_tls_policy == "client_tls_policy_value" + assert response.image_uri == "image_uri_value" + assert response.image_digest == "image_digest_value" + assert response.plugin_config_digest == "plugin_config_digest_value" @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_endpoint_policy_rest_interceptors(null_interceptor): +def test_get_wasm_plugin_version_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -39130,21 +43332,21 @@ def test_get_endpoint_policy_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_endpoint_policy" + transports.NetworkServicesRestInterceptor, "post_get_wasm_plugin_version" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_get_endpoint_policy_with_metadata", + "post_get_wasm_plugin_version_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_endpoint_policy" + transports.NetworkServicesRestInterceptor, "pre_get_wasm_plugin_version" ) as pre, ): pre.assert_not_called() post.assert_not_called() - post_with_metadata.assert_not_called() - pb_message = endpoint_policy.GetEndpointPolicyRequest.pb( - endpoint_policy.GetEndpointPolicyRequest() + post_with_metadata.assert_not_called() + pb_message = extensibility.GetWasmPluginVersionRequest.pb( + extensibility.GetWasmPluginVersionRequest() ) transcode.return_value = { "method": "post", @@ -39156,21 +43358,21 @@ def test_get_endpoint_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = endpoint_policy.EndpointPolicy.to_json( - endpoint_policy.EndpointPolicy() + return_value = extensibility.WasmPluginVersion.to_json( + extensibility.WasmPluginVersion() ) req.return_value.content = return_value - request = endpoint_policy.GetEndpointPolicyRequest() + request = extensibility.GetWasmPluginVersionRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = endpoint_policy.EndpointPolicy() - post_with_metadata.return_value = endpoint_policy.EndpointPolicy(), metadata + post.return_value = extensibility.WasmPluginVersion() + post_with_metadata.return_value = extensibility.WasmPluginVersion(), metadata - client.get_endpoint_policy( + client.get_wasm_plugin_version( request, metadata=[ ("key", "val"), @@ -39183,14 +43385,14 @@ def test_get_endpoint_policy_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_endpoint_policy_rest_bad_request( - request_type=gcn_endpoint_policy.CreateEndpointPolicyRequest, +def test_create_wasm_plugin_version_rest_bad_request( + request_type=extensibility.CreateWasmPluginVersionRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"parent": "projects/sample1/locations/sample2/wasmPlugins/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -39206,53 +43408,42 @@ def test_create_endpoint_policy_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_endpoint_policy(request) + client.create_wasm_plugin_version(request) @pytest.mark.parametrize( "request_type", [ - gcn_endpoint_policy.CreateEndpointPolicyRequest, + extensibility.CreateWasmPluginVersionRequest, dict, ], ) -def test_create_endpoint_policy_rest_call_success(request_type): +def test_create_wasm_plugin_version_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["endpoint_policy"] = { + request_init = {"parent": "projects/sample1/locations/sample2/wasmPlugins/sample3"} + request_init["wasm_plugin_version"] = { + "plugin_config_data": b"plugin_config_data_blob", + "plugin_config_uri": "plugin_config_uri_value", "name": "name_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "labels": {}, - "type_": 1, - "authorization_policy": "authorization_policy_value", - "endpoint_matcher": { - "metadata_label_matcher": { - "metadata_label_match_criteria": 1, - "metadata_labels": [ - { - "label_name": "label_name_value", - "label_value": "label_value_value", - } - ], - } - }, - "traffic_port_selector": {"ports": ["ports_value1", "ports_value2"]}, "description": "description_value", - "server_tls_policy": "server_tls_policy_value", - "client_tls_policy": "client_tls_policy_value", + "labels": {}, + "image_uri": "image_uri_value", + "image_digest": "image_digest_value", + "plugin_config_digest": "plugin_config_digest_value", } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_endpoint_policy.CreateEndpointPolicyRequest.meta.fields[ - "endpoint_policy" + test_field = extensibility.CreateWasmPluginVersionRequest.meta.fields[ + "wasm_plugin_version" ] def get_message_fields(field): @@ -39281,7 +43472,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["endpoint_policy"].items(): # pragma: NO COVER + for field, value in request_init["wasm_plugin_version"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -39311,10 +43502,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["endpoint_policy"][field])): - del request_init["endpoint_policy"][field][i][subfield] + for i in range(0, len(request_init["wasm_plugin_version"][field])): + del request_init["wasm_plugin_version"][field][i][subfield] else: - del request_init["endpoint_policy"][field][subfield] + del request_init["wasm_plugin_version"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -39329,14 +43520,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_endpoint_policy(request) + response = client.create_wasm_plugin_version(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_endpoint_policy_rest_interceptors(null_interceptor): +def test_create_wasm_plugin_version_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -39350,21 +43541,21 @@ def test_create_endpoint_policy_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_endpoint_policy" + transports.NetworkServicesRestInterceptor, "post_create_wasm_plugin_version" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_create_endpoint_policy_with_metadata", + "post_create_wasm_plugin_version_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_endpoint_policy" + transports.NetworkServicesRestInterceptor, "pre_create_wasm_plugin_version" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_endpoint_policy.CreateEndpointPolicyRequest.pb( - gcn_endpoint_policy.CreateEndpointPolicyRequest() + pb_message = extensibility.CreateWasmPluginVersionRequest.pb( + extensibility.CreateWasmPluginVersionRequest() ) transcode.return_value = { "method": "post", @@ -39379,7 +43570,7 @@ def test_create_endpoint_policy_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_endpoint_policy.CreateEndpointPolicyRequest() + request = extensibility.CreateWasmPluginVersionRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -39388,7 +43579,7 @@ def test_create_endpoint_policy_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_endpoint_policy( + client.create_wasm_plugin_version( request, metadata=[ ("key", "val"), @@ -39401,17 +43592,15 @@ def test_create_endpoint_policy_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_endpoint_policy_rest_bad_request( - request_type=gcn_endpoint_policy.UpdateEndpointPolicyRequest, +def test_delete_wasm_plugin_version_rest_bad_request( + request_type=extensibility.DeleteWasmPluginVersionRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "endpoint_policy": { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" - } + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" } request = request_type(**request_init) @@ -39428,119 +43617,25 @@ def test_update_endpoint_policy_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_endpoint_policy(request) + client.delete_wasm_plugin_version(request) @pytest.mark.parametrize( "request_type", [ - gcn_endpoint_policy.UpdateEndpointPolicyRequest, + extensibility.DeleteWasmPluginVersionRequest, dict, ], ) -def test_update_endpoint_policy_rest_call_success(request_type): +def test_delete_wasm_plugin_version_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "endpoint_policy": { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" - } - } - request_init["endpoint_policy"] = { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "labels": {}, - "type_": 1, - "authorization_policy": "authorization_policy_value", - "endpoint_matcher": { - "metadata_label_matcher": { - "metadata_label_match_criteria": 1, - "metadata_labels": [ - { - "label_name": "label_name_value", - "label_value": "label_value_value", - } - ], - } - }, - "traffic_port_selector": {"ports": ["ports_value1", "ports_value2"]}, - "description": "description_value", - "server_tls_policy": "server_tls_policy_value", - "client_tls_policy": "client_tls_policy_value", + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" } - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = gcn_endpoint_policy.UpdateEndpointPolicyRequest.meta.fields[ - "endpoint_policy" - ] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields - - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] - - subfields_not_in_runtime = [] - - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["endpoint_policy"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value - - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) - - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["endpoint_policy"][field])): - del request_init["endpoint_policy"][field][i][subfield] - else: - del request_init["endpoint_policy"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -39555,14 +43650,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_endpoint_policy(request) + response = client.delete_wasm_plugin_version(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_endpoint_policy_rest_interceptors(null_interceptor): +def test_delete_wasm_plugin_version_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -39576,21 +43671,21 @@ def test_update_endpoint_policy_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_endpoint_policy" + transports.NetworkServicesRestInterceptor, "post_delete_wasm_plugin_version" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_update_endpoint_policy_with_metadata", + "post_delete_wasm_plugin_version_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_endpoint_policy" + transports.NetworkServicesRestInterceptor, "pre_delete_wasm_plugin_version" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_endpoint_policy.UpdateEndpointPolicyRequest.pb( - gcn_endpoint_policy.UpdateEndpointPolicyRequest() + pb_message = extensibility.DeleteWasmPluginVersionRequest.pb( + extensibility.DeleteWasmPluginVersionRequest() ) transcode.return_value = { "method": "post", @@ -39605,7 +43700,7 @@ def test_update_endpoint_policy_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_endpoint_policy.UpdateEndpointPolicyRequest() + request = extensibility.DeleteWasmPluginVersionRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -39614,7 +43709,7 @@ def test_update_endpoint_policy_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.update_endpoint_policy( + client.delete_wasm_plugin_version( request, metadata=[ ("key", "val"), @@ -39627,16 +43722,14 @@ def test_update_endpoint_policy_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_endpoint_policy_rest_bad_request( - request_type=endpoint_policy.DeleteEndpointPolicyRequest, +def test_list_wasm_plugins_rest_bad_request( + request_type=extensibility.ListWasmPluginsRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" - } + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -39652,47 +43745,53 @@ def test_delete_endpoint_policy_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_endpoint_policy(request) + client.list_wasm_plugins(request) @pytest.mark.parametrize( "request_type", [ - endpoint_policy.DeleteEndpointPolicyRequest, + extensibility.ListWasmPluginsRequest, dict, ], ) -def test_delete_endpoint_policy_rest_call_success(request_type): +def test_list_wasm_plugins_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/endpointPolicies/sample3" - } + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = extensibility.ListWasmPluginsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) # Wrap the value into a proper Response obj response_value = mock.Mock() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = extensibility.ListWasmPluginsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_endpoint_policy(request) + response = client.list_wasm_plugins(request) # Establish that the response is the type that we expect. - json_return_value = json_format.MessageToJson(return_value) + assert isinstance(response, pagers.ListWasmPluginsPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_endpoint_policy_rest_interceptors(null_interceptor): +def test_list_wasm_plugins_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -39704,23 +43803,22 @@ def test_delete_endpoint_policy_rest_interceptors(null_interceptor): with ( mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, - mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_endpoint_policy" + transports.NetworkServicesRestInterceptor, "post_list_wasm_plugins" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_delete_endpoint_policy_with_metadata", + "post_list_wasm_plugins_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_endpoint_policy" + transports.NetworkServicesRestInterceptor, "pre_list_wasm_plugins" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = endpoint_policy.DeleteEndpointPolicyRequest.pb( - endpoint_policy.DeleteEndpointPolicyRequest() + pb_message = extensibility.ListWasmPluginsRequest.pb( + extensibility.ListWasmPluginsRequest() ) transcode.return_value = { "method": "post", @@ -39732,19 +43830,24 @@ def test_delete_endpoint_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = json_format.MessageToJson(operations_pb2.Operation()) + return_value = extensibility.ListWasmPluginsResponse.to_json( + extensibility.ListWasmPluginsResponse() + ) req.return_value.content = return_value - request = endpoint_policy.DeleteEndpointPolicyRequest() + request = extensibility.ListWasmPluginsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - post_with_metadata.return_value = operations_pb2.Operation(), metadata + post.return_value = extensibility.ListWasmPluginsResponse() + post_with_metadata.return_value = ( + extensibility.ListWasmPluginsResponse(), + metadata, + ) - client.delete_endpoint_policy( + client.list_wasm_plugins( request, metadata=[ ("key", "val"), @@ -39757,14 +43860,14 @@ def test_delete_endpoint_policy_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_wasm_plugin_versions_rest_bad_request( - request_type=extensibility.ListWasmPluginVersionsRequest, +def test_get_wasm_plugin_rest_bad_request( + request_type=extensibility.GetWasmPluginRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/wasmPlugins/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/wasmPlugins/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -39780,31 +43883,32 @@ def test_list_wasm_plugin_versions_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_wasm_plugin_versions(request) + client.get_wasm_plugin(request) @pytest.mark.parametrize( "request_type", [ - extensibility.ListWasmPluginVersionsRequest, + extensibility.GetWasmPluginRequest, dict, ], ) -def test_list_wasm_plugin_versions_rest_call_success(request_type): +def test_get_wasm_plugin_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/wasmPlugins/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/wasmPlugins/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = extensibility.ListWasmPluginVersionsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + return_value = extensibility.WasmPlugin( + name="name_value", + description="description_value", + main_version_id="main_version_id_value", ) # Wrap the value into a proper Response obj @@ -39812,21 +43916,22 @@ def test_list_wasm_plugin_versions_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = extensibility.ListWasmPluginVersionsResponse.pb(return_value) + return_value = extensibility.WasmPlugin.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_wasm_plugin_versions(request) + response = client.get_wasm_plugin(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListWasmPluginVersionsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, extensibility.WasmPlugin) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.main_version_id == "main_version_id_value" @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_wasm_plugin_versions_rest_interceptors(null_interceptor): +def test_get_wasm_plugin_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -39839,21 +43944,21 @@ def test_list_wasm_plugin_versions_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_wasm_plugin_versions" + transports.NetworkServicesRestInterceptor, "post_get_wasm_plugin" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_wasm_plugin_versions_with_metadata", + "post_get_wasm_plugin_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_wasm_plugin_versions" + transports.NetworkServicesRestInterceptor, "pre_get_wasm_plugin" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = extensibility.ListWasmPluginVersionsRequest.pb( - extensibility.ListWasmPluginVersionsRequest() + pb_message = extensibility.GetWasmPluginRequest.pb( + extensibility.GetWasmPluginRequest() ) transcode.return_value = { "method": "post", @@ -39865,24 +43970,19 @@ def test_list_wasm_plugin_versions_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = extensibility.ListWasmPluginVersionsResponse.to_json( - extensibility.ListWasmPluginVersionsResponse() - ) + return_value = extensibility.WasmPlugin.to_json(extensibility.WasmPlugin()) req.return_value.content = return_value - request = extensibility.ListWasmPluginVersionsRequest() + request = extensibility.GetWasmPluginRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = extensibility.ListWasmPluginVersionsResponse() - post_with_metadata.return_value = ( - extensibility.ListWasmPluginVersionsResponse(), - metadata, - ) + post.return_value = extensibility.WasmPlugin() + post_with_metadata.return_value = extensibility.WasmPlugin(), metadata - client.list_wasm_plugin_versions( + client.get_wasm_plugin( request, metadata=[ ("key", "val"), @@ -39895,16 +43995,14 @@ def test_list_wasm_plugin_versions_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_wasm_plugin_version_rest_bad_request( - request_type=extensibility.GetWasmPluginVersionRequest, +def test_create_wasm_plugin_rest_bad_request( + request_type=extensibility.CreateWasmPluginRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" - } + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -39920,62 +44018,123 @@ def test_get_wasm_plugin_version_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_wasm_plugin_version(request) + client.create_wasm_plugin(request) @pytest.mark.parametrize( "request_type", [ - extensibility.GetWasmPluginVersionRequest, + extensibility.CreateWasmPluginRequest, dict, ], ) -def test_get_wasm_plugin_version_rest_call_success(request_type): +def test_create_wasm_plugin_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["wasm_plugin"] = { + "name": "name_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "description": "description_value", + "labels": {}, + "main_version_id": "main_version_id_value", + "log_config": {"enable": True, "sample_rate": 0.1165, "min_log_level": 1}, + "versions": {}, + "used_by": [{"name": "name_value"}], } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = extensibility.CreateWasmPluginRequest.meta.fields["wasm_plugin"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["wasm_plugin"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["wasm_plugin"][field])): + del request_init["wasm_plugin"][field][i][subfield] + else: + del request_init["wasm_plugin"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = extensibility.WasmPluginVersion( - name="name_value", - description="description_value", - image_uri="image_uri_value", - image_digest="image_digest_value", - plugin_config_digest="plugin_config_digest_value", - plugin_config_data=b"plugin_config_data_blob", - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = mock.Mock() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = extensibility.WasmPluginVersion.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_wasm_plugin_version(request) + response = client.create_wasm_plugin(request) # Establish that the response is the type that we expect. - assert isinstance(response, extensibility.WasmPluginVersion) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.image_uri == "image_uri_value" - assert response.image_digest == "image_digest_value" - assert response.plugin_config_digest == "plugin_config_digest_value" + json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_wasm_plugin_version_rest_interceptors(null_interceptor): +def test_create_wasm_plugin_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -39987,22 +44146,23 @@ def test_get_wasm_plugin_version_rest_interceptors(null_interceptor): with ( mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_wasm_plugin_version" + transports.NetworkServicesRestInterceptor, "post_create_wasm_plugin" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_get_wasm_plugin_version_with_metadata", + "post_create_wasm_plugin_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_wasm_plugin_version" + transports.NetworkServicesRestInterceptor, "pre_create_wasm_plugin" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = extensibility.GetWasmPluginVersionRequest.pb( - extensibility.GetWasmPluginVersionRequest() + pb_message = extensibility.CreateWasmPluginRequest.pb( + extensibility.CreateWasmPluginRequest() ) transcode.return_value = { "method": "post", @@ -40014,21 +44174,19 @@ def test_get_wasm_plugin_version_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = extensibility.WasmPluginVersion.to_json( - extensibility.WasmPluginVersion() - ) + return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = extensibility.GetWasmPluginVersionRequest() + request = extensibility.CreateWasmPluginRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = extensibility.WasmPluginVersion() - post_with_metadata.return_value = extensibility.WasmPluginVersion(), metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.get_wasm_plugin_version( + client.create_wasm_plugin( request, metadata=[ ("key", "val"), @@ -40041,14 +44199,18 @@ def test_get_wasm_plugin_version_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_wasm_plugin_version_rest_bad_request( - request_type=extensibility.CreateWasmPluginVersionRequest, +def test_update_wasm_plugin_rest_bad_request( + request_type=extensibility.UpdateWasmPluginRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/wasmPlugins/sample3"} + request_init = { + "wasm_plugin": { + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" + } + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -40064,43 +44226,44 @@ def test_create_wasm_plugin_version_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_wasm_plugin_version(request) + client.update_wasm_plugin(request) @pytest.mark.parametrize( "request_type", [ - extensibility.CreateWasmPluginVersionRequest, + extensibility.UpdateWasmPluginRequest, dict, ], ) -def test_create_wasm_plugin_version_rest_call_success(request_type): +def test_update_wasm_plugin_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/wasmPlugins/sample3"} - request_init["wasm_plugin_version"] = { - "plugin_config_data": b"plugin_config_data_blob", - "plugin_config_uri": "plugin_config_uri_value", - "name": "name_value", + request_init = { + "wasm_plugin": { + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" + } + } + request_init["wasm_plugin"] = { + "name": "projects/sample1/locations/sample2/wasmPlugins/sample3", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, "description": "description_value", "labels": {}, - "image_uri": "image_uri_value", - "image_digest": "image_digest_value", - "plugin_config_digest": "plugin_config_digest_value", + "main_version_id": "main_version_id_value", + "log_config": {"enable": True, "sample_rate": 0.1165, "min_log_level": 1}, + "versions": {}, + "used_by": [{"name": "name_value"}], } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = extensibility.CreateWasmPluginVersionRequest.meta.fields[ - "wasm_plugin_version" - ] + test_field = extensibility.UpdateWasmPluginRequest.meta.fields["wasm_plugin"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -40128,7 +44291,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["wasm_plugin_version"].items(): # pragma: NO COVER + for field, value in request_init["wasm_plugin"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -40158,10 +44321,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["wasm_plugin_version"][field])): - del request_init["wasm_plugin_version"][field][i][subfield] + for i in range(0, len(request_init["wasm_plugin"][field])): + del request_init["wasm_plugin"][field][i][subfield] else: - del request_init["wasm_plugin_version"][field][subfield] + del request_init["wasm_plugin"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -40176,14 +44339,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_wasm_plugin_version(request) + response = client.update_wasm_plugin(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_wasm_plugin_version_rest_interceptors(null_interceptor): +def test_update_wasm_plugin_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -40197,21 +44360,21 @@ def test_create_wasm_plugin_version_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_wasm_plugin_version" + transports.NetworkServicesRestInterceptor, "post_update_wasm_plugin" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_create_wasm_plugin_version_with_metadata", + "post_update_wasm_plugin_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_wasm_plugin_version" + transports.NetworkServicesRestInterceptor, "pre_update_wasm_plugin" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = extensibility.CreateWasmPluginVersionRequest.pb( - extensibility.CreateWasmPluginVersionRequest() + pb_message = extensibility.UpdateWasmPluginRequest.pb( + extensibility.UpdateWasmPluginRequest() ) transcode.return_value = { "method": "post", @@ -40226,7 +44389,7 @@ def test_create_wasm_plugin_version_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = extensibility.CreateWasmPluginVersionRequest() + request = extensibility.UpdateWasmPluginRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -40235,7 +44398,7 @@ def test_create_wasm_plugin_version_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_wasm_plugin_version( + client.update_wasm_plugin( request, metadata=[ ("key", "val"), @@ -40248,16 +44411,14 @@ def test_create_wasm_plugin_version_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_wasm_plugin_version_rest_bad_request( - request_type=extensibility.DeleteWasmPluginVersionRequest, +def test_delete_wasm_plugin_rest_bad_request( + request_type=extensibility.DeleteWasmPluginRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" - } + request_init = {"name": "projects/sample1/locations/sample2/wasmPlugins/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -40273,25 +44434,23 @@ def test_delete_wasm_plugin_version_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_wasm_plugin_version(request) + client.delete_wasm_plugin(request) @pytest.mark.parametrize( "request_type", [ - extensibility.DeleteWasmPluginVersionRequest, + extensibility.DeleteWasmPluginRequest, dict, ], ) -def test_delete_wasm_plugin_version_rest_call_success(request_type): +def test_delete_wasm_plugin_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3/versions/sample4" - } + request_init = {"name": "projects/sample1/locations/sample2/wasmPlugins/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -40306,14 +44465,14 @@ def test_delete_wasm_plugin_version_rest_call_success(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_wasm_plugin_version(request) + response = client.delete_wasm_plugin(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_wasm_plugin_version_rest_interceptors(null_interceptor): +def test_delete_wasm_plugin_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -40327,21 +44486,21 @@ def test_delete_wasm_plugin_version_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_wasm_plugin_version" + transports.NetworkServicesRestInterceptor, "post_delete_wasm_plugin" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_delete_wasm_plugin_version_with_metadata", + "post_delete_wasm_plugin_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_wasm_plugin_version" + transports.NetworkServicesRestInterceptor, "pre_delete_wasm_plugin" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = extensibility.DeleteWasmPluginVersionRequest.pb( - extensibility.DeleteWasmPluginVersionRequest() + pb_message = extensibility.DeleteWasmPluginRequest.pb( + extensibility.DeleteWasmPluginRequest() ) transcode.return_value = { "method": "post", @@ -40356,7 +44515,7 @@ def test_delete_wasm_plugin_version_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = extensibility.DeleteWasmPluginVersionRequest() + request = extensibility.DeleteWasmPluginRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -40365,7 +44524,7 @@ def test_delete_wasm_plugin_version_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.delete_wasm_plugin_version( + client.delete_wasm_plugin( request, metadata=[ ("key", "val"), @@ -40378,9 +44537,7 @@ def test_delete_wasm_plugin_version_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_wasm_plugins_rest_bad_request( - request_type=extensibility.ListWasmPluginsRequest, -): +def test_list_gateways_rest_bad_request(request_type=gateway.ListGatewaysRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -40401,17 +44558,17 @@ def test_list_wasm_plugins_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_wasm_plugins(request) + client.list_gateways(request) @pytest.mark.parametrize( "request_type", [ - extensibility.ListWasmPluginsRequest, + gateway.ListGatewaysRequest, dict, ], ) -def test_list_wasm_plugins_rest_call_success(request_type): +def test_list_gateways_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -40423,7 +44580,7 @@ def test_list_wasm_plugins_rest_call_success(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = extensibility.ListWasmPluginsResponse( + return_value = gateway.ListGatewaysResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) @@ -40433,21 +44590,21 @@ def test_list_wasm_plugins_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = extensibility.ListWasmPluginsResponse.pb(return_value) + return_value = gateway.ListGatewaysResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_wasm_plugins(request) + response = client.list_gateways(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListWasmPluginsPager) + assert isinstance(response, pagers.ListGatewaysPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_wasm_plugins_rest_interceptors(null_interceptor): +def test_list_gateways_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -40460,22 +44617,20 @@ def test_list_wasm_plugins_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_wasm_plugins" + transports.NetworkServicesRestInterceptor, "post_list_gateways" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_wasm_plugins_with_metadata", + "post_list_gateways_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_wasm_plugins" + transports.NetworkServicesRestInterceptor, "pre_list_gateways" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = extensibility.ListWasmPluginsRequest.pb( - extensibility.ListWasmPluginsRequest() - ) + pb_message = gateway.ListGatewaysRequest.pb(gateway.ListGatewaysRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -40486,24 +44641,21 @@ def test_list_wasm_plugins_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = extensibility.ListWasmPluginsResponse.to_json( - extensibility.ListWasmPluginsResponse() + return_value = gateway.ListGatewaysResponse.to_json( + gateway.ListGatewaysResponse() ) req.return_value.content = return_value - request = extensibility.ListWasmPluginsRequest() + request = gateway.ListGatewaysRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = extensibility.ListWasmPluginsResponse() - post_with_metadata.return_value = ( - extensibility.ListWasmPluginsResponse(), - metadata, - ) + post.return_value = gateway.ListGatewaysResponse() + post_with_metadata.return_value = gateway.ListGatewaysResponse(), metadata - client.list_wasm_plugins( + client.list_gateways( request, metadata=[ ("key", "val"), @@ -40516,14 +44668,12 @@ def test_list_wasm_plugins_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_wasm_plugin_rest_bad_request( - request_type=extensibility.GetWasmPluginRequest, -): +def test_get_gateway_rest_bad_request(request_type=gateway.GetGatewayRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/wasmPlugins/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/gateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -40539,32 +44689,46 @@ def test_get_wasm_plugin_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_wasm_plugin(request) + client.get_gateway(request) @pytest.mark.parametrize( "request_type", [ - extensibility.GetWasmPluginRequest, + gateway.GetGatewayRequest, dict, ], ) -def test_get_wasm_plugin_rest_call_success(request_type): +def test_get_gateway_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/wasmPlugins/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/gateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = extensibility.WasmPlugin( + return_value = gateway.Gateway( name="name_value", + self_link="self_link_value", description="description_value", - main_version_id="main_version_id_value", + type_=gateway.Gateway.Type.OPEN_MESH, + addresses=["addresses_value"], + ports=[568], + all_ports=True, + scope="scope_value", + server_tls_policy="server_tls_policy_value", + certificate_urls=["certificate_urls_value"], + gateway_security_policy="gateway_security_policy_value", + network="network_value", + subnetwork="subnetwork_value", + ip_version=gateway.Gateway.IpVersion.IPV4, + envoy_headers=common.EnvoyHeaders.NONE, + routing_mode=gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE, + allow_global_access=True, ) # Wrap the value into a proper Response obj @@ -40572,22 +44736,36 @@ def test_get_wasm_plugin_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = extensibility.WasmPlugin.pb(return_value) + return_value = gateway.Gateway.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_wasm_plugin(request) + response = client.get_gateway(request) # Establish that the response is the type that we expect. - assert isinstance(response, extensibility.WasmPlugin) + assert isinstance(response, gateway.Gateway) assert response.name == "name_value" + assert response.self_link == "self_link_value" assert response.description == "description_value" - assert response.main_version_id == "main_version_id_value" + assert response.type_ == gateway.Gateway.Type.OPEN_MESH + assert response.addresses == ["addresses_value"] + assert response.ports == [568] + assert response.all_ports is True + assert response.scope == "scope_value" + assert response.server_tls_policy == "server_tls_policy_value" + assert response.certificate_urls == ["certificate_urls_value"] + assert response.gateway_security_policy == "gateway_security_policy_value" + assert response.network == "network_value" + assert response.subnetwork == "subnetwork_value" + assert response.ip_version == gateway.Gateway.IpVersion.IPV4 + assert response.envoy_headers == common.EnvoyHeaders.NONE + assert response.routing_mode == gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE + assert response.allow_global_access is True @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_wasm_plugin_rest_interceptors(null_interceptor): +def test_get_gateway_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -40600,22 +44778,19 @@ def test_get_wasm_plugin_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_wasm_plugin" + transports.NetworkServicesRestInterceptor, "post_get_gateway" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, - "post_get_wasm_plugin_with_metadata", + transports.NetworkServicesRestInterceptor, "post_get_gateway_with_metadata" ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_wasm_plugin" + transports.NetworkServicesRestInterceptor, "pre_get_gateway" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = extensibility.GetWasmPluginRequest.pb( - extensibility.GetWasmPluginRequest() - ) + pb_message = gateway.GetGatewayRequest.pb(gateway.GetGatewayRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -40626,19 +44801,19 @@ def test_get_wasm_plugin_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = extensibility.WasmPlugin.to_json(extensibility.WasmPlugin()) + return_value = gateway.Gateway.to_json(gateway.Gateway()) req.return_value.content = return_value - request = extensibility.GetWasmPluginRequest() + request = gateway.GetGatewayRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = extensibility.WasmPlugin() - post_with_metadata.return_value = extensibility.WasmPlugin(), metadata + post.return_value = gateway.Gateway() + post_with_metadata.return_value = gateway.Gateway(), metadata - client.get_wasm_plugin( + client.get_gateway( request, metadata=[ ("key", "val"), @@ -40651,9 +44826,7 @@ def test_get_wasm_plugin_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_wasm_plugin_rest_bad_request( - request_type=extensibility.CreateWasmPluginRequest, -): +def test_create_gateway_rest_bad_request(request_type=gcn_gateway.CreateGatewayRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -40674,40 +44847,51 @@ def test_create_wasm_plugin_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_wasm_plugin(request) + client.create_gateway(request) @pytest.mark.parametrize( "request_type", [ - extensibility.CreateWasmPluginRequest, + gcn_gateway.CreateGatewayRequest, dict, ], ) -def test_create_wasm_plugin_rest_call_success(request_type): +def test_create_gateway_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["wasm_plugin"] = { + request_init["gateway"] = { "name": "name_value", + "self_link": "self_link_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "description": "description_value", "labels": {}, - "main_version_id": "main_version_id_value", - "log_config": {"enable": True, "sample_rate": 0.1165, "min_log_level": 1}, - "versions": {}, - "used_by": [{"name": "name_value"}], + "description": "description_value", + "type_": 1, + "addresses": ["addresses_value1", "addresses_value2"], + "ports": [569, 570], + "all_ports": True, + "scope": "scope_value", + "server_tls_policy": "server_tls_policy_value", + "certificate_urls": ["certificate_urls_value1", "certificate_urls_value2"], + "gateway_security_policy": "gateway_security_policy_value", + "network": "network_value", + "subnetwork": "subnetwork_value", + "ip_version": 1, + "envoy_headers": 1, + "routing_mode": 1, + "allow_global_access": True, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = extensibility.CreateWasmPluginRequest.meta.fields["wasm_plugin"] + test_field = gcn_gateway.CreateGatewayRequest.meta.fields["gateway"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -40735,7 +44919,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["wasm_plugin"].items(): # pragma: NO COVER + for field, value in request_init["gateway"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -40765,10 +44949,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["wasm_plugin"][field])): - del request_init["wasm_plugin"][field][i][subfield] + for i in range(0, len(request_init["gateway"][field])): + del request_init["gateway"][field][i][subfield] else: - del request_init["wasm_plugin"][field][subfield] + del request_init["gateway"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -40783,14 +44967,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_wasm_plugin(request) + response = client.create_gateway(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_wasm_plugin_rest_interceptors(null_interceptor): +def test_create_gateway_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -40804,21 +44988,21 @@ def test_create_wasm_plugin_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_wasm_plugin" + transports.NetworkServicesRestInterceptor, "post_create_gateway" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_create_wasm_plugin_with_metadata", + "post_create_gateway_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_wasm_plugin" + transports.NetworkServicesRestInterceptor, "pre_create_gateway" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = extensibility.CreateWasmPluginRequest.pb( - extensibility.CreateWasmPluginRequest() + pb_message = gcn_gateway.CreateGatewayRequest.pb( + gcn_gateway.CreateGatewayRequest() ) transcode.return_value = { "method": "post", @@ -40833,7 +45017,7 @@ def test_create_wasm_plugin_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = extensibility.CreateWasmPluginRequest() + request = gcn_gateway.CreateGatewayRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -40842,7 +45026,7 @@ def test_create_wasm_plugin_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_wasm_plugin( + client.create_gateway( request, metadata=[ ("key", "val"), @@ -40855,17 +45039,13 @@ def test_create_wasm_plugin_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_wasm_plugin_rest_bad_request( - request_type=extensibility.UpdateWasmPluginRequest, -): +def test_update_gateway_rest_bad_request(request_type=gcn_gateway.UpdateGatewayRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "wasm_plugin": { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" - } + "gateway": {"name": "projects/sample1/locations/sample2/gateways/sample3"} } request = request_type(**request_init) @@ -40882,44 +45062,53 @@ def test_update_wasm_plugin_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_wasm_plugin(request) + client.update_gateway(request) @pytest.mark.parametrize( "request_type", [ - extensibility.UpdateWasmPluginRequest, + gcn_gateway.UpdateGatewayRequest, dict, ], ) -def test_update_wasm_plugin_rest_call_success(request_type): +def test_update_gateway_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "wasm_plugin": { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3" - } + "gateway": {"name": "projects/sample1/locations/sample2/gateways/sample3"} } - request_init["wasm_plugin"] = { - "name": "projects/sample1/locations/sample2/wasmPlugins/sample3", + request_init["gateway"] = { + "name": "projects/sample1/locations/sample2/gateways/sample3", + "self_link": "self_link_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "description": "description_value", "labels": {}, - "main_version_id": "main_version_id_value", - "log_config": {"enable": True, "sample_rate": 0.1165, "min_log_level": 1}, - "versions": {}, - "used_by": [{"name": "name_value"}], + "description": "description_value", + "type_": 1, + "addresses": ["addresses_value1", "addresses_value2"], + "ports": [569, 570], + "all_ports": True, + "scope": "scope_value", + "server_tls_policy": "server_tls_policy_value", + "certificate_urls": ["certificate_urls_value1", "certificate_urls_value2"], + "gateway_security_policy": "gateway_security_policy_value", + "network": "network_value", + "subnetwork": "subnetwork_value", + "ip_version": 1, + "envoy_headers": 1, + "routing_mode": 1, + "allow_global_access": True, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = extensibility.UpdateWasmPluginRequest.meta.fields["wasm_plugin"] + test_field = gcn_gateway.UpdateGatewayRequest.meta.fields["gateway"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -40947,7 +45136,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["wasm_plugin"].items(): # pragma: NO COVER + for field, value in request_init["gateway"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -40977,10 +45166,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["wasm_plugin"][field])): - del request_init["wasm_plugin"][field][i][subfield] + for i in range(0, len(request_init["gateway"][field])): + del request_init["gateway"][field][i][subfield] else: - del request_init["wasm_plugin"][field][subfield] + del request_init["gateway"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -40995,14 +45184,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_wasm_plugin(request) + response = client.update_gateway(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_wasm_plugin_rest_interceptors(null_interceptor): +def test_update_gateway_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -41016,21 +45205,21 @@ def test_update_wasm_plugin_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_wasm_plugin" + transports.NetworkServicesRestInterceptor, "post_update_gateway" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_update_wasm_plugin_with_metadata", + "post_update_gateway_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_wasm_plugin" + transports.NetworkServicesRestInterceptor, "pre_update_gateway" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = extensibility.UpdateWasmPluginRequest.pb( - extensibility.UpdateWasmPluginRequest() + pb_message = gcn_gateway.UpdateGatewayRequest.pb( + gcn_gateway.UpdateGatewayRequest() ) transcode.return_value = { "method": "post", @@ -41045,7 +45234,7 @@ def test_update_wasm_plugin_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = extensibility.UpdateWasmPluginRequest() + request = gcn_gateway.UpdateGatewayRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -41054,7 +45243,7 @@ def test_update_wasm_plugin_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.update_wasm_plugin( + client.update_gateway( request, metadata=[ ("key", "val"), @@ -41067,14 +45256,12 @@ def test_update_wasm_plugin_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_wasm_plugin_rest_bad_request( - request_type=extensibility.DeleteWasmPluginRequest, -): +def test_delete_gateway_rest_bad_request(request_type=gateway.DeleteGatewayRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/wasmPlugins/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/gateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -41090,23 +45277,23 @@ def test_delete_wasm_plugin_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_wasm_plugin(request) + client.delete_gateway(request) @pytest.mark.parametrize( "request_type", [ - extensibility.DeleteWasmPluginRequest, + gateway.DeleteGatewayRequest, dict, ], ) -def test_delete_wasm_plugin_rest_call_success(request_type): +def test_delete_gateway_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/wasmPlugins/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/gateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -41121,14 +45308,14 @@ def test_delete_wasm_plugin_rest_call_success(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_wasm_plugin(request) + response = client.delete_gateway(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_wasm_plugin_rest_interceptors(null_interceptor): +def test_delete_gateway_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -41142,22 +45329,20 @@ def test_delete_wasm_plugin_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_wasm_plugin" + transports.NetworkServicesRestInterceptor, "post_delete_gateway" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_delete_wasm_plugin_with_metadata", + "post_delete_gateway_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_wasm_plugin" + transports.NetworkServicesRestInterceptor, "pre_delete_gateway" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = extensibility.DeleteWasmPluginRequest.pb( - extensibility.DeleteWasmPluginRequest() - ) + pb_message = gateway.DeleteGatewayRequest.pb(gateway.DeleteGatewayRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -41171,7 +45356,7 @@ def test_delete_wasm_plugin_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = extensibility.DeleteWasmPluginRequest() + request = gateway.DeleteGatewayRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -41180,7 +45365,7 @@ def test_delete_wasm_plugin_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.delete_wasm_plugin( + client.delete_gateway( request, metadata=[ ("key", "val"), @@ -41193,7 +45378,9 @@ def test_delete_wasm_plugin_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_gateways_rest_bad_request(request_type=gateway.ListGatewaysRequest): +def test_list_grpc_routes_rest_bad_request( + request_type=grpc_route.ListGrpcRoutesRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -41214,17 +45401,17 @@ def test_list_gateways_rest_bad_request(request_type=gateway.ListGatewaysRequest response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_gateways(request) + client.list_grpc_routes(request) @pytest.mark.parametrize( "request_type", [ - gateway.ListGatewaysRequest, + grpc_route.ListGrpcRoutesRequest, dict, ], ) -def test_list_gateways_rest_call_success(request_type): +def test_list_grpc_routes_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -41236,7 +45423,7 @@ def test_list_gateways_rest_call_success(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gateway.ListGatewaysResponse( + return_value = grpc_route.ListGrpcRoutesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) @@ -41246,21 +45433,21 @@ def test_list_gateways_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = gateway.ListGatewaysResponse.pb(return_value) + return_value = grpc_route.ListGrpcRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_gateways(request) + response = client.list_grpc_routes(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListGatewaysPager) + assert isinstance(response, pagers.ListGrpcRoutesPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_gateways_rest_interceptors(null_interceptor): +def test_list_grpc_routes_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -41273,20 +45460,22 @@ def test_list_gateways_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_gateways" + transports.NetworkServicesRestInterceptor, "post_list_grpc_routes" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_gateways_with_metadata", + "post_list_grpc_routes_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_gateways" + transports.NetworkServicesRestInterceptor, "pre_list_grpc_routes" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gateway.ListGatewaysRequest.pb(gateway.ListGatewaysRequest()) + pb_message = grpc_route.ListGrpcRoutesRequest.pb( + grpc_route.ListGrpcRoutesRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -41297,21 +45486,21 @@ def test_list_gateways_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = gateway.ListGatewaysResponse.to_json( - gateway.ListGatewaysResponse() + return_value = grpc_route.ListGrpcRoutesResponse.to_json( + grpc_route.ListGrpcRoutesResponse() ) req.return_value.content = return_value - request = gateway.ListGatewaysRequest() + request = grpc_route.ListGrpcRoutesRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = gateway.ListGatewaysResponse() - post_with_metadata.return_value = gateway.ListGatewaysResponse(), metadata + post.return_value = grpc_route.ListGrpcRoutesResponse() + post_with_metadata.return_value = grpc_route.ListGrpcRoutesResponse(), metadata - client.list_gateways( + client.list_grpc_routes( request, metadata=[ ("key", "val"), @@ -41324,12 +45513,12 @@ def test_list_gateways_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_gateway_rest_bad_request(request_type=gateway.GetGatewayRequest): +def test_get_grpc_route_rest_bad_request(request_type=grpc_route.GetGrpcRouteRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/gateways/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -41345,44 +45534,35 @@ def test_get_gateway_rest_bad_request(request_type=gateway.GetGatewayRequest): response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_gateway(request) + client.get_grpc_route(request) @pytest.mark.parametrize( "request_type", [ - gateway.GetGatewayRequest, + grpc_route.GetGrpcRouteRequest, dict, ], ) -def test_get_gateway_rest_call_success(request_type): +def test_get_grpc_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/gateways/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gateway.Gateway( + return_value = grpc_route.GrpcRoute( name="name_value", self_link="self_link_value", description="description_value", - type_=gateway.Gateway.Type.OPEN_MESH, - addresses=["addresses_value"], - ports=[568], - scope="scope_value", - server_tls_policy="server_tls_policy_value", - certificate_urls=["certificate_urls_value"], - gateway_security_policy="gateway_security_policy_value", - network="network_value", - subnetwork="subnetwork_value", - ip_version=gateway.Gateway.IpVersion.IPV4, - envoy_headers=common.EnvoyHeaders.NONE, - routing_mode=gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE, + hostnames=["hostnames_value"], + meshes=["meshes_value"], + gateways=["gateways_value"], ) # Wrap the value into a proper Response obj @@ -41390,34 +45570,25 @@ def test_get_gateway_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = gateway.Gateway.pb(return_value) + return_value = grpc_route.GrpcRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_gateway(request) + response = client.get_grpc_route(request) # Establish that the response is the type that we expect. - assert isinstance(response, gateway.Gateway) + assert isinstance(response, grpc_route.GrpcRoute) assert response.name == "name_value" assert response.self_link == "self_link_value" assert response.description == "description_value" - assert response.type_ == gateway.Gateway.Type.OPEN_MESH - assert response.addresses == ["addresses_value"] - assert response.ports == [568] - assert response.scope == "scope_value" - assert response.server_tls_policy == "server_tls_policy_value" - assert response.certificate_urls == ["certificate_urls_value"] - assert response.gateway_security_policy == "gateway_security_policy_value" - assert response.network == "network_value" - assert response.subnetwork == "subnetwork_value" - assert response.ip_version == gateway.Gateway.IpVersion.IPV4 - assert response.envoy_headers == common.EnvoyHeaders.NONE - assert response.routing_mode == gateway.Gateway.RoutingMode.NEXT_HOP_ROUTING_MODE + assert response.hostnames == ["hostnames_value"] + assert response.meshes == ["meshes_value"] + assert response.gateways == ["gateways_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_gateway_rest_interceptors(null_interceptor): +def test_get_grpc_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -41430,19 +45601,20 @@ def test_get_gateway_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_gateway" + transports.NetworkServicesRestInterceptor, "post_get_grpc_route" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_gateway_with_metadata" + transports.NetworkServicesRestInterceptor, + "post_get_grpc_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_gateway" + transports.NetworkServicesRestInterceptor, "pre_get_grpc_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gateway.GetGatewayRequest.pb(gateway.GetGatewayRequest()) + pb_message = grpc_route.GetGrpcRouteRequest.pb(grpc_route.GetGrpcRouteRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -41453,19 +45625,19 @@ def test_get_gateway_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = gateway.Gateway.to_json(gateway.Gateway()) + return_value = grpc_route.GrpcRoute.to_json(grpc_route.GrpcRoute()) req.return_value.content = return_value - request = gateway.GetGatewayRequest() + request = grpc_route.GetGrpcRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = gateway.Gateway() - post_with_metadata.return_value = gateway.Gateway(), metadata + post.return_value = grpc_route.GrpcRoute() + post_with_metadata.return_value = grpc_route.GrpcRoute(), metadata - client.get_gateway( + client.get_grpc_route( request, metadata=[ ("key", "val"), @@ -41478,7 +45650,9 @@ def test_get_gateway_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_gateway_rest_bad_request(request_type=gcn_gateway.CreateGatewayRequest): +def test_create_grpc_route_rest_bad_request( + request_type=gcn_grpc_route.CreateGrpcRouteRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -41499,49 +45673,79 @@ def test_create_gateway_rest_bad_request(request_type=gcn_gateway.CreateGatewayR response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_gateway(request) + client.create_grpc_route(request) @pytest.mark.parametrize( "request_type", [ - gcn_gateway.CreateGatewayRequest, + gcn_grpc_route.CreateGrpcRouteRequest, dict, ], ) -def test_create_gateway_rest_call_success(request_type): +def test_create_grpc_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["gateway"] = { + request_init["grpc_route"] = { "name": "name_value", "self_link": "self_link_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, "labels": {}, "description": "description_value", - "type_": 1, - "addresses": ["addresses_value1", "addresses_value2"], - "ports": [569, 570], - "scope": "scope_value", - "server_tls_policy": "server_tls_policy_value", - "certificate_urls": ["certificate_urls_value1", "certificate_urls_value2"], - "gateway_security_policy": "gateway_security_policy_value", - "network": "network_value", - "subnetwork": "subnetwork_value", - "ip_version": 1, - "envoy_headers": 1, - "routing_mode": 1, + "hostnames": ["hostnames_value1", "hostnames_value2"], + "meshes": ["meshes_value1", "meshes_value2"], + "gateways": ["gateways_value1", "gateways_value2"], + "rules": [ + { + "matches": [ + { + "method": { + "type_": 1, + "grpc_service": "grpc_service_value", + "grpc_method": "grpc_method_value", + "case_sensitive": True, + }, + "headers": [ + {"type_": 1, "key": "key_value", "value": "value_value"} + ], + } + ], + "action": { + "destinations": [ + {"service_name": "service_name_value", "weight": 648} + ], + "fault_injection_policy": { + "delay": { + "fixed_delay": {"seconds": 751, "nanos": 543}, + "percentage": 1054, + }, + "abort": {"http_status": 1219, "percentage": 1054}, + }, + "timeout": {}, + "retry_policy": { + "retry_conditions": [ + "retry_conditions_value1", + "retry_conditions_value2", + ], + "num_retries": 1197, + }, + "stateful_session_affinity": {"cookie_ttl": {}}, + "idle_timeout": {}, + }, + } + ], } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_gateway.CreateGatewayRequest.meta.fields["gateway"] + test_field = gcn_grpc_route.CreateGrpcRouteRequest.meta.fields["grpc_route"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -41569,7 +45773,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["gateway"].items(): # pragma: NO COVER + for field, value in request_init["grpc_route"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -41599,10 +45803,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["gateway"][field])): - del request_init["gateway"][field][i][subfield] + for i in range(0, len(request_init["grpc_route"][field])): + del request_init["grpc_route"][field][i][subfield] else: - del request_init["gateway"][field][subfield] + del request_init["grpc_route"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -41617,14 +45821,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_gateway(request) + response = client.create_grpc_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_gateway_rest_interceptors(null_interceptor): +def test_create_grpc_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -41638,21 +45842,21 @@ def test_create_gateway_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_gateway" + transports.NetworkServicesRestInterceptor, "post_create_grpc_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_create_gateway_with_metadata", + "post_create_grpc_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_gateway" + transports.NetworkServicesRestInterceptor, "pre_create_grpc_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_gateway.CreateGatewayRequest.pb( - gcn_gateway.CreateGatewayRequest() + pb_message = gcn_grpc_route.CreateGrpcRouteRequest.pb( + gcn_grpc_route.CreateGrpcRouteRequest() ) transcode.return_value = { "method": "post", @@ -41667,7 +45871,7 @@ def test_create_gateway_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_gateway.CreateGatewayRequest() + request = gcn_grpc_route.CreateGrpcRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -41676,7 +45880,7 @@ def test_create_gateway_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_gateway( + client.create_grpc_route( request, metadata=[ ("key", "val"), @@ -41689,13 +45893,15 @@ def test_create_gateway_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_gateway_rest_bad_request(request_type=gcn_gateway.UpdateGatewayRequest): +def test_update_grpc_route_rest_bad_request( + request_type=gcn_grpc_route.UpdateGrpcRouteRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "gateway": {"name": "projects/sample1/locations/sample2/gateways/sample3"} + "grpc_route": {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} } request = request_type(**request_init) @@ -41712,51 +45918,81 @@ def test_update_gateway_rest_bad_request(request_type=gcn_gateway.UpdateGatewayR response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_gateway(request) + client.update_grpc_route(request) @pytest.mark.parametrize( "request_type", [ - gcn_gateway.UpdateGatewayRequest, + gcn_grpc_route.UpdateGrpcRouteRequest, dict, ], ) -def test_update_gateway_rest_call_success(request_type): +def test_update_grpc_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "gateway": {"name": "projects/sample1/locations/sample2/gateways/sample3"} + "grpc_route": {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} } - request_init["gateway"] = { - "name": "projects/sample1/locations/sample2/gateways/sample3", + request_init["grpc_route"] = { + "name": "projects/sample1/locations/sample2/grpcRoutes/sample3", "self_link": "self_link_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, "labels": {}, "description": "description_value", - "type_": 1, - "addresses": ["addresses_value1", "addresses_value2"], - "ports": [569, 570], - "scope": "scope_value", - "server_tls_policy": "server_tls_policy_value", - "certificate_urls": ["certificate_urls_value1", "certificate_urls_value2"], - "gateway_security_policy": "gateway_security_policy_value", - "network": "network_value", - "subnetwork": "subnetwork_value", - "ip_version": 1, - "envoy_headers": 1, - "routing_mode": 1, + "hostnames": ["hostnames_value1", "hostnames_value2"], + "meshes": ["meshes_value1", "meshes_value2"], + "gateways": ["gateways_value1", "gateways_value2"], + "rules": [ + { + "matches": [ + { + "method": { + "type_": 1, + "grpc_service": "grpc_service_value", + "grpc_method": "grpc_method_value", + "case_sensitive": True, + }, + "headers": [ + {"type_": 1, "key": "key_value", "value": "value_value"} + ], + } + ], + "action": { + "destinations": [ + {"service_name": "service_name_value", "weight": 648} + ], + "fault_injection_policy": { + "delay": { + "fixed_delay": {"seconds": 751, "nanos": 543}, + "percentage": 1054, + }, + "abort": {"http_status": 1219, "percentage": 1054}, + }, + "timeout": {}, + "retry_policy": { + "retry_conditions": [ + "retry_conditions_value1", + "retry_conditions_value2", + ], + "num_retries": 1197, + }, + "stateful_session_affinity": {"cookie_ttl": {}}, + "idle_timeout": {}, + }, + } + ], } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_gateway.UpdateGatewayRequest.meta.fields["gateway"] + test_field = gcn_grpc_route.UpdateGrpcRouteRequest.meta.fields["grpc_route"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -41784,7 +46020,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["gateway"].items(): # pragma: NO COVER + for field, value in request_init["grpc_route"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -41814,10 +46050,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["gateway"][field])): - del request_init["gateway"][field][i][subfield] + for i in range(0, len(request_init["grpc_route"][field])): + del request_init["grpc_route"][field][i][subfield] else: - del request_init["gateway"][field][subfield] + del request_init["grpc_route"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -41832,14 +46068,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_gateway(request) + response = client.update_grpc_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_gateway_rest_interceptors(null_interceptor): +def test_update_grpc_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -41853,21 +46089,21 @@ def test_update_gateway_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_gateway" + transports.NetworkServicesRestInterceptor, "post_update_grpc_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_update_gateway_with_metadata", + "post_update_grpc_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_gateway" + transports.NetworkServicesRestInterceptor, "pre_update_grpc_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_gateway.UpdateGatewayRequest.pb( - gcn_gateway.UpdateGatewayRequest() + pb_message = gcn_grpc_route.UpdateGrpcRouteRequest.pb( + gcn_grpc_route.UpdateGrpcRouteRequest() ) transcode.return_value = { "method": "post", @@ -41882,7 +46118,7 @@ def test_update_gateway_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_gateway.UpdateGatewayRequest() + request = gcn_grpc_route.UpdateGrpcRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -41891,7 +46127,7 @@ def test_update_gateway_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.update_gateway( + client.update_grpc_route( request, metadata=[ ("key", "val"), @@ -41904,12 +46140,14 @@ def test_update_gateway_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_gateway_rest_bad_request(request_type=gateway.DeleteGatewayRequest): +def test_delete_grpc_route_rest_bad_request( + request_type=grpc_route.DeleteGrpcRouteRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/gateways/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -41925,23 +46163,23 @@ def test_delete_gateway_rest_bad_request(request_type=gateway.DeleteGatewayReque response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_gateway(request) + client.delete_grpc_route(request) @pytest.mark.parametrize( "request_type", [ - gateway.DeleteGatewayRequest, + grpc_route.DeleteGrpcRouteRequest, dict, ], ) -def test_delete_gateway_rest_call_success(request_type): +def test_delete_grpc_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/gateways/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -41956,14 +46194,14 @@ def test_delete_gateway_rest_call_success(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_gateway(request) + response = client.delete_grpc_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_gateway_rest_interceptors(null_interceptor): +def test_delete_grpc_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -41977,20 +46215,22 @@ def test_delete_gateway_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_gateway" + transports.NetworkServicesRestInterceptor, "post_delete_grpc_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_delete_gateway_with_metadata", + "post_delete_grpc_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_gateway" + transports.NetworkServicesRestInterceptor, "pre_delete_grpc_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gateway.DeleteGatewayRequest.pb(gateway.DeleteGatewayRequest()) + pb_message = grpc_route.DeleteGrpcRouteRequest.pb( + grpc_route.DeleteGrpcRouteRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -42004,7 +46244,7 @@ def test_delete_gateway_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gateway.DeleteGatewayRequest() + request = grpc_route.DeleteGrpcRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -42013,7 +46253,7 @@ def test_delete_gateway_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.delete_gateway( + client.delete_grpc_route( request, metadata=[ ("key", "val"), @@ -42026,8 +46266,8 @@ def test_delete_gateway_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_grpc_routes_rest_bad_request( - request_type=grpc_route.ListGrpcRoutesRequest, +def test_list_http_routes_rest_bad_request( + request_type=http_route.ListHttpRoutesRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" @@ -42049,17 +46289,17 @@ def test_list_grpc_routes_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_grpc_routes(request) + client.list_http_routes(request) @pytest.mark.parametrize( "request_type", [ - grpc_route.ListGrpcRoutesRequest, + http_route.ListHttpRoutesRequest, dict, ], ) -def test_list_grpc_routes_rest_call_success(request_type): +def test_list_http_routes_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -42071,7 +46311,7 @@ def test_list_grpc_routes_rest_call_success(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = grpc_route.ListGrpcRoutesResponse( + return_value = http_route.ListHttpRoutesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) @@ -42081,21 +46321,21 @@ def test_list_grpc_routes_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = grpc_route.ListGrpcRoutesResponse.pb(return_value) + return_value = http_route.ListHttpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_grpc_routes(request) + response = client.list_http_routes(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListGrpcRoutesPager) + assert isinstance(response, pagers.ListHttpRoutesPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_grpc_routes_rest_interceptors(null_interceptor): +def test_list_http_routes_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -42108,21 +46348,21 @@ def test_list_grpc_routes_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_grpc_routes" + transports.NetworkServicesRestInterceptor, "post_list_http_routes" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_grpc_routes_with_metadata", + "post_list_http_routes_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_grpc_routes" + transports.NetworkServicesRestInterceptor, "pre_list_http_routes" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = grpc_route.ListGrpcRoutesRequest.pb( - grpc_route.ListGrpcRoutesRequest() + pb_message = http_route.ListHttpRoutesRequest.pb( + http_route.ListHttpRoutesRequest() ) transcode.return_value = { "method": "post", @@ -42134,21 +46374,21 @@ def test_list_grpc_routes_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = grpc_route.ListGrpcRoutesResponse.to_json( - grpc_route.ListGrpcRoutesResponse() + return_value = http_route.ListHttpRoutesResponse.to_json( + http_route.ListHttpRoutesResponse() ) req.return_value.content = return_value - request = grpc_route.ListGrpcRoutesRequest() + request = http_route.ListHttpRoutesRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = grpc_route.ListGrpcRoutesResponse() - post_with_metadata.return_value = grpc_route.ListGrpcRoutesResponse(), metadata + post.return_value = http_route.ListHttpRoutesResponse() + post_with_metadata.return_value = http_route.ListHttpRoutesResponse(), metadata - client.list_grpc_routes( + client.list_http_routes( request, metadata=[ ("key", "val"), @@ -42161,12 +46401,12 @@ def test_list_grpc_routes_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_grpc_route_rest_bad_request(request_type=grpc_route.GetGrpcRouteRequest): +def test_get_http_route_rest_bad_request(request_type=http_route.GetHttpRouteRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -42182,29 +46422,29 @@ def test_get_grpc_route_rest_bad_request(request_type=grpc_route.GetGrpcRouteReq response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_grpc_route(request) + client.get_http_route(request) @pytest.mark.parametrize( "request_type", [ - grpc_route.GetGrpcRouteRequest, + http_route.GetHttpRouteRequest, dict, ], ) -def test_get_grpc_route_rest_call_success(request_type): +def test_get_http_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = grpc_route.GrpcRoute( + return_value = http_route.HttpRoute( name="name_value", self_link="self_link_value", description="description_value", @@ -42218,15 +46458,15 @@ def test_get_grpc_route_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = grpc_route.GrpcRoute.pb(return_value) + return_value = http_route.HttpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_grpc_route(request) + response = client.get_http_route(request) # Establish that the response is the type that we expect. - assert isinstance(response, grpc_route.GrpcRoute) + assert isinstance(response, http_route.HttpRoute) assert response.name == "name_value" assert response.self_link == "self_link_value" assert response.description == "description_value" @@ -42236,7 +46476,7 @@ def test_get_grpc_route_rest_call_success(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_grpc_route_rest_interceptors(null_interceptor): +def test_get_http_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -42249,20 +46489,20 @@ def test_get_grpc_route_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_grpc_route" + transports.NetworkServicesRestInterceptor, "post_get_http_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_get_grpc_route_with_metadata", + "post_get_http_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_grpc_route" + transports.NetworkServicesRestInterceptor, "pre_get_http_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = grpc_route.GetGrpcRouteRequest.pb(grpc_route.GetGrpcRouteRequest()) + pb_message = http_route.GetHttpRouteRequest.pb(http_route.GetHttpRouteRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -42273,19 +46513,19 @@ def test_get_grpc_route_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = grpc_route.GrpcRoute.to_json(grpc_route.GrpcRoute()) + return_value = http_route.HttpRoute.to_json(http_route.HttpRoute()) req.return_value.content = return_value - request = grpc_route.GetGrpcRouteRequest() + request = http_route.GetHttpRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = grpc_route.GrpcRoute() - post_with_metadata.return_value = grpc_route.GrpcRoute(), metadata + post.return_value = http_route.HttpRoute() + post_with_metadata.return_value = http_route.HttpRoute(), metadata - client.get_grpc_route( + client.get_http_route( request, metadata=[ ("key", "val"), @@ -42298,8 +46538,8 @@ def test_get_grpc_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_grpc_route_rest_bad_request( - request_type=gcn_grpc_route.CreateGrpcRouteRequest, +def test_create_http_route_rest_bad_request( + request_type=gcn_http_route.CreateHttpRouteRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" @@ -42321,52 +46561,85 @@ def test_create_grpc_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_grpc_route(request) + client.create_http_route(request) @pytest.mark.parametrize( "request_type", [ - gcn_grpc_route.CreateGrpcRouteRequest, + gcn_http_route.CreateHttpRouteRequest, dict, ], ) -def test_create_grpc_route_rest_call_success(request_type): +def test_create_http_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["grpc_route"] = { + request_init["http_route"] = { "name": "name_value", "self_link": "self_link_value", + "description": "description_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "labels": {}, - "description": "description_value", "hostnames": ["hostnames_value1", "hostnames_value2"], "meshes": ["meshes_value1", "meshes_value2"], "gateways": ["gateways_value1", "gateways_value2"], + "labels": {}, "rules": [ { "matches": [ { - "method": { - "type_": 1, - "grpc_service": "grpc_service_value", - "grpc_method": "grpc_method_value", - "case_sensitive": True, - }, + "full_path_match": "full_path_match_value", + "prefix_match": "prefix_match_value", + "regex_match": "regex_match_value", + "ignore_case": True, "headers": [ - {"type_": 1, "key": "key_value", "value": "value_value"} + { + "exact_match": "exact_match_value", + "regex_match": "regex_match_value", + "prefix_match": "prefix_match_value", + "present_match": True, + "suffix_match": "suffix_match_value", + "range_match": {"start": 558, "end": 311}, + "header": "header_value", + "invert_match": True, + } + ], + "query_parameters": [ + { + "exact_match": "exact_match_value", + "regex_match": "regex_match_value", + "present_match": True, + "query_parameter": "query_parameter_value", + } ], } ], "action": { "destinations": [ - {"service_name": "service_name_value", "weight": 648} + { + "service_name": "service_name_value", + "weight": 648, + "request_header_modifier": { + "set": {}, + "add": {}, + "remove": ["remove_value1", "remove_value2"], + }, + "response_header_modifier": {}, + } ], + "redirect": { + "host_redirect": "host_redirect_value", + "path_redirect": "path_redirect_value", + "prefix_rewrite": "prefix_rewrite_value", + "response_code": 1, + "https_redirect": True, + "strip_query": True, + "port_redirect": 1398, + }, "fault_injection_policy": { "delay": { "fixed_delay": {"seconds": 751, "nanos": 543}, @@ -42374,6 +46647,12 @@ def test_create_grpc_route_rest_call_success(request_type): }, "abort": {"http_status": 1219, "percentage": 1054}, }, + "request_header_modifier": {}, + "response_header_modifier": {}, + "url_rewrite": { + "path_prefix_rewrite": "path_prefix_rewrite_value", + "host_rewrite": "host_rewrite_value", + }, "timeout": {}, "retry_policy": { "retry_conditions": [ @@ -42381,8 +46660,43 @@ def test_create_grpc_route_rest_call_success(request_type): "retry_conditions_value2", ], "num_retries": 1197, + "per_try_timeout": {}, + }, + "request_mirror_policy": { + "destination": {}, + "mirror_percent": 0.1515, + }, + "cors_policy": { + "allow_origins": [ + "allow_origins_value1", + "allow_origins_value2", + ], + "allow_origin_regexes": [ + "allow_origin_regexes_value1", + "allow_origin_regexes_value2", + ], + "allow_methods": [ + "allow_methods_value1", + "allow_methods_value2", + ], + "allow_headers": [ + "allow_headers_value1", + "allow_headers_value2", + ], + "expose_headers": [ + "expose_headers_value1", + "expose_headers_value2", + ], + "max_age": "max_age_value", + "allow_credentials": True, + "disabled": True, }, "stateful_session_affinity": {"cookie_ttl": {}}, + "direct_response": { + "string_body": "string_body_value", + "bytes_body": b"bytes_body_blob", + "status": 676, + }, "idle_timeout": {}, }, } @@ -42393,7 +46707,7 @@ def test_create_grpc_route_rest_call_success(request_type): # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_grpc_route.CreateGrpcRouteRequest.meta.fields["grpc_route"] + test_field = gcn_http_route.CreateHttpRouteRequest.meta.fields["http_route"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -42421,7 +46735,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["grpc_route"].items(): # pragma: NO COVER + for field, value in request_init["http_route"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -42451,10 +46765,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["grpc_route"][field])): - del request_init["grpc_route"][field][i][subfield] + for i in range(0, len(request_init["http_route"][field])): + del request_init["http_route"][field][i][subfield] else: - del request_init["grpc_route"][field][subfield] + del request_init["http_route"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -42469,14 +46783,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_grpc_route(request) + response = client.create_http_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_grpc_route_rest_interceptors(null_interceptor): +def test_create_http_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -42490,21 +46804,21 @@ def test_create_grpc_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_grpc_route" + transports.NetworkServicesRestInterceptor, "post_create_http_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_create_grpc_route_with_metadata", + "post_create_http_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_grpc_route" + transports.NetworkServicesRestInterceptor, "pre_create_http_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_grpc_route.CreateGrpcRouteRequest.pb( - gcn_grpc_route.CreateGrpcRouteRequest() + pb_message = gcn_http_route.CreateHttpRouteRequest.pb( + gcn_http_route.CreateHttpRouteRequest() ) transcode.return_value = { "method": "post", @@ -42519,7 +46833,7 @@ def test_create_grpc_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_grpc_route.CreateGrpcRouteRequest() + request = gcn_http_route.CreateHttpRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -42528,7 +46842,7 @@ def test_create_grpc_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_grpc_route( + client.create_http_route( request, metadata=[ ("key", "val"), @@ -42541,15 +46855,15 @@ def test_create_grpc_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_grpc_route_rest_bad_request( - request_type=gcn_grpc_route.UpdateGrpcRouteRequest, +def test_update_http_route_rest_bad_request( + request_type=gcn_http_route.UpdateHttpRouteRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "grpc_route": {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} + "http_route": {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} } request = request_type(**request_init) @@ -42566,54 +46880,87 @@ def test_update_grpc_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_grpc_route(request) + client.update_http_route(request) @pytest.mark.parametrize( "request_type", [ - gcn_grpc_route.UpdateGrpcRouteRequest, + gcn_http_route.UpdateHttpRouteRequest, dict, ], ) -def test_update_grpc_route_rest_call_success(request_type): +def test_update_http_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "grpc_route": {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} + "http_route": {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} } - request_init["grpc_route"] = { - "name": "projects/sample1/locations/sample2/grpcRoutes/sample3", + request_init["http_route"] = { + "name": "projects/sample1/locations/sample2/httpRoutes/sample3", "self_link": "self_link_value", + "description": "description_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "labels": {}, - "description": "description_value", "hostnames": ["hostnames_value1", "hostnames_value2"], "meshes": ["meshes_value1", "meshes_value2"], "gateways": ["gateways_value1", "gateways_value2"], + "labels": {}, "rules": [ { "matches": [ { - "method": { - "type_": 1, - "grpc_service": "grpc_service_value", - "grpc_method": "grpc_method_value", - "case_sensitive": True, - }, + "full_path_match": "full_path_match_value", + "prefix_match": "prefix_match_value", + "regex_match": "regex_match_value", + "ignore_case": True, "headers": [ - {"type_": 1, "key": "key_value", "value": "value_value"} + { + "exact_match": "exact_match_value", + "regex_match": "regex_match_value", + "prefix_match": "prefix_match_value", + "present_match": True, + "suffix_match": "suffix_match_value", + "range_match": {"start": 558, "end": 311}, + "header": "header_value", + "invert_match": True, + } + ], + "query_parameters": [ + { + "exact_match": "exact_match_value", + "regex_match": "regex_match_value", + "present_match": True, + "query_parameter": "query_parameter_value", + } ], } ], "action": { "destinations": [ - {"service_name": "service_name_value", "weight": 648} + { + "service_name": "service_name_value", + "weight": 648, + "request_header_modifier": { + "set": {}, + "add": {}, + "remove": ["remove_value1", "remove_value2"], + }, + "response_header_modifier": {}, + } ], + "redirect": { + "host_redirect": "host_redirect_value", + "path_redirect": "path_redirect_value", + "prefix_rewrite": "prefix_rewrite_value", + "response_code": 1, + "https_redirect": True, + "strip_query": True, + "port_redirect": 1398, + }, "fault_injection_policy": { "delay": { "fixed_delay": {"seconds": 751, "nanos": 543}, @@ -42621,6 +46968,12 @@ def test_update_grpc_route_rest_call_success(request_type): }, "abort": {"http_status": 1219, "percentage": 1054}, }, + "request_header_modifier": {}, + "response_header_modifier": {}, + "url_rewrite": { + "path_prefix_rewrite": "path_prefix_rewrite_value", + "host_rewrite": "host_rewrite_value", + }, "timeout": {}, "retry_policy": { "retry_conditions": [ @@ -42628,8 +46981,43 @@ def test_update_grpc_route_rest_call_success(request_type): "retry_conditions_value2", ], "num_retries": 1197, + "per_try_timeout": {}, + }, + "request_mirror_policy": { + "destination": {}, + "mirror_percent": 0.1515, + }, + "cors_policy": { + "allow_origins": [ + "allow_origins_value1", + "allow_origins_value2", + ], + "allow_origin_regexes": [ + "allow_origin_regexes_value1", + "allow_origin_regexes_value2", + ], + "allow_methods": [ + "allow_methods_value1", + "allow_methods_value2", + ], + "allow_headers": [ + "allow_headers_value1", + "allow_headers_value2", + ], + "expose_headers": [ + "expose_headers_value1", + "expose_headers_value2", + ], + "max_age": "max_age_value", + "allow_credentials": True, + "disabled": True, }, "stateful_session_affinity": {"cookie_ttl": {}}, + "direct_response": { + "string_body": "string_body_value", + "bytes_body": b"bytes_body_blob", + "status": 676, + }, "idle_timeout": {}, }, } @@ -42640,7 +47028,7 @@ def test_update_grpc_route_rest_call_success(request_type): # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_grpc_route.UpdateGrpcRouteRequest.meta.fields["grpc_route"] + test_field = gcn_http_route.UpdateHttpRouteRequest.meta.fields["http_route"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -42668,7 +47056,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["grpc_route"].items(): # pragma: NO COVER + for field, value in request_init["http_route"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -42698,10 +47086,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["grpc_route"][field])): - del request_init["grpc_route"][field][i][subfield] + for i in range(0, len(request_init["http_route"][field])): + del request_init["http_route"][field][i][subfield] else: - del request_init["grpc_route"][field][subfield] + del request_init["http_route"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -42716,14 +47104,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_grpc_route(request) + response = client.update_http_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_grpc_route_rest_interceptors(null_interceptor): +def test_update_http_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -42737,21 +47125,21 @@ def test_update_grpc_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_grpc_route" + transports.NetworkServicesRestInterceptor, "post_update_http_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_update_grpc_route_with_metadata", + "post_update_http_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_grpc_route" + transports.NetworkServicesRestInterceptor, "pre_update_http_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_grpc_route.UpdateGrpcRouteRequest.pb( - gcn_grpc_route.UpdateGrpcRouteRequest() + pb_message = gcn_http_route.UpdateHttpRouteRequest.pb( + gcn_http_route.UpdateHttpRouteRequest() ) transcode.return_value = { "method": "post", @@ -42766,7 +47154,7 @@ def test_update_grpc_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_grpc_route.UpdateGrpcRouteRequest() + request = gcn_http_route.UpdateHttpRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -42775,7 +47163,7 @@ def test_update_grpc_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.update_grpc_route( + client.update_http_route( request, metadata=[ ("key", "val"), @@ -42788,14 +47176,14 @@ def test_update_grpc_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_grpc_route_rest_bad_request( - request_type=grpc_route.DeleteGrpcRouteRequest, +def test_delete_http_route_rest_bad_request( + request_type=http_route.DeleteHttpRouteRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -42811,23 +47199,23 @@ def test_delete_grpc_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_grpc_route(request) + client.delete_http_route(request) @pytest.mark.parametrize( "request_type", [ - grpc_route.DeleteGrpcRouteRequest, + http_route.DeleteHttpRouteRequest, dict, ], ) -def test_delete_grpc_route_rest_call_success(request_type): +def test_delete_http_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/grpcRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -42842,14 +47230,14 @@ def test_delete_grpc_route_rest_call_success(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_grpc_route(request) + response = client.delete_http_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_grpc_route_rest_interceptors(null_interceptor): +def test_delete_http_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -42863,21 +47251,21 @@ def test_delete_grpc_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_grpc_route" + transports.NetworkServicesRestInterceptor, "post_delete_http_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_delete_grpc_route_with_metadata", + "post_delete_http_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_grpc_route" + transports.NetworkServicesRestInterceptor, "pre_delete_http_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = grpc_route.DeleteGrpcRouteRequest.pb( - grpc_route.DeleteGrpcRouteRequest() + pb_message = http_route.DeleteHttpRouteRequest.pb( + http_route.DeleteHttpRouteRequest() ) transcode.return_value = { "method": "post", @@ -42892,7 +47280,7 @@ def test_delete_grpc_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = grpc_route.DeleteGrpcRouteRequest() + request = http_route.DeleteHttpRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -42901,7 +47289,7 @@ def test_delete_grpc_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.delete_grpc_route( + client.delete_http_route( request, metadata=[ ("key", "val"), @@ -42914,9 +47302,7 @@ def test_delete_grpc_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_http_routes_rest_bad_request( - request_type=http_route.ListHttpRoutesRequest, -): +def test_list_tcp_routes_rest_bad_request(request_type=tcp_route.ListTcpRoutesRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -42937,17 +47323,17 @@ def test_list_http_routes_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_http_routes(request) + client.list_tcp_routes(request) @pytest.mark.parametrize( "request_type", [ - http_route.ListHttpRoutesRequest, + tcp_route.ListTcpRoutesRequest, dict, ], ) -def test_list_http_routes_rest_call_success(request_type): +def test_list_tcp_routes_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -42959,7 +47345,7 @@ def test_list_http_routes_rest_call_success(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = http_route.ListHttpRoutesResponse( + return_value = tcp_route.ListTcpRoutesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) @@ -42969,21 +47355,21 @@ def test_list_http_routes_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = http_route.ListHttpRoutesResponse.pb(return_value) + return_value = tcp_route.ListTcpRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_http_routes(request) + response = client.list_tcp_routes(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListHttpRoutesPager) + assert isinstance(response, pagers.ListTcpRoutesPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_http_routes_rest_interceptors(null_interceptor): +def test_list_tcp_routes_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -42996,22 +47382,20 @@ def test_list_http_routes_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_http_routes" + transports.NetworkServicesRestInterceptor, "post_list_tcp_routes" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_http_routes_with_metadata", + "post_list_tcp_routes_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_http_routes" + transports.NetworkServicesRestInterceptor, "pre_list_tcp_routes" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = http_route.ListHttpRoutesRequest.pb( - http_route.ListHttpRoutesRequest() - ) + pb_message = tcp_route.ListTcpRoutesRequest.pb(tcp_route.ListTcpRoutesRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -43022,21 +47406,21 @@ def test_list_http_routes_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = http_route.ListHttpRoutesResponse.to_json( - http_route.ListHttpRoutesResponse() + return_value = tcp_route.ListTcpRoutesResponse.to_json( + tcp_route.ListTcpRoutesResponse() ) req.return_value.content = return_value - request = http_route.ListHttpRoutesRequest() + request = tcp_route.ListTcpRoutesRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = http_route.ListHttpRoutesResponse() - post_with_metadata.return_value = http_route.ListHttpRoutesResponse(), metadata + post.return_value = tcp_route.ListTcpRoutesResponse() + post_with_metadata.return_value = tcp_route.ListTcpRoutesResponse(), metadata - client.list_http_routes( + client.list_tcp_routes( request, metadata=[ ("key", "val"), @@ -43049,12 +47433,12 @@ def test_list_http_routes_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_http_route_rest_bad_request(request_type=http_route.GetHttpRouteRequest): +def test_get_tcp_route_rest_bad_request(request_type=tcp_route.GetTcpRouteRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -43070,33 +47454,32 @@ def test_get_http_route_rest_bad_request(request_type=http_route.GetHttpRouteReq response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_http_route(request) + client.get_tcp_route(request) @pytest.mark.parametrize( "request_type", [ - http_route.GetHttpRouteRequest, + tcp_route.GetTcpRouteRequest, dict, ], ) -def test_get_http_route_rest_call_success(request_type): +def test_get_tcp_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = http_route.HttpRoute( + return_value = tcp_route.TcpRoute( name="name_value", self_link="self_link_value", description="description_value", - hostnames=["hostnames_value"], meshes=["meshes_value"], gateways=["gateways_value"], ) @@ -43106,25 +47489,24 @@ def test_get_http_route_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = http_route.HttpRoute.pb(return_value) + return_value = tcp_route.TcpRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_http_route(request) + response = client.get_tcp_route(request) # Establish that the response is the type that we expect. - assert isinstance(response, http_route.HttpRoute) + assert isinstance(response, tcp_route.TcpRoute) assert response.name == "name_value" assert response.self_link == "self_link_value" assert response.description == "description_value" - assert response.hostnames == ["hostnames_value"] assert response.meshes == ["meshes_value"] assert response.gateways == ["gateways_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_http_route_rest_interceptors(null_interceptor): +def test_get_tcp_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -43137,20 +47519,20 @@ def test_get_http_route_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_http_route" + transports.NetworkServicesRestInterceptor, "post_get_tcp_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_get_http_route_with_metadata", + "post_get_tcp_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_http_route" + transports.NetworkServicesRestInterceptor, "pre_get_tcp_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = http_route.GetHttpRouteRequest.pb(http_route.GetHttpRouteRequest()) + pb_message = tcp_route.GetTcpRouteRequest.pb(tcp_route.GetTcpRouteRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -43161,19 +47543,19 @@ def test_get_http_route_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = http_route.HttpRoute.to_json(http_route.HttpRoute()) + return_value = tcp_route.TcpRoute.to_json(tcp_route.TcpRoute()) req.return_value.content = return_value - request = http_route.GetHttpRouteRequest() + request = tcp_route.GetTcpRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = http_route.HttpRoute() - post_with_metadata.return_value = http_route.HttpRoute(), metadata + post.return_value = tcp_route.TcpRoute() + post_with_metadata.return_value = tcp_route.TcpRoute(), metadata - client.get_http_route( + client.get_tcp_route( request, metadata=[ ("key", "val"), @@ -43186,8 +47568,8 @@ def test_get_http_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_http_route_rest_bad_request( - request_type=gcn_http_route.CreateHttpRouteRequest, +def test_create_tcp_route_rest_bad_request( + request_type=gcn_tcp_route.CreateTcpRouteRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" @@ -43209,153 +47591,51 @@ def test_create_http_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_http_route(request) + client.create_tcp_route(request) @pytest.mark.parametrize( "request_type", [ - gcn_http_route.CreateHttpRouteRequest, + gcn_tcp_route.CreateTcpRouteRequest, dict, ], ) -def test_create_http_route_rest_call_success(request_type): +def test_create_tcp_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["http_route"] = { + request_init["tcp_route"] = { "name": "name_value", "self_link": "self_link_value", - "description": "description_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "hostnames": ["hostnames_value1", "hostnames_value2"], - "meshes": ["meshes_value1", "meshes_value2"], - "gateways": ["gateways_value1", "gateways_value2"], - "labels": {}, + "description": "description_value", "rules": [ { - "matches": [ - { - "full_path_match": "full_path_match_value", - "prefix_match": "prefix_match_value", - "regex_match": "regex_match_value", - "ignore_case": True, - "headers": [ - { - "exact_match": "exact_match_value", - "regex_match": "regex_match_value", - "prefix_match": "prefix_match_value", - "present_match": True, - "suffix_match": "suffix_match_value", - "range_match": {"start": 558, "end": 311}, - "header": "header_value", - "invert_match": True, - } - ], - "query_parameters": [ - { - "exact_match": "exact_match_value", - "regex_match": "regex_match_value", - "present_match": True, - "query_parameter": "query_parameter_value", - } - ], - } - ], + "matches": [{"address": "address_value", "port": "port_value"}], "action": { "destinations": [ - { - "service_name": "service_name_value", - "weight": 648, - "request_header_modifier": { - "set": {}, - "add": {}, - "remove": ["remove_value1", "remove_value2"], - }, - "response_header_modifier": {}, - } + {"service_name": "service_name_value", "weight": 648} ], - "redirect": { - "host_redirect": "host_redirect_value", - "path_redirect": "path_redirect_value", - "prefix_rewrite": "prefix_rewrite_value", - "response_code": 1, - "https_redirect": True, - "strip_query": True, - "port_redirect": 1398, - }, - "fault_injection_policy": { - "delay": { - "fixed_delay": {"seconds": 751, "nanos": 543}, - "percentage": 1054, - }, - "abort": {"http_status": 1219, "percentage": 1054}, - }, - "request_header_modifier": {}, - "response_header_modifier": {}, - "url_rewrite": { - "path_prefix_rewrite": "path_prefix_rewrite_value", - "host_rewrite": "host_rewrite_value", - }, - "timeout": {}, - "retry_policy": { - "retry_conditions": [ - "retry_conditions_value1", - "retry_conditions_value2", - ], - "num_retries": 1197, - "per_try_timeout": {}, - }, - "request_mirror_policy": { - "destination": {}, - "mirror_percent": 0.1515, - }, - "cors_policy": { - "allow_origins": [ - "allow_origins_value1", - "allow_origins_value2", - ], - "allow_origin_regexes": [ - "allow_origin_regexes_value1", - "allow_origin_regexes_value2", - ], - "allow_methods": [ - "allow_methods_value1", - "allow_methods_value2", - ], - "allow_headers": [ - "allow_headers_value1", - "allow_headers_value2", - ], - "expose_headers": [ - "expose_headers_value1", - "expose_headers_value2", - ], - "max_age": "max_age_value", - "allow_credentials": True, - "disabled": True, - }, - "stateful_session_affinity": {"cookie_ttl": {}}, - "direct_response": { - "string_body": "string_body_value", - "bytes_body": b"bytes_body_blob", - "status": 676, - }, - "idle_timeout": {}, + "original_destination": True, + "idle_timeout": {"seconds": 751, "nanos": 543}, }, } ], + "meshes": ["meshes_value1", "meshes_value2"], + "gateways": ["gateways_value1", "gateways_value2"], + "labels": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_http_route.CreateHttpRouteRequest.meta.fields["http_route"] + test_field = gcn_tcp_route.CreateTcpRouteRequest.meta.fields["tcp_route"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -43383,7 +47663,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["http_route"].items(): # pragma: NO COVER + for field, value in request_init["tcp_route"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -43413,10 +47693,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["http_route"][field])): - del request_init["http_route"][field][i][subfield] + for i in range(0, len(request_init["tcp_route"][field])): + del request_init["tcp_route"][field][i][subfield] else: - del request_init["http_route"][field][subfield] + del request_init["tcp_route"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -43431,14 +47711,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_http_route(request) + response = client.create_tcp_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_http_route_rest_interceptors(null_interceptor): +def test_create_tcp_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -43452,21 +47732,21 @@ def test_create_http_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_http_route" + transports.NetworkServicesRestInterceptor, "post_create_tcp_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_create_http_route_with_metadata", + "post_create_tcp_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_http_route" + transports.NetworkServicesRestInterceptor, "pre_create_tcp_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_http_route.CreateHttpRouteRequest.pb( - gcn_http_route.CreateHttpRouteRequest() + pb_message = gcn_tcp_route.CreateTcpRouteRequest.pb( + gcn_tcp_route.CreateTcpRouteRequest() ) transcode.return_value = { "method": "post", @@ -43481,7 +47761,7 @@ def test_create_http_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_http_route.CreateHttpRouteRequest() + request = gcn_tcp_route.CreateTcpRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -43490,7 +47770,7 @@ def test_create_http_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_http_route( + client.create_tcp_route( request, metadata=[ ("key", "val"), @@ -43503,15 +47783,15 @@ def test_create_http_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_http_route_rest_bad_request( - request_type=gcn_http_route.UpdateHttpRouteRequest, +def test_update_tcp_route_rest_bad_request( + request_type=gcn_tcp_route.UpdateTcpRouteRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "http_route": {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} + "tcp_route": {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} } request = request_type(**request_init) @@ -43528,155 +47808,53 @@ def test_update_http_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_http_route(request) + client.update_tcp_route(request) @pytest.mark.parametrize( "request_type", [ - gcn_http_route.UpdateHttpRouteRequest, + gcn_tcp_route.UpdateTcpRouteRequest, dict, ], ) -def test_update_http_route_rest_call_success(request_type): +def test_update_tcp_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "http_route": {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} + "tcp_route": {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} } - request_init["http_route"] = { - "name": "projects/sample1/locations/sample2/httpRoutes/sample3", + request_init["tcp_route"] = { + "name": "projects/sample1/locations/sample2/tcpRoutes/sample3", "self_link": "self_link_value", - "description": "description_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "hostnames": ["hostnames_value1", "hostnames_value2"], - "meshes": ["meshes_value1", "meshes_value2"], - "gateways": ["gateways_value1", "gateways_value2"], - "labels": {}, + "description": "description_value", "rules": [ { - "matches": [ - { - "full_path_match": "full_path_match_value", - "prefix_match": "prefix_match_value", - "regex_match": "regex_match_value", - "ignore_case": True, - "headers": [ - { - "exact_match": "exact_match_value", - "regex_match": "regex_match_value", - "prefix_match": "prefix_match_value", - "present_match": True, - "suffix_match": "suffix_match_value", - "range_match": {"start": 558, "end": 311}, - "header": "header_value", - "invert_match": True, - } - ], - "query_parameters": [ - { - "exact_match": "exact_match_value", - "regex_match": "regex_match_value", - "present_match": True, - "query_parameter": "query_parameter_value", - } - ], - } - ], + "matches": [{"address": "address_value", "port": "port_value"}], "action": { "destinations": [ - { - "service_name": "service_name_value", - "weight": 648, - "request_header_modifier": { - "set": {}, - "add": {}, - "remove": ["remove_value1", "remove_value2"], - }, - "response_header_modifier": {}, - } + {"service_name": "service_name_value", "weight": 648} ], - "redirect": { - "host_redirect": "host_redirect_value", - "path_redirect": "path_redirect_value", - "prefix_rewrite": "prefix_rewrite_value", - "response_code": 1, - "https_redirect": True, - "strip_query": True, - "port_redirect": 1398, - }, - "fault_injection_policy": { - "delay": { - "fixed_delay": {"seconds": 751, "nanos": 543}, - "percentage": 1054, - }, - "abort": {"http_status": 1219, "percentage": 1054}, - }, - "request_header_modifier": {}, - "response_header_modifier": {}, - "url_rewrite": { - "path_prefix_rewrite": "path_prefix_rewrite_value", - "host_rewrite": "host_rewrite_value", - }, - "timeout": {}, - "retry_policy": { - "retry_conditions": [ - "retry_conditions_value1", - "retry_conditions_value2", - ], - "num_retries": 1197, - "per_try_timeout": {}, - }, - "request_mirror_policy": { - "destination": {}, - "mirror_percent": 0.1515, - }, - "cors_policy": { - "allow_origins": [ - "allow_origins_value1", - "allow_origins_value2", - ], - "allow_origin_regexes": [ - "allow_origin_regexes_value1", - "allow_origin_regexes_value2", - ], - "allow_methods": [ - "allow_methods_value1", - "allow_methods_value2", - ], - "allow_headers": [ - "allow_headers_value1", - "allow_headers_value2", - ], - "expose_headers": [ - "expose_headers_value1", - "expose_headers_value2", - ], - "max_age": "max_age_value", - "allow_credentials": True, - "disabled": True, - }, - "stateful_session_affinity": {"cookie_ttl": {}}, - "direct_response": { - "string_body": "string_body_value", - "bytes_body": b"bytes_body_blob", - "status": 676, - }, - "idle_timeout": {}, + "original_destination": True, + "idle_timeout": {"seconds": 751, "nanos": 543}, }, } ], + "meshes": ["meshes_value1", "meshes_value2"], + "gateways": ["gateways_value1", "gateways_value2"], + "labels": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_http_route.UpdateHttpRouteRequest.meta.fields["http_route"] + test_field = gcn_tcp_route.UpdateTcpRouteRequest.meta.fields["tcp_route"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -43704,7 +47882,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["http_route"].items(): # pragma: NO COVER + for field, value in request_init["tcp_route"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -43734,10 +47912,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["http_route"][field])): - del request_init["http_route"][field][i][subfield] + for i in range(0, len(request_init["tcp_route"][field])): + del request_init["tcp_route"][field][i][subfield] else: - del request_init["http_route"][field][subfield] + del request_init["tcp_route"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -43752,14 +47930,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_http_route(request) + response = client.update_tcp_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_http_route_rest_interceptors(null_interceptor): +def test_update_tcp_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -43773,21 +47951,21 @@ def test_update_http_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_http_route" + transports.NetworkServicesRestInterceptor, "post_update_tcp_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_update_http_route_with_metadata", + "post_update_tcp_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_http_route" + transports.NetworkServicesRestInterceptor, "pre_update_tcp_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_http_route.UpdateHttpRouteRequest.pb( - gcn_http_route.UpdateHttpRouteRequest() + pb_message = gcn_tcp_route.UpdateTcpRouteRequest.pb( + gcn_tcp_route.UpdateTcpRouteRequest() ) transcode.return_value = { "method": "post", @@ -43802,7 +47980,7 @@ def test_update_http_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_http_route.UpdateHttpRouteRequest() + request = gcn_tcp_route.UpdateTcpRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -43811,7 +47989,7 @@ def test_update_http_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.update_http_route( + client.update_tcp_route( request, metadata=[ ("key", "val"), @@ -43824,14 +48002,14 @@ def test_update_http_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_http_route_rest_bad_request( - request_type=http_route.DeleteHttpRouteRequest, +def test_delete_tcp_route_rest_bad_request( + request_type=tcp_route.DeleteTcpRouteRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -43847,23 +48025,23 @@ def test_delete_http_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_http_route(request) + client.delete_tcp_route(request) @pytest.mark.parametrize( "request_type", [ - http_route.DeleteHttpRouteRequest, + tcp_route.DeleteTcpRouteRequest, dict, ], ) -def test_delete_http_route_rest_call_success(request_type): +def test_delete_tcp_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/httpRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -43878,14 +48056,14 @@ def test_delete_http_route_rest_call_success(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_http_route(request) + response = client.delete_tcp_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_http_route_rest_interceptors(null_interceptor): +def test_delete_tcp_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -43899,21 +48077,21 @@ def test_delete_http_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_http_route" + transports.NetworkServicesRestInterceptor, "post_delete_tcp_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_delete_http_route_with_metadata", + "post_delete_tcp_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_http_route" + transports.NetworkServicesRestInterceptor, "pre_delete_tcp_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = http_route.DeleteHttpRouteRequest.pb( - http_route.DeleteHttpRouteRequest() + pb_message = tcp_route.DeleteTcpRouteRequest.pb( + tcp_route.DeleteTcpRouteRequest() ) transcode.return_value = { "method": "post", @@ -43928,7 +48106,7 @@ def test_delete_http_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = http_route.DeleteHttpRouteRequest() + request = tcp_route.DeleteTcpRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -43937,7 +48115,7 @@ def test_delete_http_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.delete_http_route( + client.delete_tcp_route( request, metadata=[ ("key", "val"), @@ -43950,7 +48128,7 @@ def test_delete_http_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_tcp_routes_rest_bad_request(request_type=tcp_route.ListTcpRoutesRequest): +def test_list_tls_routes_rest_bad_request(request_type=tls_route.ListTlsRoutesRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -43971,17 +48149,17 @@ def test_list_tcp_routes_rest_bad_request(request_type=tcp_route.ListTcpRoutesRe response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_tcp_routes(request) + client.list_tls_routes(request) @pytest.mark.parametrize( "request_type", [ - tcp_route.ListTcpRoutesRequest, + tls_route.ListTlsRoutesRequest, dict, ], ) -def test_list_tcp_routes_rest_call_success(request_type): +def test_list_tls_routes_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -43993,7 +48171,7 @@ def test_list_tcp_routes_rest_call_success(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = tcp_route.ListTcpRoutesResponse( + return_value = tls_route.ListTlsRoutesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) @@ -44003,21 +48181,21 @@ def test_list_tcp_routes_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = tcp_route.ListTcpRoutesResponse.pb(return_value) + return_value = tls_route.ListTlsRoutesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_tcp_routes(request) + response = client.list_tls_routes(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListTcpRoutesPager) + assert isinstance(response, pagers.ListTlsRoutesPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_tcp_routes_rest_interceptors(null_interceptor): +def test_list_tls_routes_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -44030,20 +48208,20 @@ def test_list_tcp_routes_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_tcp_routes" + transports.NetworkServicesRestInterceptor, "post_list_tls_routes" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_tcp_routes_with_metadata", + "post_list_tls_routes_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_tcp_routes" + transports.NetworkServicesRestInterceptor, "pre_list_tls_routes" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = tcp_route.ListTcpRoutesRequest.pb(tcp_route.ListTcpRoutesRequest()) + pb_message = tls_route.ListTlsRoutesRequest.pb(tls_route.ListTlsRoutesRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -44054,21 +48232,21 @@ def test_list_tcp_routes_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = tcp_route.ListTcpRoutesResponse.to_json( - tcp_route.ListTcpRoutesResponse() + return_value = tls_route.ListTlsRoutesResponse.to_json( + tls_route.ListTlsRoutesResponse() ) req.return_value.content = return_value - request = tcp_route.ListTcpRoutesRequest() + request = tls_route.ListTlsRoutesRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = tcp_route.ListTcpRoutesResponse() - post_with_metadata.return_value = tcp_route.ListTcpRoutesResponse(), metadata + post.return_value = tls_route.ListTlsRoutesResponse() + post_with_metadata.return_value = tls_route.ListTlsRoutesResponse(), metadata - client.list_tcp_routes( + client.list_tls_routes( request, metadata=[ ("key", "val"), @@ -44081,12 +48259,12 @@ def test_list_tcp_routes_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_tcp_route_rest_bad_request(request_type=tcp_route.GetTcpRouteRequest): +def test_get_tls_route_rest_bad_request(request_type=tls_route.GetTlsRouteRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -44102,34 +48280,35 @@ def test_get_tcp_route_rest_bad_request(request_type=tcp_route.GetTcpRouteReques response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_tcp_route(request) + client.get_tls_route(request) @pytest.mark.parametrize( "request_type", [ - tcp_route.GetTcpRouteRequest, + tls_route.GetTlsRouteRequest, dict, ], ) -def test_get_tcp_route_rest_call_success(request_type): +def test_get_tls_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = tcp_route.TcpRoute( + return_value = tls_route.TlsRoute( name="name_value", self_link="self_link_value", description="description_value", meshes=["meshes_value"], gateways=["gateways_value"], + target_proxies=["target_proxies_value"], ) # Wrap the value into a proper Response obj @@ -44137,24 +48316,25 @@ def test_get_tcp_route_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = tcp_route.TcpRoute.pb(return_value) + return_value = tls_route.TlsRoute.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_tcp_route(request) + response = client.get_tls_route(request) # Establish that the response is the type that we expect. - assert isinstance(response, tcp_route.TcpRoute) + assert isinstance(response, tls_route.TlsRoute) assert response.name == "name_value" assert response.self_link == "self_link_value" assert response.description == "description_value" assert response.meshes == ["meshes_value"] assert response.gateways == ["gateways_value"] + assert response.target_proxies == ["target_proxies_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_tcp_route_rest_interceptors(null_interceptor): +def test_get_tls_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -44167,20 +48347,20 @@ def test_get_tcp_route_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_tcp_route" + transports.NetworkServicesRestInterceptor, "post_get_tls_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_get_tcp_route_with_metadata", + "post_get_tls_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_tcp_route" + transports.NetworkServicesRestInterceptor, "pre_get_tls_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = tcp_route.GetTcpRouteRequest.pb(tcp_route.GetTcpRouteRequest()) + pb_message = tls_route.GetTlsRouteRequest.pb(tls_route.GetTlsRouteRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -44191,19 +48371,19 @@ def test_get_tcp_route_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = tcp_route.TcpRoute.to_json(tcp_route.TcpRoute()) + return_value = tls_route.TlsRoute.to_json(tls_route.TlsRoute()) req.return_value.content = return_value - request = tcp_route.GetTcpRouteRequest() + request = tls_route.GetTlsRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = tcp_route.TcpRoute() - post_with_metadata.return_value = tcp_route.TcpRoute(), metadata + post.return_value = tls_route.TlsRoute() + post_with_metadata.return_value = tls_route.TlsRoute(), metadata - client.get_tcp_route( + client.get_tls_route( request, metadata=[ ("key", "val"), @@ -44216,8 +48396,8 @@ def test_get_tcp_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_tcp_route_rest_bad_request( - request_type=gcn_tcp_route.CreateTcpRouteRequest, +def test_create_tls_route_rest_bad_request( + request_type=gcn_tls_route.CreateTlsRouteRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" @@ -44239,24 +48419,24 @@ def test_create_tcp_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_tcp_route(request) + client.create_tls_route(request) @pytest.mark.parametrize( "request_type", [ - gcn_tcp_route.CreateTcpRouteRequest, + gcn_tls_route.CreateTlsRouteRequest, dict, ], ) -def test_create_tcp_route_rest_call_success(request_type): +def test_create_tls_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["tcp_route"] = { + request_init["tls_route"] = { "name": "name_value", "self_link": "self_link_value", "create_time": {"seconds": 751, "nanos": 543}, @@ -44264,18 +48444,23 @@ def test_create_tcp_route_rest_call_success(request_type): "description": "description_value", "rules": [ { - "matches": [{"address": "address_value", "port": "port_value"}], + "matches": [ + { + "sni_host": ["sni_host_value1", "sni_host_value2"], + "alpn": ["alpn_value1", "alpn_value2"], + } + ], "action": { "destinations": [ {"service_name": "service_name_value", "weight": 648} ], - "original_destination": True, "idle_timeout": {"seconds": 751, "nanos": 543}, }, } ], "meshes": ["meshes_value1", "meshes_value2"], "gateways": ["gateways_value1", "gateways_value2"], + "target_proxies": ["target_proxies_value1", "target_proxies_value2"], "labels": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. @@ -44283,7 +48468,7 @@ def test_create_tcp_route_rest_call_success(request_type): # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_tcp_route.CreateTcpRouteRequest.meta.fields["tcp_route"] + test_field = gcn_tls_route.CreateTlsRouteRequest.meta.fields["tls_route"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -44311,7 +48496,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["tcp_route"].items(): # pragma: NO COVER + for field, value in request_init["tls_route"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -44341,10 +48526,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["tcp_route"][field])): - del request_init["tcp_route"][field][i][subfield] + for i in range(0, len(request_init["tls_route"][field])): + del request_init["tls_route"][field][i][subfield] else: - del request_init["tcp_route"][field][subfield] + del request_init["tls_route"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -44359,14 +48544,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_tcp_route(request) + response = client.create_tls_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_tcp_route_rest_interceptors(null_interceptor): +def test_create_tls_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -44380,21 +48565,21 @@ def test_create_tcp_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_tcp_route" + transports.NetworkServicesRestInterceptor, "post_create_tls_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_create_tcp_route_with_metadata", + "post_create_tls_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_tcp_route" + transports.NetworkServicesRestInterceptor, "pre_create_tls_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_tcp_route.CreateTcpRouteRequest.pb( - gcn_tcp_route.CreateTcpRouteRequest() + pb_message = gcn_tls_route.CreateTlsRouteRequest.pb( + gcn_tls_route.CreateTlsRouteRequest() ) transcode.return_value = { "method": "post", @@ -44409,7 +48594,7 @@ def test_create_tcp_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_tcp_route.CreateTcpRouteRequest() + request = gcn_tls_route.CreateTlsRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -44418,7 +48603,7 @@ def test_create_tcp_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_tcp_route( + client.create_tls_route( request, metadata=[ ("key", "val"), @@ -44431,15 +48616,15 @@ def test_create_tcp_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_tcp_route_rest_bad_request( - request_type=gcn_tcp_route.UpdateTcpRouteRequest, +def test_update_tls_route_rest_bad_request( + request_type=gcn_tls_route.UpdateTlsRouteRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "tcp_route": {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} + "tls_route": {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} } request = request_type(**request_init) @@ -44456,45 +48641,50 @@ def test_update_tcp_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_tcp_route(request) + client.update_tls_route(request) @pytest.mark.parametrize( "request_type", [ - gcn_tcp_route.UpdateTcpRouteRequest, + gcn_tls_route.UpdateTlsRouteRequest, dict, ], ) -def test_update_tcp_route_rest_call_success(request_type): +def test_update_tls_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "tcp_route": {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} + "tls_route": {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} } - request_init["tcp_route"] = { - "name": "projects/sample1/locations/sample2/tcpRoutes/sample3", + request_init["tls_route"] = { + "name": "projects/sample1/locations/sample2/tlsRoutes/sample3", "self_link": "self_link_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, "description": "description_value", "rules": [ { - "matches": [{"address": "address_value", "port": "port_value"}], + "matches": [ + { + "sni_host": ["sni_host_value1", "sni_host_value2"], + "alpn": ["alpn_value1", "alpn_value2"], + } + ], "action": { "destinations": [ {"service_name": "service_name_value", "weight": 648} ], - "original_destination": True, "idle_timeout": {"seconds": 751, "nanos": 543}, }, } ], "meshes": ["meshes_value1", "meshes_value2"], "gateways": ["gateways_value1", "gateways_value2"], + "target_proxies": ["target_proxies_value1", "target_proxies_value2"], "labels": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. @@ -44502,7 +48692,7 @@ def test_update_tcp_route_rest_call_success(request_type): # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_tcp_route.UpdateTcpRouteRequest.meta.fields["tcp_route"] + test_field = gcn_tls_route.UpdateTlsRouteRequest.meta.fields["tls_route"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -44530,7 +48720,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["tcp_route"].items(): # pragma: NO COVER + for field, value in request_init["tls_route"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -44560,10 +48750,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["tcp_route"][field])): - del request_init["tcp_route"][field][i][subfield] + for i in range(0, len(request_init["tls_route"][field])): + del request_init["tls_route"][field][i][subfield] else: - del request_init["tcp_route"][field][subfield] + del request_init["tls_route"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -44578,14 +48768,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_tcp_route(request) + response = client.update_tls_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_tcp_route_rest_interceptors(null_interceptor): +def test_update_tls_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -44599,21 +48789,21 @@ def test_update_tcp_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_tcp_route" + transports.NetworkServicesRestInterceptor, "post_update_tls_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_update_tcp_route_with_metadata", + "post_update_tls_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_tcp_route" + transports.NetworkServicesRestInterceptor, "pre_update_tls_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_tcp_route.UpdateTcpRouteRequest.pb( - gcn_tcp_route.UpdateTcpRouteRequest() + pb_message = gcn_tls_route.UpdateTlsRouteRequest.pb( + gcn_tls_route.UpdateTlsRouteRequest() ) transcode.return_value = { "method": "post", @@ -44628,7 +48818,7 @@ def test_update_tcp_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_tcp_route.UpdateTcpRouteRequest() + request = gcn_tls_route.UpdateTlsRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -44637,7 +48827,7 @@ def test_update_tcp_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.update_tcp_route( + client.update_tls_route( request, metadata=[ ("key", "val"), @@ -44650,14 +48840,14 @@ def test_update_tcp_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_tcp_route_rest_bad_request( - request_type=tcp_route.DeleteTcpRouteRequest, +def test_delete_tls_route_rest_bad_request( + request_type=tls_route.DeleteTlsRouteRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -44673,23 +48863,23 @@ def test_delete_tcp_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_tcp_route(request) + client.delete_tls_route(request) @pytest.mark.parametrize( "request_type", [ - tcp_route.DeleteTcpRouteRequest, + tls_route.DeleteTlsRouteRequest, dict, ], ) -def test_delete_tcp_route_rest_call_success(request_type): +def test_delete_tls_route_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/tcpRoutes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -44704,14 +48894,14 @@ def test_delete_tcp_route_rest_call_success(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_tcp_route(request) + response = client.delete_tls_route(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_tcp_route_rest_interceptors(null_interceptor): +def test_delete_tls_route_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -44725,21 +48915,21 @@ def test_delete_tcp_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_tcp_route" + transports.NetworkServicesRestInterceptor, "post_delete_tls_route" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_delete_tcp_route_with_metadata", + "post_delete_tls_route_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_tcp_route" + transports.NetworkServicesRestInterceptor, "pre_delete_tls_route" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = tcp_route.DeleteTcpRouteRequest.pb( - tcp_route.DeleteTcpRouteRequest() + pb_message = tls_route.DeleteTlsRouteRequest.pb( + tls_route.DeleteTlsRouteRequest() ) transcode.return_value = { "method": "post", @@ -44754,7 +48944,7 @@ def test_delete_tcp_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = tcp_route.DeleteTcpRouteRequest() + request = tls_route.DeleteTlsRouteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -44763,7 +48953,7 @@ def test_delete_tcp_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.delete_tcp_route( + client.delete_tls_route( request, metadata=[ ("key", "val"), @@ -44776,7 +48966,9 @@ def test_delete_tcp_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_tls_routes_rest_bad_request(request_type=tls_route.ListTlsRoutesRequest): +def test_list_service_bindings_rest_bad_request( + request_type=service_binding.ListServiceBindingsRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -44797,17 +48989,17 @@ def test_list_tls_routes_rest_bad_request(request_type=tls_route.ListTlsRoutesRe response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_tls_routes(request) + client.list_service_bindings(request) @pytest.mark.parametrize( "request_type", [ - tls_route.ListTlsRoutesRequest, + service_binding.ListServiceBindingsRequest, dict, ], ) -def test_list_tls_routes_rest_call_success(request_type): +def test_list_service_bindings_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -44819,7 +49011,7 @@ def test_list_tls_routes_rest_call_success(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = tls_route.ListTlsRoutesResponse( + return_value = service_binding.ListServiceBindingsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) @@ -44829,21 +49021,21 @@ def test_list_tls_routes_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = tls_route.ListTlsRoutesResponse.pb(return_value) + return_value = service_binding.ListServiceBindingsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_tls_routes(request) + response = client.list_service_bindings(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListTlsRoutesPager) + assert isinstance(response, pagers.ListServiceBindingsPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_tls_routes_rest_interceptors(null_interceptor): +def test_list_service_bindings_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -44856,20 +49048,22 @@ def test_list_tls_routes_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_tls_routes" + transports.NetworkServicesRestInterceptor, "post_list_service_bindings" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_tls_routes_with_metadata", + "post_list_service_bindings_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_tls_routes" + transports.NetworkServicesRestInterceptor, "pre_list_service_bindings" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = tls_route.ListTlsRoutesRequest.pb(tls_route.ListTlsRoutesRequest()) + pb_message = service_binding.ListServiceBindingsRequest.pb( + service_binding.ListServiceBindingsRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -44880,21 +49074,24 @@ def test_list_tls_routes_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = tls_route.ListTlsRoutesResponse.to_json( - tls_route.ListTlsRoutesResponse() + return_value = service_binding.ListServiceBindingsResponse.to_json( + service_binding.ListServiceBindingsResponse() ) req.return_value.content = return_value - request = tls_route.ListTlsRoutesRequest() + request = service_binding.ListServiceBindingsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = tls_route.ListTlsRoutesResponse() - post_with_metadata.return_value = tls_route.ListTlsRoutesResponse(), metadata + post.return_value = service_binding.ListServiceBindingsResponse() + post_with_metadata.return_value = ( + service_binding.ListServiceBindingsResponse(), + metadata, + ) - client.list_tls_routes( + client.list_service_bindings( request, metadata=[ ("key", "val"), @@ -44907,12 +49104,16 @@ def test_list_tls_routes_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_tls_route_rest_bad_request(request_type=tls_route.GetTlsRouteRequest): +def test_get_service_binding_rest_bad_request( + request_type=service_binding.GetServiceBindingRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/serviceBindings/sample3" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -44928,34 +49129,35 @@ def test_get_tls_route_rest_bad_request(request_type=tls_route.GetTlsRouteReques response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_tls_route(request) + client.get_service_binding(request) @pytest.mark.parametrize( "request_type", [ - tls_route.GetTlsRouteRequest, + service_binding.GetServiceBindingRequest, dict, ], ) -def test_get_tls_route_rest_call_success(request_type): +def test_get_service_binding_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/serviceBindings/sample3" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = tls_route.TlsRoute( + return_value = service_binding.ServiceBinding( name="name_value", - self_link="self_link_value", description="description_value", - meshes=["meshes_value"], - gateways=["gateways_value"], + service="service_value", + service_id="service_id_value", ) # Wrap the value into a proper Response obj @@ -44963,24 +49165,23 @@ def test_get_tls_route_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = tls_route.TlsRoute.pb(return_value) + return_value = service_binding.ServiceBinding.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_tls_route(request) + response = client.get_service_binding(request) # Establish that the response is the type that we expect. - assert isinstance(response, tls_route.TlsRoute) + assert isinstance(response, service_binding.ServiceBinding) assert response.name == "name_value" - assert response.self_link == "self_link_value" assert response.description == "description_value" - assert response.meshes == ["meshes_value"] - assert response.gateways == ["gateways_value"] + assert response.service == "service_value" + assert response.service_id == "service_id_value" @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_tls_route_rest_interceptors(null_interceptor): +def test_get_service_binding_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -44993,20 +49194,22 @@ def test_get_tls_route_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_tls_route" + transports.NetworkServicesRestInterceptor, "post_get_service_binding" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_get_tls_route_with_metadata", + "post_get_service_binding_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_tls_route" + transports.NetworkServicesRestInterceptor, "pre_get_service_binding" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = tls_route.GetTlsRouteRequest.pb(tls_route.GetTlsRouteRequest()) + pb_message = service_binding.GetServiceBindingRequest.pb( + service_binding.GetServiceBindingRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -45017,19 +49220,21 @@ def test_get_tls_route_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = tls_route.TlsRoute.to_json(tls_route.TlsRoute()) + return_value = service_binding.ServiceBinding.to_json( + service_binding.ServiceBinding() + ) req.return_value.content = return_value - request = tls_route.GetTlsRouteRequest() + request = service_binding.GetServiceBindingRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = tls_route.TlsRoute() - post_with_metadata.return_value = tls_route.TlsRoute(), metadata + post.return_value = service_binding.ServiceBinding() + post_with_metadata.return_value = service_binding.ServiceBinding(), metadata - client.get_tls_route( + client.get_service_binding( request, metadata=[ ("key", "val"), @@ -45042,8 +49247,8 @@ def test_get_tls_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_tls_route_rest_bad_request( - request_type=gcn_tls_route.CreateTlsRouteRequest, +def test_create_service_binding_rest_bad_request( + request_type=gcn_service_binding.CreateServiceBindingRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" @@ -45065,47 +49270,30 @@ def test_create_tls_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_tls_route(request) + client.create_service_binding(request) @pytest.mark.parametrize( "request_type", [ - gcn_tls_route.CreateTlsRouteRequest, + gcn_service_binding.CreateServiceBindingRequest, dict, ], ) -def test_create_tls_route_rest_call_success(request_type): +def test_create_service_binding_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["tls_route"] = { + request_init["service_binding"] = { "name": "name_value", - "self_link": "self_link_value", + "description": "description_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "description": "description_value", - "rules": [ - { - "matches": [ - { - "sni_host": ["sni_host_value1", "sni_host_value2"], - "alpn": ["alpn_value1", "alpn_value2"], - } - ], - "action": { - "destinations": [ - {"service_name": "service_name_value", "weight": 648} - ], - "idle_timeout": {"seconds": 751, "nanos": 543}, - }, - } - ], - "meshes": ["meshes_value1", "meshes_value2"], - "gateways": ["gateways_value1", "gateways_value2"], + "service": "service_value", + "service_id": "service_id_value", "labels": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. @@ -45113,7 +49301,9 @@ def test_create_tls_route_rest_call_success(request_type): # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_tls_route.CreateTlsRouteRequest.meta.fields["tls_route"] + test_field = gcn_service_binding.CreateServiceBindingRequest.meta.fields[ + "service_binding" + ] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -45141,7 +49331,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["tls_route"].items(): # pragma: NO COVER + for field, value in request_init["service_binding"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -45171,10 +49361,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["tls_route"][field])): - del request_init["tls_route"][field][i][subfield] + for i in range(0, len(request_init["service_binding"][field])): + del request_init["service_binding"][field][i][subfield] else: - del request_init["tls_route"][field][subfield] + del request_init["service_binding"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -45189,14 +49379,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_tls_route(request) + response = client.create_service_binding(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_tls_route_rest_interceptors(null_interceptor): +def test_create_service_binding_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -45210,21 +49400,21 @@ def test_create_tls_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_tls_route" + transports.NetworkServicesRestInterceptor, "post_create_service_binding" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_create_tls_route_with_metadata", + "post_create_service_binding_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_tls_route" + transports.NetworkServicesRestInterceptor, "pre_create_service_binding" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_tls_route.CreateTlsRouteRequest.pb( - gcn_tls_route.CreateTlsRouteRequest() + pb_message = gcn_service_binding.CreateServiceBindingRequest.pb( + gcn_service_binding.CreateServiceBindingRequest() ) transcode.return_value = { "method": "post", @@ -45239,7 +49429,7 @@ def test_create_tls_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_tls_route.CreateTlsRouteRequest() + request = gcn_service_binding.CreateServiceBindingRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -45248,7 +49438,7 @@ def test_create_tls_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_tls_route( + client.create_service_binding( request, metadata=[ ("key", "val"), @@ -45261,15 +49451,17 @@ def test_create_tls_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_tls_route_rest_bad_request( - request_type=gcn_tls_route.UpdateTlsRouteRequest, +def test_update_service_binding_rest_bad_request( + request_type=gcn_service_binding.UpdateServiceBindingRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "tls_route": {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} + "service_binding": { + "name": "projects/sample1/locations/sample2/serviceBindings/sample3" + } } request = request_type(**request_init) @@ -45286,49 +49478,34 @@ def test_update_tls_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_tls_route(request) + client.update_service_binding(request) @pytest.mark.parametrize( "request_type", [ - gcn_tls_route.UpdateTlsRouteRequest, + gcn_service_binding.UpdateServiceBindingRequest, dict, ], ) -def test_update_tls_route_rest_call_success(request_type): +def test_update_service_binding_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "tls_route": {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} + "service_binding": { + "name": "projects/sample1/locations/sample2/serviceBindings/sample3" + } } - request_init["tls_route"] = { - "name": "projects/sample1/locations/sample2/tlsRoutes/sample3", - "self_link": "self_link_value", + request_init["service_binding"] = { + "name": "projects/sample1/locations/sample2/serviceBindings/sample3", + "description": "description_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "description": "description_value", - "rules": [ - { - "matches": [ - { - "sni_host": ["sni_host_value1", "sni_host_value2"], - "alpn": ["alpn_value1", "alpn_value2"], - } - ], - "action": { - "destinations": [ - {"service_name": "service_name_value", "weight": 648} - ], - "idle_timeout": {"seconds": 751, "nanos": 543}, - }, - } - ], - "meshes": ["meshes_value1", "meshes_value2"], - "gateways": ["gateways_value1", "gateways_value2"], + "service": "service_value", + "service_id": "service_id_value", "labels": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. @@ -45336,7 +49513,9 @@ def test_update_tls_route_rest_call_success(request_type): # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_tls_route.UpdateTlsRouteRequest.meta.fields["tls_route"] + test_field = gcn_service_binding.UpdateServiceBindingRequest.meta.fields[ + "service_binding" + ] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -45364,7 +49543,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["tls_route"].items(): # pragma: NO COVER + for field, value in request_init["service_binding"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -45394,10 +49573,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["tls_route"][field])): - del request_init["tls_route"][field][i][subfield] + for i in range(0, len(request_init["service_binding"][field])): + del request_init["service_binding"][field][i][subfield] else: - del request_init["tls_route"][field][subfield] + del request_init["service_binding"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -45412,14 +49591,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_tls_route(request) + response = client.update_service_binding(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_tls_route_rest_interceptors(null_interceptor): +def test_update_service_binding_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -45433,21 +49612,21 @@ def test_update_tls_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_tls_route" + transports.NetworkServicesRestInterceptor, "post_update_service_binding" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_update_tls_route_with_metadata", + "post_update_service_binding_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_tls_route" + transports.NetworkServicesRestInterceptor, "pre_update_service_binding" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_tls_route.UpdateTlsRouteRequest.pb( - gcn_tls_route.UpdateTlsRouteRequest() + pb_message = gcn_service_binding.UpdateServiceBindingRequest.pb( + gcn_service_binding.UpdateServiceBindingRequest() ) transcode.return_value = { "method": "post", @@ -45462,7 +49641,7 @@ def test_update_tls_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_tls_route.UpdateTlsRouteRequest() + request = gcn_service_binding.UpdateServiceBindingRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -45471,7 +49650,7 @@ def test_update_tls_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.update_tls_route( + client.update_service_binding( request, metadata=[ ("key", "val"), @@ -45484,14 +49663,16 @@ def test_update_tls_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_tls_route_rest_bad_request( - request_type=tls_route.DeleteTlsRouteRequest, +def test_delete_service_binding_rest_bad_request( + request_type=service_binding.DeleteServiceBindingRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/serviceBindings/sample3" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -45507,23 +49688,25 @@ def test_delete_tls_route_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_tls_route(request) + client.delete_service_binding(request) @pytest.mark.parametrize( "request_type", [ - tls_route.DeleteTlsRouteRequest, + service_binding.DeleteServiceBindingRequest, dict, ], ) -def test_delete_tls_route_rest_call_success(request_type): +def test_delete_service_binding_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/tlsRoutes/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/serviceBindings/sample3" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -45538,14 +49721,14 @@ def test_delete_tls_route_rest_call_success(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_tls_route(request) + response = client.delete_service_binding(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_tls_route_rest_interceptors(null_interceptor): +def test_delete_service_binding_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -45559,21 +49742,21 @@ def test_delete_tls_route_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_tls_route" + transports.NetworkServicesRestInterceptor, "post_delete_service_binding" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_delete_tls_route_with_metadata", + "post_delete_service_binding_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_tls_route" + transports.NetworkServicesRestInterceptor, "pre_delete_service_binding" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = tls_route.DeleteTlsRouteRequest.pb( - tls_route.DeleteTlsRouteRequest() + pb_message = service_binding.DeleteServiceBindingRequest.pb( + service_binding.DeleteServiceBindingRequest() ) transcode.return_value = { "method": "post", @@ -45588,7 +49771,7 @@ def test_delete_tls_route_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = tls_route.DeleteTlsRouteRequest() + request = service_binding.DeleteServiceBindingRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -45597,7 +49780,7 @@ def test_delete_tls_route_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.delete_tls_route( + client.delete_service_binding( request, metadata=[ ("key", "val"), @@ -45610,9 +49793,7 @@ def test_delete_tls_route_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_service_bindings_rest_bad_request( - request_type=service_binding.ListServiceBindingsRequest, -): +def test_list_meshes_rest_bad_request(request_type=mesh.ListMeshesRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -45633,17 +49814,17 @@ def test_list_service_bindings_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_service_bindings(request) + client.list_meshes(request) @pytest.mark.parametrize( "request_type", [ - service_binding.ListServiceBindingsRequest, + mesh.ListMeshesRequest, dict, ], ) -def test_list_service_bindings_rest_call_success(request_type): +def test_list_meshes_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -45655,7 +49836,7 @@ def test_list_service_bindings_rest_call_success(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service_binding.ListServiceBindingsResponse( + return_value = mesh.ListMeshesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) @@ -45665,21 +49846,21 @@ def test_list_service_bindings_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = service_binding.ListServiceBindingsResponse.pb(return_value) + return_value = mesh.ListMeshesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_service_bindings(request) + response = client.list_meshes(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListServiceBindingsPager) + assert isinstance(response, pagers.ListMeshesPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_service_bindings_rest_interceptors(null_interceptor): +def test_list_meshes_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -45692,22 +49873,19 @@ def test_list_service_bindings_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_service_bindings" + transports.NetworkServicesRestInterceptor, "post_list_meshes" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, - "post_list_service_bindings_with_metadata", + transports.NetworkServicesRestInterceptor, "post_list_meshes_with_metadata" ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_service_bindings" + transports.NetworkServicesRestInterceptor, "pre_list_meshes" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = service_binding.ListServiceBindingsRequest.pb( - service_binding.ListServiceBindingsRequest() - ) + pb_message = mesh.ListMeshesRequest.pb(mesh.ListMeshesRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -45718,24 +49896,19 @@ def test_list_service_bindings_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = service_binding.ListServiceBindingsResponse.to_json( - service_binding.ListServiceBindingsResponse() - ) + return_value = mesh.ListMeshesResponse.to_json(mesh.ListMeshesResponse()) req.return_value.content = return_value - request = service_binding.ListServiceBindingsRequest() + request = mesh.ListMeshesRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = service_binding.ListServiceBindingsResponse() - post_with_metadata.return_value = ( - service_binding.ListServiceBindingsResponse(), - metadata, - ) + post.return_value = mesh.ListMeshesResponse() + post_with_metadata.return_value = mesh.ListMeshesResponse(), metadata - client.list_service_bindings( + client.list_meshes( request, metadata=[ ("key", "val"), @@ -45748,16 +49921,12 @@ def test_list_service_bindings_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_service_binding_rest_bad_request( - request_type=service_binding.GetServiceBindingRequest, -): +def test_get_mesh_rest_bad_request(request_type=mesh.GetMeshRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3" - } + request_init = {"name": "projects/sample1/locations/sample2/meshes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -45773,35 +49942,34 @@ def test_get_service_binding_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_service_binding(request) + client.get_mesh(request) @pytest.mark.parametrize( "request_type", [ - service_binding.GetServiceBindingRequest, + mesh.GetMeshRequest, dict, ], ) -def test_get_service_binding_rest_call_success(request_type): +def test_get_mesh_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3" - } + request_init = {"name": "projects/sample1/locations/sample2/meshes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service_binding.ServiceBinding( + return_value = mesh.Mesh( name="name_value", + self_link="self_link_value", description="description_value", - service="service_value", - service_id="service_id_value", + interception_port=1848, + envoy_headers=common.EnvoyHeaders.NONE, ) # Wrap the value into a proper Response obj @@ -45809,23 +49977,24 @@ def test_get_service_binding_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = service_binding.ServiceBinding.pb(return_value) + return_value = mesh.Mesh.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_service_binding(request) + response = client.get_mesh(request) # Establish that the response is the type that we expect. - assert isinstance(response, service_binding.ServiceBinding) + assert isinstance(response, mesh.Mesh) assert response.name == "name_value" + assert response.self_link == "self_link_value" assert response.description == "description_value" - assert response.service == "service_value" - assert response.service_id == "service_id_value" + assert response.interception_port == 1848 + assert response.envoy_headers == common.EnvoyHeaders.NONE @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_service_binding_rest_interceptors(null_interceptor): +def test_get_mesh_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -45838,22 +50007,19 @@ def test_get_service_binding_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_service_binding" + transports.NetworkServicesRestInterceptor, "post_get_mesh" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, - "post_get_service_binding_with_metadata", + transports.NetworkServicesRestInterceptor, "post_get_mesh_with_metadata" ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_service_binding" + transports.NetworkServicesRestInterceptor, "pre_get_mesh" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = service_binding.GetServiceBindingRequest.pb( - service_binding.GetServiceBindingRequest() - ) + pb_message = mesh.GetMeshRequest.pb(mesh.GetMeshRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -45864,21 +50030,19 @@ def test_get_service_binding_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = service_binding.ServiceBinding.to_json( - service_binding.ServiceBinding() - ) + return_value = mesh.Mesh.to_json(mesh.Mesh()) req.return_value.content = return_value - request = service_binding.GetServiceBindingRequest() + request = mesh.GetMeshRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = service_binding.ServiceBinding() - post_with_metadata.return_value = service_binding.ServiceBinding(), metadata + post.return_value = mesh.Mesh() + post_with_metadata.return_value = mesh.Mesh(), metadata - client.get_service_binding( + client.get_mesh( request, metadata=[ ("key", "val"), @@ -45891,9 +50055,7 @@ def test_get_service_binding_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_service_binding_rest_bad_request( - request_type=gcn_service_binding.CreateServiceBindingRequest, -): +def test_create_mesh_rest_bad_request(request_type=gcn_mesh.CreateMeshRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -45914,40 +50076,39 @@ def test_create_service_binding_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_service_binding(request) + client.create_mesh(request) @pytest.mark.parametrize( "request_type", [ - gcn_service_binding.CreateServiceBindingRequest, + gcn_mesh.CreateMeshRequest, dict, ], ) -def test_create_service_binding_rest_call_success(request_type): +def test_create_mesh_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["service_binding"] = { + request_init["mesh"] = { "name": "name_value", - "description": "description_value", + "self_link": "self_link_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "service": "service_value", - "service_id": "service_id_value", "labels": {}, + "description": "description_value", + "interception_port": 1848, + "envoy_headers": 1, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_service_binding.CreateServiceBindingRequest.meta.fields[ - "service_binding" - ] + test_field = gcn_mesh.CreateMeshRequest.meta.fields["mesh"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -45975,7 +50136,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["service_binding"].items(): # pragma: NO COVER + for field, value in request_init["mesh"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -46005,10 +50166,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["service_binding"][field])): - del request_init["service_binding"][field][i][subfield] + for i in range(0, len(request_init["mesh"][field])): + del request_init["mesh"][field][i][subfield] else: - del request_init["service_binding"][field][subfield] + del request_init["mesh"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -46023,14 +50184,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_service_binding(request) + response = client.create_mesh(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_service_binding_rest_interceptors(null_interceptor): +def test_create_mesh_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -46044,22 +50205,19 @@ def test_create_service_binding_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_service_binding" + transports.NetworkServicesRestInterceptor, "post_create_mesh" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, - "post_create_service_binding_with_metadata", + transports.NetworkServicesRestInterceptor, "post_create_mesh_with_metadata" ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_service_binding" + transports.NetworkServicesRestInterceptor, "pre_create_mesh" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_service_binding.CreateServiceBindingRequest.pb( - gcn_service_binding.CreateServiceBindingRequest() - ) + pb_message = gcn_mesh.CreateMeshRequest.pb(gcn_mesh.CreateMeshRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -46073,7 +50231,7 @@ def test_create_service_binding_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_service_binding.CreateServiceBindingRequest() + request = gcn_mesh.CreateMeshRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -46082,7 +50240,7 @@ def test_create_service_binding_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_service_binding( + client.create_mesh( request, metadata=[ ("key", "val"), @@ -46095,17 +50253,13 @@ def test_create_service_binding_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_service_binding_rest_bad_request( - request_type=gcn_service_binding.UpdateServiceBindingRequest, -): +def test_update_mesh_rest_bad_request(request_type=gcn_mesh.UpdateMeshRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "service_binding": { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3" - } + "mesh": {"name": "projects/sample1/locations/sample2/meshes/sample3"} } request = request_type(**request_init) @@ -46122,44 +50276,41 @@ def test_update_service_binding_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_service_binding(request) + client.update_mesh(request) @pytest.mark.parametrize( "request_type", [ - gcn_service_binding.UpdateServiceBindingRequest, + gcn_mesh.UpdateMeshRequest, dict, ], ) -def test_update_service_binding_rest_call_success(request_type): +def test_update_mesh_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "service_binding": { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3" - } + "mesh": {"name": "projects/sample1/locations/sample2/meshes/sample3"} } - request_init["service_binding"] = { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3", - "description": "description_value", + request_init["mesh"] = { + "name": "projects/sample1/locations/sample2/meshes/sample3", + "self_link": "self_link_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, - "service": "service_value", - "service_id": "service_id_value", "labels": {}, + "description": "description_value", + "interception_port": 1848, + "envoy_headers": 1, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_service_binding.UpdateServiceBindingRequest.meta.fields[ - "service_binding" - ] + test_field = gcn_mesh.UpdateMeshRequest.meta.fields["mesh"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -46187,7 +50338,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["service_binding"].items(): # pragma: NO COVER + for field, value in request_init["mesh"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -46217,10 +50368,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["service_binding"][field])): - del request_init["service_binding"][field][i][subfield] + for i in range(0, len(request_init["mesh"][field])): + del request_init["mesh"][field][i][subfield] else: - del request_init["service_binding"][field][subfield] + del request_init["mesh"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -46235,14 +50386,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_service_binding(request) + response = client.update_mesh(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_service_binding_rest_interceptors(null_interceptor): +def test_update_mesh_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -46256,22 +50407,19 @@ def test_update_service_binding_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_service_binding" + transports.NetworkServicesRestInterceptor, "post_update_mesh" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, - "post_update_service_binding_with_metadata", + transports.NetworkServicesRestInterceptor, "post_update_mesh_with_metadata" ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_service_binding" + transports.NetworkServicesRestInterceptor, "pre_update_mesh" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_service_binding.UpdateServiceBindingRequest.pb( - gcn_service_binding.UpdateServiceBindingRequest() - ) + pb_message = gcn_mesh.UpdateMeshRequest.pb(gcn_mesh.UpdateMeshRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -46285,7 +50433,7 @@ def test_update_service_binding_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_service_binding.UpdateServiceBindingRequest() + request = gcn_mesh.UpdateMeshRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -46294,7 +50442,7 @@ def test_update_service_binding_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.update_service_binding( + client.update_mesh( request, metadata=[ ("key", "val"), @@ -46307,16 +50455,12 @@ def test_update_service_binding_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_service_binding_rest_bad_request( - request_type=service_binding.DeleteServiceBindingRequest, -): +def test_delete_mesh_rest_bad_request(request_type=mesh.DeleteMeshRequest): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3" - } + request_init = {"name": "projects/sample1/locations/sample2/meshes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -46332,25 +50476,23 @@ def test_delete_service_binding_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_service_binding(request) + client.delete_mesh(request) @pytest.mark.parametrize( "request_type", [ - service_binding.DeleteServiceBindingRequest, + mesh.DeleteMeshRequest, dict, ], ) -def test_delete_service_binding_rest_call_success(request_type): +def test_delete_mesh_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/serviceBindings/sample3" - } + request_init = {"name": "projects/sample1/locations/sample2/meshes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -46365,14 +50507,14 @@ def test_delete_service_binding_rest_call_success(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_service_binding(request) + response = client.delete_mesh(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_service_binding_rest_interceptors(null_interceptor): +def test_delete_mesh_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -46386,22 +50528,19 @@ def test_delete_service_binding_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_service_binding" + transports.NetworkServicesRestInterceptor, "post_delete_mesh" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, - "post_delete_service_binding_with_metadata", + transports.NetworkServicesRestInterceptor, "post_delete_mesh_with_metadata" ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_service_binding" + transports.NetworkServicesRestInterceptor, "pre_delete_mesh" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = service_binding.DeleteServiceBindingRequest.pb( - service_binding.DeleteServiceBindingRequest() - ) + pb_message = mesh.DeleteMeshRequest.pb(mesh.DeleteMeshRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -46415,7 +50554,7 @@ def test_delete_service_binding_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = service_binding.DeleteServiceBindingRequest() + request = mesh.DeleteMeshRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -46424,7 +50563,7 @@ def test_delete_service_binding_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.delete_service_binding( + client.delete_mesh( request, metadata=[ ("key", "val"), @@ -46437,7 +50576,9 @@ def test_delete_service_binding_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_meshes_rest_bad_request(request_type=mesh.ListMeshesRequest): +def test_list_service_lb_policies_rest_bad_request( + request_type=service_lb_policy.ListServiceLbPoliciesRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -46458,17 +50599,17 @@ def test_list_meshes_rest_bad_request(request_type=mesh.ListMeshesRequest): response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_meshes(request) + client.list_service_lb_policies(request) @pytest.mark.parametrize( "request_type", [ - mesh.ListMeshesRequest, + service_lb_policy.ListServiceLbPoliciesRequest, dict, ], ) -def test_list_meshes_rest_call_success(request_type): +def test_list_service_lb_policies_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -46480,7 +50621,7 @@ def test_list_meshes_rest_call_success(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = mesh.ListMeshesResponse( + return_value = service_lb_policy.ListServiceLbPoliciesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) @@ -46490,21 +50631,21 @@ def test_list_meshes_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = mesh.ListMeshesResponse.pb(return_value) + return_value = service_lb_policy.ListServiceLbPoliciesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_meshes(request) + response = client.list_service_lb_policies(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListMeshesPager) + assert isinstance(response, pagers.ListServiceLbPoliciesPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_meshes_rest_interceptors(null_interceptor): +def test_list_service_lb_policies_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -46517,19 +50658,22 @@ def test_list_meshes_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_meshes" + transports.NetworkServicesRestInterceptor, "post_list_service_lb_policies" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_meshes_with_metadata" + transports.NetworkServicesRestInterceptor, + "post_list_service_lb_policies_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_meshes" + transports.NetworkServicesRestInterceptor, "pre_list_service_lb_policies" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = mesh.ListMeshesRequest.pb(mesh.ListMeshesRequest()) + pb_message = service_lb_policy.ListServiceLbPoliciesRequest.pb( + service_lb_policy.ListServiceLbPoliciesRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -46540,19 +50684,24 @@ def test_list_meshes_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = mesh.ListMeshesResponse.to_json(mesh.ListMeshesResponse()) + return_value = service_lb_policy.ListServiceLbPoliciesResponse.to_json( + service_lb_policy.ListServiceLbPoliciesResponse() + ) req.return_value.content = return_value - request = mesh.ListMeshesRequest() + request = service_lb_policy.ListServiceLbPoliciesRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = mesh.ListMeshesResponse() - post_with_metadata.return_value = mesh.ListMeshesResponse(), metadata + post.return_value = service_lb_policy.ListServiceLbPoliciesResponse() + post_with_metadata.return_value = ( + service_lb_policy.ListServiceLbPoliciesResponse(), + metadata, + ) - client.list_meshes( + client.list_service_lb_policies( request, metadata=[ ("key", "val"), @@ -46565,12 +50714,16 @@ def test_list_meshes_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_mesh_rest_bad_request(request_type=mesh.GetMeshRequest): +def test_get_service_lb_policy_rest_bad_request( + request_type=service_lb_policy.GetServiceLbPolicyRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/meshes/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -46586,34 +50739,34 @@ def test_get_mesh_rest_bad_request(request_type=mesh.GetMeshRequest): response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_mesh(request) + client.get_service_lb_policy(request) @pytest.mark.parametrize( "request_type", [ - mesh.GetMeshRequest, + service_lb_policy.GetServiceLbPolicyRequest, dict, ], ) -def test_get_mesh_rest_call_success(request_type): +def test_get_service_lb_policy_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/meshes/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = mesh.Mesh( + return_value = service_lb_policy.ServiceLbPolicy( name="name_value", - self_link="self_link_value", description="description_value", - interception_port=1848, - envoy_headers=common.EnvoyHeaders.NONE, + load_balancing_algorithm=service_lb_policy.ServiceLbPolicy.LoadBalancingAlgorithm.SPRAY_TO_WORLD, ) # Wrap the value into a proper Response obj @@ -46621,24 +50774,25 @@ def test_get_mesh_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = mesh.Mesh.pb(return_value) + return_value = service_lb_policy.ServiceLbPolicy.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_mesh(request) + response = client.get_service_lb_policy(request) # Establish that the response is the type that we expect. - assert isinstance(response, mesh.Mesh) + assert isinstance(response, service_lb_policy.ServiceLbPolicy) assert response.name == "name_value" - assert response.self_link == "self_link_value" assert response.description == "description_value" - assert response.interception_port == 1848 - assert response.envoy_headers == common.EnvoyHeaders.NONE + assert ( + response.load_balancing_algorithm + == service_lb_policy.ServiceLbPolicy.LoadBalancingAlgorithm.SPRAY_TO_WORLD + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_mesh_rest_interceptors(null_interceptor): +def test_get_service_lb_policy_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -46651,19 +50805,22 @@ def test_get_mesh_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_mesh" + transports.NetworkServicesRestInterceptor, "post_get_service_lb_policy" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_mesh_with_metadata" + transports.NetworkServicesRestInterceptor, + "post_get_service_lb_policy_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_mesh" + transports.NetworkServicesRestInterceptor, "pre_get_service_lb_policy" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = mesh.GetMeshRequest.pb(mesh.GetMeshRequest()) + pb_message = service_lb_policy.GetServiceLbPolicyRequest.pb( + service_lb_policy.GetServiceLbPolicyRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -46674,19 +50831,21 @@ def test_get_mesh_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = mesh.Mesh.to_json(mesh.Mesh()) + return_value = service_lb_policy.ServiceLbPolicy.to_json( + service_lb_policy.ServiceLbPolicy() + ) req.return_value.content = return_value - request = mesh.GetMeshRequest() + request = service_lb_policy.GetServiceLbPolicyRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = mesh.Mesh() - post_with_metadata.return_value = mesh.Mesh(), metadata + post.return_value = service_lb_policy.ServiceLbPolicy() + post_with_metadata.return_value = service_lb_policy.ServiceLbPolicy(), metadata - client.get_mesh( + client.get_service_lb_policy( request, metadata=[ ("key", "val"), @@ -46699,7 +50858,9 @@ def test_get_mesh_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_mesh_rest_bad_request(request_type=gcn_mesh.CreateMeshRequest): +def test_create_service_lb_policy_rest_bad_request( + request_type=gcn_service_lb_policy.CreateServiceLbPolicyRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -46720,39 +50881,42 @@ def test_create_mesh_rest_bad_request(request_type=gcn_mesh.CreateMeshRequest): response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_mesh(request) + client.create_service_lb_policy(request) @pytest.mark.parametrize( "request_type", [ - gcn_mesh.CreateMeshRequest, + gcn_service_lb_policy.CreateServiceLbPolicyRequest, dict, ], ) -def test_create_mesh_rest_call_success(request_type): +def test_create_service_lb_policy_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["mesh"] = { + request_init["service_lb_policy"] = { "name": "name_value", - "self_link": "self_link_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, "labels": {}, "description": "description_value", - "interception_port": 1848, - "envoy_headers": 1, + "load_balancing_algorithm": 3, + "auto_capacity_drain": {"enable": True}, + "failover_config": {"failover_health_threshold": 2649}, + "isolation_config": {"isolation_granularity": 1, "isolation_mode": 1}, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_mesh.CreateMeshRequest.meta.fields["mesh"] + test_field = gcn_service_lb_policy.CreateServiceLbPolicyRequest.meta.fields[ + "service_lb_policy" + ] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -46780,7 +50944,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["mesh"].items(): # pragma: NO COVER + for field, value in request_init["service_lb_policy"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -46810,10 +50974,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["mesh"][field])): - del request_init["mesh"][field][i][subfield] + for i in range(0, len(request_init["service_lb_policy"][field])): + del request_init["service_lb_policy"][field][i][subfield] else: - del request_init["mesh"][field][subfield] + del request_init["service_lb_policy"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -46828,14 +50992,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_mesh(request) + response = client.create_service_lb_policy(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_mesh_rest_interceptors(null_interceptor): +def test_create_service_lb_policy_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -46849,19 +51013,22 @@ def test_create_mesh_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_mesh" + transports.NetworkServicesRestInterceptor, "post_create_service_lb_policy" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_mesh_with_metadata" + transports.NetworkServicesRestInterceptor, + "post_create_service_lb_policy_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_mesh" + transports.NetworkServicesRestInterceptor, "pre_create_service_lb_policy" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_mesh.CreateMeshRequest.pb(gcn_mesh.CreateMeshRequest()) + pb_message = gcn_service_lb_policy.CreateServiceLbPolicyRequest.pb( + gcn_service_lb_policy.CreateServiceLbPolicyRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -46875,7 +51042,7 @@ def test_create_mesh_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_mesh.CreateMeshRequest() + request = gcn_service_lb_policy.CreateServiceLbPolicyRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -46884,7 +51051,7 @@ def test_create_mesh_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.create_mesh( + client.create_service_lb_policy( request, metadata=[ ("key", "val"), @@ -46897,13 +51064,17 @@ def test_create_mesh_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_mesh_rest_bad_request(request_type=gcn_mesh.UpdateMeshRequest): +def test_update_service_lb_policy_rest_bad_request( + request_type=gcn_service_lb_policy.UpdateServiceLbPolicyRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "mesh": {"name": "projects/sample1/locations/sample2/meshes/sample3"} + "service_lb_policy": { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + } } request = request_type(**request_init) @@ -46920,41 +51091,46 @@ def test_update_mesh_rest_bad_request(request_type=gcn_mesh.UpdateMeshRequest): response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_mesh(request) + client.update_service_lb_policy(request) @pytest.mark.parametrize( "request_type", [ - gcn_mesh.UpdateMeshRequest, + gcn_service_lb_policy.UpdateServiceLbPolicyRequest, dict, ], ) -def test_update_mesh_rest_call_success(request_type): +def test_update_service_lb_policy_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "mesh": {"name": "projects/sample1/locations/sample2/meshes/sample3"} + "service_lb_policy": { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + } } - request_init["mesh"] = { - "name": "projects/sample1/locations/sample2/meshes/sample3", - "self_link": "self_link_value", + request_init["service_lb_policy"] = { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, "labels": {}, "description": "description_value", - "interception_port": 1848, - "envoy_headers": 1, + "load_balancing_algorithm": 3, + "auto_capacity_drain": {"enable": True}, + "failover_config": {"failover_health_threshold": 2649}, + "isolation_config": {"isolation_granularity": 1, "isolation_mode": 1}, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = gcn_mesh.UpdateMeshRequest.meta.fields["mesh"] + test_field = gcn_service_lb_policy.UpdateServiceLbPolicyRequest.meta.fields[ + "service_lb_policy" + ] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -46982,7 +51158,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["mesh"].items(): # pragma: NO COVER + for field, value in request_init["service_lb_policy"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -47012,10 +51188,10 @@ def get_message_fields(field): subfield = subfield_to_delete.get("subfield") if subfield: if field_repeated: - for i in range(0, len(request_init["mesh"][field])): - del request_init["mesh"][field][i][subfield] + for i in range(0, len(request_init["service_lb_policy"][field])): + del request_init["service_lb_policy"][field][i][subfield] else: - del request_init["mesh"][field][subfield] + del request_init["service_lb_policy"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -47030,14 +51206,14 @@ def get_message_fields(field): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_mesh(request) + response = client.update_service_lb_policy(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_mesh_rest_interceptors(null_interceptor): +def test_update_service_lb_policy_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -47051,19 +51227,22 @@ def test_update_mesh_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_mesh" + transports.NetworkServicesRestInterceptor, "post_update_service_lb_policy" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_mesh_with_metadata" + transports.NetworkServicesRestInterceptor, + "post_update_service_lb_policy_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_mesh" + transports.NetworkServicesRestInterceptor, "pre_update_service_lb_policy" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_mesh.UpdateMeshRequest.pb(gcn_mesh.UpdateMeshRequest()) + pb_message = gcn_service_lb_policy.UpdateServiceLbPolicyRequest.pb( + gcn_service_lb_policy.UpdateServiceLbPolicyRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -47077,7 +51256,7 @@ def test_update_mesh_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = gcn_mesh.UpdateMeshRequest() + request = gcn_service_lb_policy.UpdateServiceLbPolicyRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -47086,7 +51265,7 @@ def test_update_mesh_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.update_mesh( + client.update_service_lb_policy( request, metadata=[ ("key", "val"), @@ -47099,12 +51278,16 @@ def test_update_mesh_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_mesh_rest_bad_request(request_type=mesh.DeleteMeshRequest): +def test_delete_service_lb_policy_rest_bad_request( + request_type=service_lb_policy.DeleteServiceLbPolicyRequest, +): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/meshes/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -47120,23 +51303,25 @@ def test_delete_mesh_rest_bad_request(request_type=mesh.DeleteMeshRequest): response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_mesh(request) + client.delete_service_lb_policy(request) @pytest.mark.parametrize( "request_type", [ - mesh.DeleteMeshRequest, + service_lb_policy.DeleteServiceLbPolicyRequest, dict, ], ) -def test_delete_mesh_rest_call_success(request_type): +def test_delete_service_lb_policy_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/meshes/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -47151,14 +51336,14 @@ def test_delete_mesh_rest_call_success(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_mesh(request) + response = client.delete_service_lb_policy(request) # Establish that the response is the type that we expect. json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_mesh_rest_interceptors(null_interceptor): +def test_delete_service_lb_policy_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -47172,19 +51357,22 @@ def test_delete_mesh_rest_interceptors(null_interceptor): mock.patch.object(path_template, "transcode") as transcode, mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_mesh" + transports.NetworkServicesRestInterceptor, "post_delete_service_lb_policy" ) as post, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_mesh_with_metadata" + transports.NetworkServicesRestInterceptor, + "post_delete_service_lb_policy_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_mesh" + transports.NetworkServicesRestInterceptor, "pre_delete_service_lb_policy" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = mesh.DeleteMeshRequest.pb(mesh.DeleteMeshRequest()) + pb_message = service_lb_policy.DeleteServiceLbPolicyRequest.pb( + service_lb_policy.DeleteServiceLbPolicyRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -47198,7 +51386,7 @@ def test_delete_mesh_rest_interceptors(null_interceptor): return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = mesh.DeleteMeshRequest() + request = service_lb_policy.DeleteServiceLbPolicyRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -47207,7 +51395,7 @@ def test_delete_mesh_rest_interceptors(null_interceptor): post.return_value = operations_pb2.Operation() post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.delete_mesh( + client.delete_service_lb_policy( request, metadata=[ ("key", "val"), @@ -47220,14 +51408,16 @@ def test_delete_mesh_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_service_lb_policies_rest_bad_request( - request_type=service_lb_policy.ListServiceLbPoliciesRequest, +def test_get_gateway_route_view_rest_bad_request( + request_type=route_view.GetGatewayRouteViewRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = { + "name": "projects/sample1/locations/sample2/gateways/sample3/routeViews/sample4" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -47243,31 +51433,36 @@ def test_list_service_lb_policies_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_service_lb_policies(request) + client.get_gateway_route_view(request) @pytest.mark.parametrize( "request_type", [ - service_lb_policy.ListServiceLbPoliciesRequest, + route_view.GetGatewayRouteViewRequest, dict, ], ) -def test_list_service_lb_policies_rest_call_success(request_type): +def test_get_gateway_route_view_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = { + "name": "projects/sample1/locations/sample2/gateways/sample3/routeViews/sample4" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service_lb_policy.ListServiceLbPoliciesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + return_value = route_view.GatewayRouteView( + name="name_value", + route_project_number=2157, + route_location="route_location_value", + route_type="route_type_value", + route_id="route_id_value", ) # Wrap the value into a proper Response obj @@ -47275,21 +51470,24 @@ def test_list_service_lb_policies_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = service_lb_policy.ListServiceLbPoliciesResponse.pb(return_value) + return_value = route_view.GatewayRouteView.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_service_lb_policies(request) + response = client.get_gateway_route_view(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListServiceLbPoliciesPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, route_view.GatewayRouteView) + assert response.name == "name_value" + assert response.route_project_number == 2157 + assert response.route_location == "route_location_value" + assert response.route_type == "route_type_value" + assert response.route_id == "route_id_value" @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_service_lb_policies_rest_interceptors(null_interceptor): +def test_get_gateway_route_view_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -47302,21 +51500,21 @@ def test_list_service_lb_policies_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_service_lb_policies" + transports.NetworkServicesRestInterceptor, "post_get_gateway_route_view" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_service_lb_policies_with_metadata", + "post_get_gateway_route_view_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_service_lb_policies" + transports.NetworkServicesRestInterceptor, "pre_get_gateway_route_view" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = service_lb_policy.ListServiceLbPoliciesRequest.pb( - service_lb_policy.ListServiceLbPoliciesRequest() + pb_message = route_view.GetGatewayRouteViewRequest.pb( + route_view.GetGatewayRouteViewRequest() ) transcode.return_value = { "method": "post", @@ -47328,24 +51526,21 @@ def test_list_service_lb_policies_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = service_lb_policy.ListServiceLbPoliciesResponse.to_json( - service_lb_policy.ListServiceLbPoliciesResponse() + return_value = route_view.GatewayRouteView.to_json( + route_view.GatewayRouteView() ) req.return_value.content = return_value - request = service_lb_policy.ListServiceLbPoliciesRequest() + request = route_view.GetGatewayRouteViewRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = service_lb_policy.ListServiceLbPoliciesResponse() - post_with_metadata.return_value = ( - service_lb_policy.ListServiceLbPoliciesResponse(), - metadata, - ) + post.return_value = route_view.GatewayRouteView() + post_with_metadata.return_value = route_view.GatewayRouteView(), metadata - client.list_service_lb_policies( + client.get_gateway_route_view( request, metadata=[ ("key", "val"), @@ -47358,15 +51553,15 @@ def test_list_service_lb_policies_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_service_lb_policy_rest_bad_request( - request_type=service_lb_policy.GetServiceLbPolicyRequest, +def test_get_mesh_route_view_rest_bad_request( + request_type=route_view.GetMeshRouteViewRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + "name": "projects/sample1/locations/sample2/meshes/sample3/routeViews/sample4" } request = request_type(**request_init) @@ -47383,34 +51578,36 @@ def test_get_service_lb_policy_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_service_lb_policy(request) + client.get_mesh_route_view(request) @pytest.mark.parametrize( "request_type", [ - service_lb_policy.GetServiceLbPolicyRequest, + route_view.GetMeshRouteViewRequest, dict, ], ) -def test_get_service_lb_policy_rest_call_success(request_type): +def test_get_mesh_route_view_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding request_init = { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" + "name": "projects/sample1/locations/sample2/meshes/sample3/routeViews/sample4" } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service_lb_policy.ServiceLbPolicy( + return_value = route_view.MeshRouteView( name="name_value", - description="description_value", - load_balancing_algorithm=service_lb_policy.ServiceLbPolicy.LoadBalancingAlgorithm.SPRAY_TO_WORLD, + route_project_number=2157, + route_location="route_location_value", + route_type="route_type_value", + route_id="route_id_value", ) # Wrap the value into a proper Response obj @@ -47418,25 +51615,24 @@ def test_get_service_lb_policy_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = service_lb_policy.ServiceLbPolicy.pb(return_value) + return_value = route_view.MeshRouteView.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_service_lb_policy(request) + response = client.get_mesh_route_view(request) # Establish that the response is the type that we expect. - assert isinstance(response, service_lb_policy.ServiceLbPolicy) + assert isinstance(response, route_view.MeshRouteView) assert response.name == "name_value" - assert response.description == "description_value" - assert ( - response.load_balancing_algorithm - == service_lb_policy.ServiceLbPolicy.LoadBalancingAlgorithm.SPRAY_TO_WORLD - ) + assert response.route_project_number == 2157 + assert response.route_location == "route_location_value" + assert response.route_type == "route_type_value" + assert response.route_id == "route_id_value" @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_service_lb_policy_rest_interceptors(null_interceptor): +def test_get_mesh_route_view_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -47449,21 +51645,21 @@ def test_get_service_lb_policy_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_service_lb_policy" + transports.NetworkServicesRestInterceptor, "post_get_mesh_route_view" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_get_service_lb_policy_with_metadata", + "post_get_mesh_route_view_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_service_lb_policy" + transports.NetworkServicesRestInterceptor, "pre_get_mesh_route_view" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = service_lb_policy.GetServiceLbPolicyRequest.pb( - service_lb_policy.GetServiceLbPolicyRequest() + pb_message = route_view.GetMeshRouteViewRequest.pb( + route_view.GetMeshRouteViewRequest() ) transcode.return_value = { "method": "post", @@ -47475,21 +51671,19 @@ def test_get_service_lb_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = service_lb_policy.ServiceLbPolicy.to_json( - service_lb_policy.ServiceLbPolicy() - ) + return_value = route_view.MeshRouteView.to_json(route_view.MeshRouteView()) req.return_value.content = return_value - request = service_lb_policy.GetServiceLbPolicyRequest() + request = route_view.GetMeshRouteViewRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = service_lb_policy.ServiceLbPolicy() - post_with_metadata.return_value = service_lb_policy.ServiceLbPolicy(), metadata + post.return_value = route_view.MeshRouteView() + post_with_metadata.return_value = route_view.MeshRouteView(), metadata - client.get_service_lb_policy( + client.get_mesh_route_view( request, metadata=[ ("key", "val"), @@ -47502,14 +51696,14 @@ def test_get_service_lb_policy_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_create_service_lb_policy_rest_bad_request( - request_type=gcn_service_lb_policy.CreateServiceLbPolicyRequest, +def test_list_gateway_route_views_rest_bad_request( + request_type=route_view.ListGatewayRouteViewsRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"parent": "projects/sample1/locations/sample2/gateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -47525,125 +51719,53 @@ def test_create_service_lb_policy_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_service_lb_policy(request) + client.list_gateway_route_views(request) @pytest.mark.parametrize( "request_type", [ - gcn_service_lb_policy.CreateServiceLbPolicyRequest, + route_view.ListGatewayRouteViewsRequest, dict, ], ) -def test_create_service_lb_policy_rest_call_success(request_type): +def test_list_gateway_route_views_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["service_lb_policy"] = { - "name": "name_value", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "labels": {}, - "description": "description_value", - "load_balancing_algorithm": 3, - "auto_capacity_drain": {"enable": True}, - "failover_config": {"failover_health_threshold": 2649}, - "isolation_config": {"isolation_granularity": 1, "isolation_mode": 1}, - } - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = gcn_service_lb_policy.CreateServiceLbPolicyRequest.meta.fields[ - "service_lb_policy" - ] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields - - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] - - subfields_not_in_runtime = [] - - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["service_lb_policy"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value - - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) - - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["service_lb_policy"][field])): - del request_init["service_lb_policy"][field][i][subfield] - else: - del request_init["service_lb_policy"][field][subfield] + request_init = {"parent": "projects/sample1/locations/sample2/gateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = route_view.ListGatewayRouteViewsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) # Wrap the value into a proper Response obj response_value = mock.Mock() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = route_view.ListGatewayRouteViewsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_service_lb_policy(request) + response = client.list_gateway_route_views(request) # Establish that the response is the type that we expect. - json_return_value = json_format.MessageToJson(return_value) + assert isinstance(response, pagers.ListGatewayRouteViewsPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_service_lb_policy_rest_interceptors(null_interceptor): +def test_list_gateway_route_views_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -47655,23 +51777,22 @@ def test_create_service_lb_policy_rest_interceptors(null_interceptor): with ( mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, - mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_create_service_lb_policy" + transports.NetworkServicesRestInterceptor, "post_list_gateway_route_views" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_create_service_lb_policy_with_metadata", + "post_list_gateway_route_views_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_create_service_lb_policy" + transports.NetworkServicesRestInterceptor, "pre_list_gateway_route_views" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_service_lb_policy.CreateServiceLbPolicyRequest.pb( - gcn_service_lb_policy.CreateServiceLbPolicyRequest() + pb_message = route_view.ListGatewayRouteViewsRequest.pb( + route_view.ListGatewayRouteViewsRequest() ) transcode.return_value = { "method": "post", @@ -47683,19 +51804,24 @@ def test_create_service_lb_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = json_format.MessageToJson(operations_pb2.Operation()) + return_value = route_view.ListGatewayRouteViewsResponse.to_json( + route_view.ListGatewayRouteViewsResponse() + ) req.return_value.content = return_value - request = gcn_service_lb_policy.CreateServiceLbPolicyRequest() + request = route_view.ListGatewayRouteViewsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - post_with_metadata.return_value = operations_pb2.Operation(), metadata + post.return_value = route_view.ListGatewayRouteViewsResponse() + post_with_metadata.return_value = ( + route_view.ListGatewayRouteViewsResponse(), + metadata, + ) - client.create_service_lb_policy( + client.list_gateway_route_views( request, metadata=[ ("key", "val"), @@ -47708,18 +51834,14 @@ def test_create_service_lb_policy_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_update_service_lb_policy_rest_bad_request( - request_type=gcn_service_lb_policy.UpdateServiceLbPolicyRequest, +def test_list_mesh_route_views_rest_bad_request( + request_type=route_view.ListMeshRouteViewsRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "service_lb_policy": { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" - } - } + request_init = {"parent": "projects/sample1/locations/sample2/meshes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -47735,129 +51857,53 @@ def test_update_service_lb_policy_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_service_lb_policy(request) + client.list_mesh_route_views(request) @pytest.mark.parametrize( "request_type", [ - gcn_service_lb_policy.UpdateServiceLbPolicyRequest, + route_view.ListMeshRouteViewsRequest, dict, ], ) -def test_update_service_lb_policy_rest_call_success(request_type): +def test_list_mesh_route_views_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "service_lb_policy": { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" - } - } - request_init["service_lb_policy"] = { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "labels": {}, - "description": "description_value", - "load_balancing_algorithm": 3, - "auto_capacity_drain": {"enable": True}, - "failover_config": {"failover_health_threshold": 2649}, - "isolation_config": {"isolation_granularity": 1, "isolation_mode": 1}, - } - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = gcn_service_lb_policy.UpdateServiceLbPolicyRequest.meta.fields[ - "service_lb_policy" - ] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields - - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] - - subfields_not_in_runtime = [] - - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["service_lb_policy"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value - - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) - - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["service_lb_policy"][field])): - del request_init["service_lb_policy"][field][i][subfield] - else: - del request_init["service_lb_policy"][field][subfield] + request_init = {"parent": "projects/sample1/locations/sample2/meshes/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = route_view.ListMeshRouteViewsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) # Wrap the value into a proper Response obj response_value = mock.Mock() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = route_view.ListMeshRouteViewsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_service_lb_policy(request) + response = client.list_mesh_route_views(request) # Establish that the response is the type that we expect. - json_return_value = json_format.MessageToJson(return_value) + assert isinstance(response, pagers.ListMeshRouteViewsPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_service_lb_policy_rest_interceptors(null_interceptor): +def test_list_mesh_route_views_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -47869,23 +51915,22 @@ def test_update_service_lb_policy_rest_interceptors(null_interceptor): with ( mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, - mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_update_service_lb_policy" + transports.NetworkServicesRestInterceptor, "post_list_mesh_route_views" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_update_service_lb_policy_with_metadata", + "post_list_mesh_route_views_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_update_service_lb_policy" + transports.NetworkServicesRestInterceptor, "pre_list_mesh_route_views" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = gcn_service_lb_policy.UpdateServiceLbPolicyRequest.pb( - gcn_service_lb_policy.UpdateServiceLbPolicyRequest() + pb_message = route_view.ListMeshRouteViewsRequest.pb( + route_view.ListMeshRouteViewsRequest() ) transcode.return_value = { "method": "post", @@ -47897,19 +51942,24 @@ def test_update_service_lb_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = json_format.MessageToJson(operations_pb2.Operation()) + return_value = route_view.ListMeshRouteViewsResponse.to_json( + route_view.ListMeshRouteViewsResponse() + ) req.return_value.content = return_value - request = gcn_service_lb_policy.UpdateServiceLbPolicyRequest() + request = route_view.ListMeshRouteViewsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - post_with_metadata.return_value = operations_pb2.Operation(), metadata + post.return_value = route_view.ListMeshRouteViewsResponse() + post_with_metadata.return_value = ( + route_view.ListMeshRouteViewsResponse(), + metadata, + ) - client.update_service_lb_policy( + client.list_mesh_route_views( request, metadata=[ ("key", "val"), @@ -47922,16 +51972,14 @@ def test_update_service_lb_policy_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_delete_service_lb_policy_rest_bad_request( - request_type=service_lb_policy.DeleteServiceLbPolicyRequest, +def test_list_agent_gateways_rest_bad_request( + request_type=agent_gateway.ListAgentGatewaysRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" - } + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -47947,47 +51995,53 @@ def test_delete_service_lb_policy_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_service_lb_policy(request) + client.list_agent_gateways(request) @pytest.mark.parametrize( "request_type", [ - service_lb_policy.DeleteServiceLbPolicyRequest, + agent_gateway.ListAgentGatewaysRequest, dict, ], ) -def test_delete_service_lb_policy_rest_call_success(request_type): +def test_list_agent_gateways_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/serviceLbPolicies/sample3" - } + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = agent_gateway.ListAgentGatewaysResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) # Wrap the value into a proper Response obj response_value = mock.Mock() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = agent_gateway.ListAgentGatewaysResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_service_lb_policy(request) + response = client.list_agent_gateways(request) # Establish that the response is the type that we expect. - json_return_value = json_format.MessageToJson(return_value) + assert isinstance(response, pagers.ListAgentGatewaysPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_service_lb_policy_rest_interceptors(null_interceptor): +def test_list_agent_gateways_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -47999,23 +52053,22 @@ def test_delete_service_lb_policy_rest_interceptors(null_interceptor): with ( mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, - mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_delete_service_lb_policy" + transports.NetworkServicesRestInterceptor, "post_list_agent_gateways" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_delete_service_lb_policy_with_metadata", + "post_list_agent_gateways_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_delete_service_lb_policy" + transports.NetworkServicesRestInterceptor, "pre_list_agent_gateways" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = service_lb_policy.DeleteServiceLbPolicyRequest.pb( - service_lb_policy.DeleteServiceLbPolicyRequest() + pb_message = agent_gateway.ListAgentGatewaysRequest.pb( + agent_gateway.ListAgentGatewaysRequest() ) transcode.return_value = { "method": "post", @@ -48027,19 +52080,24 @@ def test_delete_service_lb_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = json_format.MessageToJson(operations_pb2.Operation()) + return_value = agent_gateway.ListAgentGatewaysResponse.to_json( + agent_gateway.ListAgentGatewaysResponse() + ) req.return_value.content = return_value - request = service_lb_policy.DeleteServiceLbPolicyRequest() + request = agent_gateway.ListAgentGatewaysRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - post_with_metadata.return_value = operations_pb2.Operation(), metadata + post.return_value = agent_gateway.ListAgentGatewaysResponse() + post_with_metadata.return_value = ( + agent_gateway.ListAgentGatewaysResponse(), + metadata, + ) - client.delete_service_lb_policy( + client.list_agent_gateways( request, metadata=[ ("key", "val"), @@ -48052,16 +52110,14 @@ def test_delete_service_lb_policy_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_gateway_route_view_rest_bad_request( - request_type=route_view.GetGatewayRouteViewRequest, +def test_get_agent_gateway_rest_bad_request( + request_type=agent_gateway.GetAgentGatewayRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/gateways/sample3/routeViews/sample4" - } + request_init = {"name": "projects/sample1/locations/sample2/agentGateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -48077,36 +52133,34 @@ def test_get_gateway_route_view_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_gateway_route_view(request) + client.get_agent_gateway(request) @pytest.mark.parametrize( "request_type", [ - route_view.GetGatewayRouteViewRequest, + agent_gateway.GetAgentGatewayRequest, dict, ], ) -def test_get_gateway_route_view_rest_call_success(request_type): +def test_get_agent_gateway_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/gateways/sample3/routeViews/sample4" - } + request_init = {"name": "projects/sample1/locations/sample2/agentGateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = route_view.GatewayRouteView( + return_value = agent_gateway.AgentGateway( name="name_value", - route_project_number=2157, - route_location="route_location_value", - route_type="route_type_value", - route_id="route_id_value", + description="description_value", + etag="etag_value", + protocols=[agent_gateway.AgentGateway.Protocol.MCP], + registries=["registries_value"], ) # Wrap the value into a proper Response obj @@ -48114,24 +52168,24 @@ def test_get_gateway_route_view_rest_call_success(request_type): response_value.status_code = 200 # Convert return value to protobuf type - return_value = route_view.GatewayRouteView.pb(return_value) + return_value = agent_gateway.AgentGateway.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_gateway_route_view(request) + response = client.get_agent_gateway(request) # Establish that the response is the type that we expect. - assert isinstance(response, route_view.GatewayRouteView) + assert isinstance(response, agent_gateway.AgentGateway) assert response.name == "name_value" - assert response.route_project_number == 2157 - assert response.route_location == "route_location_value" - assert response.route_type == "route_type_value" - assert response.route_id == "route_id_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.protocols == [agent_gateway.AgentGateway.Protocol.MCP] + assert response.registries == ["registries_value"] @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_gateway_route_view_rest_interceptors(null_interceptor): +def test_get_agent_gateway_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -48144,21 +52198,21 @@ def test_get_gateway_route_view_rest_interceptors(null_interceptor): mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_gateway_route_view" + transports.NetworkServicesRestInterceptor, "post_get_agent_gateway" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_get_gateway_route_view_with_metadata", + "post_get_agent_gateway_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_gateway_route_view" + transports.NetworkServicesRestInterceptor, "pre_get_agent_gateway" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = route_view.GetGatewayRouteViewRequest.pb( - route_view.GetGatewayRouteViewRequest() + pb_message = agent_gateway.GetAgentGatewayRequest.pb( + agent_gateway.GetAgentGatewayRequest() ) transcode.return_value = { "method": "post", @@ -48170,21 +52224,19 @@ def test_get_gateway_route_view_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = route_view.GatewayRouteView.to_json( - route_view.GatewayRouteView() - ) + return_value = agent_gateway.AgentGateway.to_json(agent_gateway.AgentGateway()) req.return_value.content = return_value - request = route_view.GetGatewayRouteViewRequest() + request = agent_gateway.GetAgentGatewayRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = route_view.GatewayRouteView() - post_with_metadata.return_value = route_view.GatewayRouteView(), metadata + post.return_value = agent_gateway.AgentGateway() + post_with_metadata.return_value = agent_gateway.AgentGateway(), metadata - client.get_gateway_route_view( + client.get_agent_gateway( request, metadata=[ ("key", "val"), @@ -48197,16 +52249,14 @@ def test_get_gateway_route_view_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_get_mesh_route_view_rest_bad_request( - request_type=route_view.GetMeshRouteViewRequest, +def test_create_agent_gateway_rest_bad_request( + request_type=gcn_agent_gateway.CreateAgentGatewayRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/meshes/sample3/routeViews/sample4" - } + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -48222,61 +52272,150 @@ def test_get_mesh_route_view_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_mesh_route_view(request) + client.create_agent_gateway(request) @pytest.mark.parametrize( "request_type", [ - route_view.GetMeshRouteViewRequest, + gcn_agent_gateway.CreateAgentGatewayRequest, dict, ], ) -def test_get_mesh_route_view_rest_call_success(request_type): +def test_create_agent_gateway_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/meshes/sample3/routeViews/sample4" + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["agent_gateway"] = { + "google_managed": {"governed_access_path": 1}, + "self_managed": {"resource_uri": "resource_uri_value"}, + "name": "name_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "labels": {}, + "description": "description_value", + "etag": "etag_value", + "protocols": [1], + "registries": ["registries_value1", "registries_value2"], + "network_config": { + "egress": { + "network_attachment": "network_attachment_value", + "trust_config": { + "pem_certificates": [ + "pem_certificates_value1", + "pem_certificates_value2", + ] + }, + }, + "dns_peering_config": { + "domains": ["domains_value1", "domains_value2"], + "target_project": "target_project_value", + "target_network": "target_network_value", + }, + }, + "agent_gateway_card": { + "mtls_endpoint": "mtls_endpoint_value", + "root_certificates": [ + "root_certificates_value1", + "root_certificates_value2", + ], + "service_extensions_service_account": "service_extensions_service_account_value", + }, } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = gcn_agent_gateway.CreateAgentGatewayRequest.meta.fields[ + "agent_gateway" + ] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["agent_gateway"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["agent_gateway"][field])): + del request_init["agent_gateway"][field][i][subfield] + else: + del request_init["agent_gateway"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = route_view.MeshRouteView( - name="name_value", - route_project_number=2157, - route_location="route_location_value", - route_type="route_type_value", - route_id="route_id_value", - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = mock.Mock() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = route_view.MeshRouteView.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_mesh_route_view(request) + response = client.create_agent_gateway(request) # Establish that the response is the type that we expect. - assert isinstance(response, route_view.MeshRouteView) - assert response.name == "name_value" - assert response.route_project_number == 2157 - assert response.route_location == "route_location_value" - assert response.route_type == "route_type_value" - assert response.route_id == "route_id_value" + json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_mesh_route_view_rest_interceptors(null_interceptor): +def test_create_agent_gateway_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -48288,22 +52427,23 @@ def test_get_mesh_route_view_rest_interceptors(null_interceptor): with ( mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_get_mesh_route_view" + transports.NetworkServicesRestInterceptor, "post_create_agent_gateway" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_get_mesh_route_view_with_metadata", + "post_create_agent_gateway_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_get_mesh_route_view" + transports.NetworkServicesRestInterceptor, "pre_create_agent_gateway" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = route_view.GetMeshRouteViewRequest.pb( - route_view.GetMeshRouteViewRequest() + pb_message = gcn_agent_gateway.CreateAgentGatewayRequest.pb( + gcn_agent_gateway.CreateAgentGatewayRequest() ) transcode.return_value = { "method": "post", @@ -48315,19 +52455,19 @@ def test_get_mesh_route_view_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = route_view.MeshRouteView.to_json(route_view.MeshRouteView()) + return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = route_view.GetMeshRouteViewRequest() + request = gcn_agent_gateway.CreateAgentGatewayRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = route_view.MeshRouteView() - post_with_metadata.return_value = route_view.MeshRouteView(), metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.get_mesh_route_view( + client.create_agent_gateway( request, metadata=[ ("key", "val"), @@ -48340,14 +52480,18 @@ def test_get_mesh_route_view_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_gateway_route_views_rest_bad_request( - request_type=route_view.ListGatewayRouteViewsRequest, +def test_update_agent_gateway_rest_bad_request( + request_type=gcn_agent_gateway.UpdateAgentGatewayRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/gateways/sample3"} + request_init = { + "agent_gateway": { + "name": "projects/sample1/locations/sample2/agentGateways/sample3" + } + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -48363,53 +52507,154 @@ def test_list_gateway_route_views_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_gateway_route_views(request) + client.update_agent_gateway(request) @pytest.mark.parametrize( "request_type", [ - route_view.ListGatewayRouteViewsRequest, + gcn_agent_gateway.UpdateAgentGatewayRequest, dict, ], ) -def test_list_gateway_route_views_rest_call_success(request_type): +def test_update_agent_gateway_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/gateways/sample3"} + request_init = { + "agent_gateway": { + "name": "projects/sample1/locations/sample2/agentGateways/sample3" + } + } + request_init["agent_gateway"] = { + "google_managed": {"governed_access_path": 1}, + "self_managed": {"resource_uri": "resource_uri_value"}, + "name": "projects/sample1/locations/sample2/agentGateways/sample3", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "labels": {}, + "description": "description_value", + "etag": "etag_value", + "protocols": [1], + "registries": ["registries_value1", "registries_value2"], + "network_config": { + "egress": { + "network_attachment": "network_attachment_value", + "trust_config": { + "pem_certificates": [ + "pem_certificates_value1", + "pem_certificates_value2", + ] + }, + }, + "dns_peering_config": { + "domains": ["domains_value1", "domains_value2"], + "target_project": "target_project_value", + "target_network": "target_network_value", + }, + }, + "agent_gateway_card": { + "mtls_endpoint": "mtls_endpoint_value", + "root_certificates": [ + "root_certificates_value1", + "root_certificates_value2", + ], + "service_extensions_service_account": "service_extensions_service_account_value", + }, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = gcn_agent_gateway.UpdateAgentGatewayRequest.meta.fields[ + "agent_gateway" + ] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["agent_gateway"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["agent_gateway"][field])): + del request_init["agent_gateway"][field][i][subfield] + else: + del request_init["agent_gateway"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = route_view.ListGatewayRouteViewsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = mock.Mock() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = route_view.ListGatewayRouteViewsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_gateway_route_views(request) + response = client.update_agent_gateway(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListGatewayRouteViewsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_gateway_route_views_rest_interceptors(null_interceptor): +def test_update_agent_gateway_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -48421,22 +52666,23 @@ def test_list_gateway_route_views_rest_interceptors(null_interceptor): with ( mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_gateway_route_views" + transports.NetworkServicesRestInterceptor, "post_update_agent_gateway" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_gateway_route_views_with_metadata", + "post_update_agent_gateway_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_gateway_route_views" + transports.NetworkServicesRestInterceptor, "pre_update_agent_gateway" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = route_view.ListGatewayRouteViewsRequest.pb( - route_view.ListGatewayRouteViewsRequest() + pb_message = gcn_agent_gateway.UpdateAgentGatewayRequest.pb( + gcn_agent_gateway.UpdateAgentGatewayRequest() ) transcode.return_value = { "method": "post", @@ -48448,24 +52694,19 @@ def test_list_gateway_route_views_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = route_view.ListGatewayRouteViewsResponse.to_json( - route_view.ListGatewayRouteViewsResponse() - ) + return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = route_view.ListGatewayRouteViewsRequest() + request = gcn_agent_gateway.UpdateAgentGatewayRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = route_view.ListGatewayRouteViewsResponse() - post_with_metadata.return_value = ( - route_view.ListGatewayRouteViewsResponse(), - metadata, - ) + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.list_gateway_route_views( + client.update_agent_gateway( request, metadata=[ ("key", "val"), @@ -48478,14 +52719,14 @@ def test_list_gateway_route_views_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() -def test_list_mesh_route_views_rest_bad_request( - request_type=route_view.ListMeshRouteViewsRequest, +def test_delete_agent_gateway_rest_bad_request( + request_type=agent_gateway.DeleteAgentGatewayRequest, ): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/meshes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/agentGateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -48501,53 +52742,45 @@ def test_list_mesh_route_views_rest_bad_request( response_value.request = mock.Mock() req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_mesh_route_views(request) + client.delete_agent_gateway(request) @pytest.mark.parametrize( "request_type", [ - route_view.ListMeshRouteViewsRequest, + agent_gateway.DeleteAgentGatewayRequest, dict, ], ) -def test_list_mesh_route_views_rest_call_success(request_type): +def test_delete_agent_gateway_rest_call_success(request_type): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/meshes/sample3"} + request_init = {"name": "projects/sample1/locations/sample2/agentGateways/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = route_view.ListMeshRouteViewsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = mock.Mock() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = route_view.ListMeshRouteViewsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_mesh_route_views(request) + response = client.delete_agent_gateway(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListMeshRouteViewsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + json_return_value = json_format.MessageToJson(return_value) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_mesh_route_views_rest_interceptors(null_interceptor): +def test_delete_agent_gateway_rest_interceptors(null_interceptor): transport = transports.NetworkServicesRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -48559,22 +52792,23 @@ def test_list_mesh_route_views_rest_interceptors(null_interceptor): with ( mock.patch.object(type(client.transport._session), "request") as req, mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), mock.patch.object( - transports.NetworkServicesRestInterceptor, "post_list_mesh_route_views" + transports.NetworkServicesRestInterceptor, "post_delete_agent_gateway" ) as post, mock.patch.object( transports.NetworkServicesRestInterceptor, - "post_list_mesh_route_views_with_metadata", + "post_delete_agent_gateway_with_metadata", ) as post_with_metadata, mock.patch.object( - transports.NetworkServicesRestInterceptor, "pre_list_mesh_route_views" + transports.NetworkServicesRestInterceptor, "pre_delete_agent_gateway" ) as pre, ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = route_view.ListMeshRouteViewsRequest.pb( - route_view.ListMeshRouteViewsRequest() + pb_message = agent_gateway.DeleteAgentGatewayRequest.pb( + agent_gateway.DeleteAgentGatewayRequest() ) transcode.return_value = { "method": "post", @@ -48586,24 +52820,19 @@ def test_list_mesh_route_views_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = route_view.ListMeshRouteViewsResponse.to_json( - route_view.ListMeshRouteViewsResponse() - ) + return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value - request = route_view.ListMeshRouteViewsRequest() + request = agent_gateway.DeleteAgentGatewayRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = route_view.ListMeshRouteViewsResponse() - post_with_metadata.return_value = ( - route_view.ListMeshRouteViewsResponse(), - metadata, - ) + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata - client.list_mesh_route_views( + client.delete_agent_gateway( request, metadata=[ ("key", "val"), @@ -50363,6 +54592,111 @@ def test_list_mesh_route_views_empty_call_rest(): assert args[0] == request_msg +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_agent_gateways_empty_call_rest(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_agent_gateways), "__call__" + ) as call: + client.list_agent_gateways(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.ListAgentGatewaysRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_agent_gateway_empty_call_rest(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_agent_gateway), "__call__" + ) as call: + client.get_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.GetAgentGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_agent_gateway_empty_call_rest(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_agent_gateway), "__call__" + ) as call: + client.create_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_agent_gateway.CreateAgentGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_agent_gateway_empty_call_rest(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_agent_gateway), "__call__" + ) as call: + client.update_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = gcn_agent_gateway.UpdateAgentGatewayRequest() + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_agent_gateway_empty_call_rest(): + client = NetworkServicesClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_agent_gateway), "__call__" + ) as call: + client.delete_agent_gateway(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = agent_gateway.DeleteAgentGatewayRequest() + assert args[0] == request_msg + + def test_network_services_rest_lro_client(): client = NetworkServicesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -50471,6 +54805,11 @@ def test_network_services_base_transport(): "get_mesh_route_view", "list_gateway_route_views", "list_mesh_route_views", + "list_agent_gateways", + "get_agent_gateway", + "create_agent_gateway", + "update_agent_gateway", + "delete_agent_gateway", "set_iam_policy", "get_iam_policy", "test_iam_permissions", @@ -50924,6 +55263,21 @@ def test_network_services_client_transport_session_collision(transport_name): session1 = client1.transport.list_mesh_route_views._session session2 = client2.transport.list_mesh_route_views._session assert session1 != session2 + session1 = client1.transport.list_agent_gateways._session + session2 = client2.transport.list_agent_gateways._session + assert session1 != session2 + session1 = client1.transport.get_agent_gateway._session + session2 = client2.transport.get_agent_gateway._session + assert session1 != session2 + session1 = client1.transport.create_agent_gateway._session + session2 = client2.transport.create_agent_gateway._session + assert session1 != session2 + session1 = client1.transport.update_agent_gateway._session + session2 = client2.transport.update_agent_gateway._session + assert session1 != session2 + session1 = client1.transport.delete_agent_gateway._session + session2 = client2.transport.delete_agent_gateway._session + assert session1 != session2 def test_network_services_grpc_transport_channel(): @@ -51113,10 +55467,38 @@ def test_parse_address_path(): assert expected == actual -def test_authorization_policy_path(): +def test_agent_gateway_path(): project = "cuttlefish" location = "mussel" - authorization_policy = "winkle" + agent_gateway = "winkle" + expected = ( + "projects/{project}/locations/{location}/agentGateways/{agent_gateway}".format( + project=project, + location=location, + agent_gateway=agent_gateway, + ) + ) + actual = NetworkServicesClient.agent_gateway_path(project, location, agent_gateway) + assert expected == actual + + +def test_parse_agent_gateway_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "agent_gateway": "abalone", + } + path = NetworkServicesClient.agent_gateway_path(**expected) + + # Check that the path construction is reversible. + actual = NetworkServicesClient.parse_agent_gateway_path(path) + assert expected == actual + + +def test_authorization_policy_path(): + project = "squid" + location = "clam" + authorization_policy = "whelk" expected = "projects/{project}/locations/{location}/authorizationPolicies/{authorization_policy}".format( project=project, location=location, @@ -51130,9 +55512,9 @@ def test_authorization_policy_path(): def test_parse_authorization_policy_path(): expected = { - "project": "nautilus", - "location": "scallop", - "authorization_policy": "abalone", + "project": "octopus", + "location": "oyster", + "authorization_policy": "nudibranch", } path = NetworkServicesClient.authorization_policy_path(**expected) @@ -51142,9 +55524,9 @@ def test_parse_authorization_policy_path(): def test_backend_service_path(): - project = "squid" - location = "clam" - backend_service = "whelk" + project = "cuttlefish" + location = "mussel" + backend_service = "winkle" expected = "projects/{project}/locations/{location}/backendServices/{backend_service}".format( project=project, location=location, @@ -51158,9 +55540,9 @@ def test_backend_service_path(): def test_parse_backend_service_path(): expected = { - "project": "octopus", - "location": "oyster", - "backend_service": "nudibranch", + "project": "nautilus", + "location": "scallop", + "backend_service": "abalone", } path = NetworkServicesClient.backend_service_path(**expected) @@ -51170,9 +55552,9 @@ def test_parse_backend_service_path(): def test_certificate_path(): - project = "cuttlefish" - location = "mussel" - certificate = "winkle" + project = "squid" + location = "clam" + certificate = "whelk" expected = ( "projects/{project}/locations/{location}/certificates/{certificate}".format( project=project, @@ -51186,9 +55568,9 @@ def test_certificate_path(): def test_parse_certificate_path(): expected = { - "project": "nautilus", - "location": "scallop", - "certificate": "abalone", + "project": "octopus", + "location": "oyster", + "certificate": "nudibranch", } path = NetworkServicesClient.certificate_path(**expected) @@ -51198,9 +55580,9 @@ def test_parse_certificate_path(): def test_client_tls_policy_path(): - project = "squid" - location = "clam" - client_tls_policy = "whelk" + project = "cuttlefish" + location = "mussel" + client_tls_policy = "winkle" expected = "projects/{project}/locations/{location}/clientTlsPolicies/{client_tls_policy}".format( project=project, location=location, @@ -51214,9 +55596,9 @@ def test_client_tls_policy_path(): def test_parse_client_tls_policy_path(): expected = { - "project": "octopus", - "location": "oyster", - "client_tls_policy": "nudibranch", + "project": "nautilus", + "location": "scallop", + "client_tls_policy": "abalone", } path = NetworkServicesClient.client_tls_policy_path(**expected) @@ -51226,9 +55608,9 @@ def test_parse_client_tls_policy_path(): def test_endpoint_policy_path(): - project = "cuttlefish" - location = "mussel" - endpoint_policy = "winkle" + project = "squid" + location = "clam" + endpoint_policy = "whelk" expected = "projects/{project}/locations/{location}/endpointPolicies/{endpoint_policy}".format( project=project, location=location, @@ -51242,9 +55624,9 @@ def test_endpoint_policy_path(): def test_parse_endpoint_policy_path(): expected = { - "project": "nautilus", - "location": "scallop", - "endpoint_policy": "abalone", + "project": "octopus", + "location": "oyster", + "endpoint_policy": "nudibranch", } path = NetworkServicesClient.endpoint_policy_path(**expected) @@ -51254,9 +55636,9 @@ def test_parse_endpoint_policy_path(): def test_gateway_path(): - project = "squid" - location = "clam" - gateway = "whelk" + project = "cuttlefish" + location = "mussel" + gateway = "winkle" expected = "projects/{project}/locations/{location}/gateways/{gateway}".format( project=project, location=location, @@ -51268,9 +55650,9 @@ def test_gateway_path(): def test_parse_gateway_path(): expected = { - "project": "octopus", - "location": "oyster", - "gateway": "nudibranch", + "project": "nautilus", + "location": "scallop", + "gateway": "abalone", } path = NetworkServicesClient.gateway_path(**expected) @@ -51280,10 +55662,10 @@ def test_parse_gateway_path(): def test_gateway_route_view_path(): - project = "cuttlefish" - location = "mussel" - gateway = "winkle" - route_view = "nautilus" + project = "squid" + location = "clam" + gateway = "whelk" + route_view = "octopus" expected = "projects/{project}/locations/{location}/gateways/{gateway}/routeViews/{route_view}".format( project=project, location=location, @@ -51298,10 +55680,10 @@ def test_gateway_route_view_path(): def test_parse_gateway_route_view_path(): expected = { - "project": "scallop", - "location": "abalone", - "gateway": "squid", - "route_view": "clam", + "project": "oyster", + "location": "nudibranch", + "gateway": "cuttlefish", + "route_view": "mussel", } path = NetworkServicesClient.gateway_route_view_path(**expected) @@ -51311,9 +55693,9 @@ def test_parse_gateway_route_view_path(): def test_gateway_security_policy_path(): - project = "whelk" - location = "octopus" - gateway_security_policy = "oyster" + project = "winkle" + location = "nautilus" + gateway_security_policy = "scallop" expected = "projects/{project}/locations/{location}/gatewaySecurityPolicies/{gateway_security_policy}".format( project=project, location=location, @@ -51327,9 +55709,9 @@ def test_gateway_security_policy_path(): def test_parse_gateway_security_policy_path(): expected = { - "project": "nudibranch", - "location": "cuttlefish", - "gateway_security_policy": "mussel", + "project": "abalone", + "location": "squid", + "gateway_security_policy": "clam", } path = NetworkServicesClient.gateway_security_policy_path(**expected) @@ -51339,9 +55721,9 @@ def test_parse_gateway_security_policy_path(): def test_grpc_route_path(): - project = "winkle" - location = "nautilus" - grpc_route = "scallop" + project = "whelk" + location = "octopus" + grpc_route = "oyster" expected = "projects/{project}/locations/{location}/grpcRoutes/{grpc_route}".format( project=project, location=location, @@ -51353,9 +55735,9 @@ def test_grpc_route_path(): def test_parse_grpc_route_path(): expected = { - "project": "abalone", - "location": "squid", - "grpc_route": "clam", + "project": "nudibranch", + "location": "cuttlefish", + "grpc_route": "mussel", } path = NetworkServicesClient.grpc_route_path(**expected) @@ -51365,9 +55747,9 @@ def test_parse_grpc_route_path(): def test_http_route_path(): - project = "whelk" - location = "octopus" - http_route = "oyster" + project = "winkle" + location = "nautilus" + http_route = "scallop" expected = "projects/{project}/locations/{location}/httpRoutes/{http_route}".format( project=project, location=location, @@ -51379,9 +55761,9 @@ def test_http_route_path(): def test_parse_http_route_path(): expected = { - "project": "nudibranch", - "location": "cuttlefish", - "http_route": "mussel", + "project": "abalone", + "location": "squid", + "http_route": "clam", } path = NetworkServicesClient.http_route_path(**expected) @@ -51391,9 +55773,9 @@ def test_parse_http_route_path(): def test_mesh_path(): - project = "winkle" - location = "nautilus" - mesh = "scallop" + project = "whelk" + location = "octopus" + mesh = "oyster" expected = "projects/{project}/locations/{location}/meshes/{mesh}".format( project=project, location=location, @@ -51405,9 +55787,9 @@ def test_mesh_path(): def test_parse_mesh_path(): expected = { - "project": "abalone", - "location": "squid", - "mesh": "clam", + "project": "nudibranch", + "location": "cuttlefish", + "mesh": "mussel", } path = NetworkServicesClient.mesh_path(**expected) @@ -51417,10 +55799,10 @@ def test_parse_mesh_path(): def test_mesh_route_view_path(): - project = "whelk" - location = "octopus" - mesh = "oyster" - route_view = "nudibranch" + project = "winkle" + location = "nautilus" + mesh = "scallop" + route_view = "abalone" expected = "projects/{project}/locations/{location}/meshes/{mesh}/routeViews/{route_view}".format( project=project, location=location, @@ -51435,10 +55817,10 @@ def test_mesh_route_view_path(): def test_parse_mesh_route_view_path(): expected = { - "project": "cuttlefish", - "location": "mussel", - "mesh": "winkle", - "route_view": "nautilus", + "project": "squid", + "location": "clam", + "mesh": "whelk", + "route_view": "octopus", } path = NetworkServicesClient.mesh_route_view_path(**expected) @@ -51448,8 +55830,8 @@ def test_parse_mesh_route_view_path(): def test_network_path(): - project = "scallop" - network = "abalone" + project = "oyster" + network = "nudibranch" expected = "projects/{project}/global/networks/{network}".format( project=project, network=network, @@ -51460,8 +55842,8 @@ def test_network_path(): def test_parse_network_path(): expected = { - "project": "squid", - "network": "clam", + "project": "cuttlefish", + "network": "mussel", } path = NetworkServicesClient.network_path(**expected) @@ -51471,9 +55853,9 @@ def test_parse_network_path(): def test_server_tls_policy_path(): - project = "whelk" - location = "octopus" - server_tls_policy = "oyster" + project = "winkle" + location = "nautilus" + server_tls_policy = "scallop" expected = "projects/{project}/locations/{location}/serverTlsPolicies/{server_tls_policy}".format( project=project, location=location, @@ -51487,9 +55869,9 @@ def test_server_tls_policy_path(): def test_parse_server_tls_policy_path(): expected = { - "project": "nudibranch", - "location": "cuttlefish", - "server_tls_policy": "mussel", + "project": "abalone", + "location": "squid", + "server_tls_policy": "clam", } path = NetworkServicesClient.server_tls_policy_path(**expected) @@ -51499,10 +55881,10 @@ def test_parse_server_tls_policy_path(): def test_service_path(): - project = "winkle" - location = "nautilus" - namespace = "scallop" - service = "abalone" + project = "whelk" + location = "octopus" + namespace = "oyster" + service = "nudibranch" expected = "projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}".format( project=project, location=location, @@ -51515,10 +55897,10 @@ def test_service_path(): def test_parse_service_path(): expected = { - "project": "squid", - "location": "clam", - "namespace": "whelk", - "service": "octopus", + "project": "cuttlefish", + "location": "mussel", + "namespace": "winkle", + "service": "nautilus", } path = NetworkServicesClient.service_path(**expected) @@ -51528,9 +55910,9 @@ def test_parse_service_path(): def test_service_binding_path(): - project = "oyster" - location = "nudibranch" - service_binding = "cuttlefish" + project = "scallop" + location = "abalone" + service_binding = "squid" expected = "projects/{project}/locations/{location}/serviceBindings/{service_binding}".format( project=project, location=location, @@ -51544,9 +55926,9 @@ def test_service_binding_path(): def test_parse_service_binding_path(): expected = { - "project": "mussel", - "location": "winkle", - "service_binding": "nautilus", + "project": "clam", + "location": "whelk", + "service_binding": "octopus", } path = NetworkServicesClient.service_binding_path(**expected) @@ -51556,9 +55938,9 @@ def test_parse_service_binding_path(): def test_service_lb_policy_path(): - project = "scallop" - location = "abalone" - service_lb_policy = "squid" + project = "oyster" + location = "nudibranch" + service_lb_policy = "cuttlefish" expected = "projects/{project}/locations/{location}/serviceLbPolicies/{service_lb_policy}".format( project=project, location=location, @@ -51572,9 +55954,9 @@ def test_service_lb_policy_path(): def test_parse_service_lb_policy_path(): expected = { - "project": "clam", - "location": "whelk", - "service_lb_policy": "octopus", + "project": "mussel", + "location": "winkle", + "service_lb_policy": "nautilus", } path = NetworkServicesClient.service_lb_policy_path(**expected) @@ -51584,9 +55966,9 @@ def test_parse_service_lb_policy_path(): def test_subnetwork_path(): - project = "oyster" - region = "nudibranch" - subnetwork = "cuttlefish" + project = "scallop" + region = "abalone" + subnetwork = "squid" expected = "projects/{project}/regions/{region}/subnetworks/{subnetwork}".format( project=project, region=region, @@ -51598,9 +55980,9 @@ def test_subnetwork_path(): def test_parse_subnetwork_path(): expected = { - "project": "mussel", - "region": "winkle", - "subnetwork": "nautilus", + "project": "clam", + "region": "whelk", + "subnetwork": "octopus", } path = NetworkServicesClient.subnetwork_path(**expected) @@ -51609,6 +55991,34 @@ def test_parse_subnetwork_path(): assert expected == actual +def test_target_tcp_proxy_path(): + project = "oyster" + location = "nudibranch" + target_tcp_proxy = "cuttlefish" + expected = "projects/{project}/locations/{location}/targetTcpProxies/{target_tcp_proxy}".format( + project=project, + location=location, + target_tcp_proxy=target_tcp_proxy, + ) + actual = NetworkServicesClient.target_tcp_proxy_path( + project, location, target_tcp_proxy + ) + assert expected == actual + + +def test_parse_target_tcp_proxy_path(): + expected = { + "project": "mussel", + "location": "winkle", + "target_tcp_proxy": "nautilus", + } + path = NetworkServicesClient.target_tcp_proxy_path(**expected) + + # Check that the path construction is reversible. + actual = NetworkServicesClient.parse_target_tcp_proxy_path(path) + assert expected == actual + + def test_tcp_route_path(): project = "scallop" location = "abalone"