diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 8388fe10..6bb50d96 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.8.0" + ".": "2.9.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index d7e14843..85aa6ba3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [2.9.0](https://github.com/googleapis/python-documentai/compare/v2.8.0...v2.9.0) (2023-01-17) + + +### Features + +* **v1:** Exposed GetProcessorType ([#446](https://github.com/googleapis/python-documentai/issues/446)) ([6c38227](https://github.com/googleapis/python-documentai/commit/6c38227279d889f760375dfe56f805da78e7bc68)) + ## [2.8.0](https://github.com/googleapis/python-documentai/compare/v2.7.0...v2.8.0) (2023-01-17) diff --git a/google/cloud/documentai/__init__.py b/google/cloud/documentai/__init__.py index 7bc41047..29407c4c 100644 --- a/google/cloud/documentai/__init__.py +++ b/google/cloud/documentai/__init__.py @@ -55,6 +55,7 @@ FetchProcessorTypesRequest, FetchProcessorTypesResponse, GetProcessorRequest, + GetProcessorTypeRequest, GetProcessorVersionRequest, HumanReviewStatus, ListProcessorsRequest, @@ -116,6 +117,7 @@ "FetchProcessorTypesRequest", "FetchProcessorTypesResponse", "GetProcessorRequest", + "GetProcessorTypeRequest", "GetProcessorVersionRequest", "HumanReviewStatus", "ListProcessorsRequest", diff --git a/google/cloud/documentai/gapic_version.py b/google/cloud/documentai/gapic_version.py index e248a9ca..60aeb18d 100644 --- a/google/cloud/documentai/gapic_version.py +++ b/google/cloud/documentai/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.8.0" # {x-release-please-version} +__version__ = "2.9.0" # {x-release-please-version} diff --git a/google/cloud/documentai_v1/__init__.py b/google/cloud/documentai_v1/__init__.py index a3039bd0..5566b091 100644 --- a/google/cloud/documentai_v1/__init__.py +++ b/google/cloud/documentai_v1/__init__.py @@ -53,6 +53,7 @@ FetchProcessorTypesRequest, FetchProcessorTypesResponse, GetProcessorRequest, + GetProcessorTypeRequest, GetProcessorVersionRequest, HumanReviewStatus, ListProcessorsRequest, @@ -112,6 +113,7 @@ "GcsDocuments", "GcsPrefix", "GetProcessorRequest", + "GetProcessorTypeRequest", "GetProcessorVersionRequest", "HumanReviewStatus", "ListProcessorTypesRequest", diff --git a/google/cloud/documentai_v1/gapic_metadata.json b/google/cloud/documentai_v1/gapic_metadata.json index 8436c789..7bc1c8e7 100644 --- a/google/cloud/documentai_v1/gapic_metadata.json +++ b/google/cloud/documentai_v1/gapic_metadata.json @@ -55,6 +55,11 @@ "get_processor" ] }, + "GetProcessorType": { + "methods": [ + "get_processor_type" + ] + }, "GetProcessorVersion": { "methods": [ "get_processor_version" @@ -145,6 +150,11 @@ "get_processor" ] }, + "GetProcessorType": { + "methods": [ + "get_processor_type" + ] + }, "GetProcessorVersion": { "methods": [ "get_processor_version" diff --git a/google/cloud/documentai_v1/gapic_version.py b/google/cloud/documentai_v1/gapic_version.py index e248a9ca..60aeb18d 100644 --- a/google/cloud/documentai_v1/gapic_version.py +++ b/google/cloud/documentai_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.8.0" # {x-release-please-version} +__version__ = "2.9.0" # {x-release-please-version} diff --git a/google/cloud/documentai_v1/services/document_processor_service/async_client.py b/google/cloud/documentai_v1/services/document_processor_service/async_client.py index e0d7ca97..4a28256a 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/async_client.py +++ b/google/cloud/documentai_v1/services/document_processor_service/async_client.py @@ -42,6 +42,7 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object] # type: ignore +from google.api import launch_stage_pb2 # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore @@ -746,6 +747,111 @@ async def sample_list_processor_types(): # Done; return the response. return response + async def get_processor_type( + self, + request: Optional[ + Union[document_processor_service.GetProcessorTypeRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> processor_type.ProcessorType: + r"""Gets a processor type detail. + + .. 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 documentai_v1 + + async def sample_get_processor_type(): + # Create a client + client = documentai_v1.DocumentProcessorServiceAsyncClient() + + # Initialize request argument(s) + request = documentai_v1.GetProcessorTypeRequest( + name="name_value", + ) + + # Make the request + response = await client.get_processor_type(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.documentai_v1.types.GetProcessorTypeRequest, dict]]): + The request object. Request message for get processor. + name (:class:`str`): + Required. The processor type resource + name. + + 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, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1.types.ProcessorType: + A processor type is responsible for + performing a certain document + understanding task on a certain type of + document. + + """ + # 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. + has_flattened_params = any([name]) + 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." + ) + + request = document_processor_service.GetProcessorTypeRequest(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 = gapic_v1.method_async.wrap_method( + self._client._transport.get_processor_type, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def list_processors( self, request: Optional[ diff --git a/google/cloud/documentai_v1/services/document_processor_service/client.py b/google/cloud/documentai_v1/services/document_processor_service/client.py index d35f24da..165cce11 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/client.py +++ b/google/cloud/documentai_v1/services/document_processor_service/client.py @@ -46,6 +46,7 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object] # type: ignore +from google.api import launch_stage_pb2 # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore @@ -1000,6 +1001,111 @@ def sample_list_processor_types(): # Done; return the response. return response + def get_processor_type( + self, + request: Optional[ + Union[document_processor_service.GetProcessorTypeRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> processor_type.ProcessorType: + r"""Gets a processor type detail. + + .. 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 documentai_v1 + + def sample_get_processor_type(): + # Create a client + client = documentai_v1.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1.GetProcessorTypeRequest( + name="name_value", + ) + + # Make the request + response = client.get_processor_type(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.documentai_v1.types.GetProcessorTypeRequest, dict]): + The request object. Request message for get processor. + name (str): + Required. The processor type resource + name. + + 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, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1.types.ProcessorType: + A processor type is responsible for + performing a certain document + understanding task on a certain type of + document. + + """ + # 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. + has_flattened_params = any([name]) + 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." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.GetProcessorTypeRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.GetProcessorTypeRequest): + request = document_processor_service.GetProcessorTypeRequest(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_processor_type] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + def list_processors( self, request: Optional[ diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index f613cb57..00055f71 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -30,6 +30,7 @@ from google.cloud.documentai_v1.types import document_processor_service from google.cloud.documentai_v1.types import processor from google.cloud.documentai_v1.types import processor as gcd_processor +from google.cloud.documentai_v1.types import processor_type DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=package_version.__version__ @@ -166,6 +167,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.get_processor_type: gapic_v1.method.wrap_method( + self.get_processor_type, + default_timeout=None, + client_info=client_info, + ), self.list_processors: gapic_v1.method.wrap_method( self.list_processors, default_timeout=None, @@ -302,6 +308,15 @@ def list_processor_types( ]: raise NotImplementedError() + @property + def get_processor_type( + self, + ) -> Callable[ + [document_processor_service.GetProcessorTypeRequest], + Union[processor_type.ProcessorType, Awaitable[processor_type.ProcessorType]], + ]: + raise NotImplementedError() + @property def list_processors( self, diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py index 666a6852..97eb8a7c 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py @@ -27,6 +27,7 @@ from google.cloud.documentai_v1.types import document_processor_service from google.cloud.documentai_v1.types import processor from google.cloud.documentai_v1.types import processor as gcd_processor +from google.cloud.documentai_v1.types import processor_type from .base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport @@ -368,6 +369,35 @@ def list_processor_types( ) return self._stubs["list_processor_types"] + @property + def get_processor_type( + self, + ) -> Callable[ + [document_processor_service.GetProcessorTypeRequest], + processor_type.ProcessorType, + ]: + r"""Return a callable for the get processor type method over gRPC. + + Gets a processor type detail. + + Returns: + Callable[[~.GetProcessorTypeRequest], + ~.ProcessorType]: + 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_processor_type" not in self._stubs: + self._stubs["get_processor_type"] = self.grpc_channel.unary_unary( + "/google.cloud.documentai.v1.DocumentProcessorService/GetProcessorType", + request_serializer=document_processor_service.GetProcessorTypeRequest.serialize, + response_deserializer=processor_type.ProcessorType.deserialize, + ) + return self._stubs["get_processor_type"] + @property def list_processors( self, diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py index 39901026..e4d2128c 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py @@ -27,6 +27,7 @@ from google.cloud.documentai_v1.types import document_processor_service from google.cloud.documentai_v1.types import processor from google.cloud.documentai_v1.types import processor as gcd_processor +from google.cloud.documentai_v1.types import processor_type from .base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport from .grpc import DocumentProcessorServiceGrpcTransport @@ -374,6 +375,35 @@ def list_processor_types( ) return self._stubs["list_processor_types"] + @property + def get_processor_type( + self, + ) -> Callable[ + [document_processor_service.GetProcessorTypeRequest], + Awaitable[processor_type.ProcessorType], + ]: + r"""Return a callable for the get processor type method over gRPC. + + Gets a processor type detail. + + Returns: + Callable[[~.GetProcessorTypeRequest], + Awaitable[~.ProcessorType]]: + 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_processor_type" not in self._stubs: + self._stubs["get_processor_type"] = self.grpc_channel.unary_unary( + "/google.cloud.documentai.v1.DocumentProcessorService/GetProcessorType", + request_serializer=document_processor_service.GetProcessorTypeRequest.serialize, + response_deserializer=processor_type.ProcessorType.deserialize, + ) + return self._stubs["get_processor_type"] + @property def list_processors( self, diff --git a/google/cloud/documentai_v1/types/__init__.py b/google/cloud/documentai_v1/types/__init__.py index 2ed2cde6..4d1bee7d 100644 --- a/google/cloud/documentai_v1/types/__init__.py +++ b/google/cloud/documentai_v1/types/__init__.py @@ -44,6 +44,7 @@ FetchProcessorTypesRequest, FetchProcessorTypesResponse, GetProcessorRequest, + GetProcessorTypeRequest, GetProcessorVersionRequest, HumanReviewStatus, ListProcessorsRequest, @@ -99,6 +100,7 @@ "FetchProcessorTypesRequest", "FetchProcessorTypesResponse", "GetProcessorRequest", + "GetProcessorTypeRequest", "GetProcessorVersionRequest", "HumanReviewStatus", "ListProcessorsRequest", diff --git a/google/cloud/documentai_v1/types/document_processor_service.py b/google/cloud/documentai_v1/types/document_processor_service.py index 3c5d97dc..c830a017 100644 --- a/google/cloud/documentai_v1/types/document_processor_service.py +++ b/google/cloud/documentai_v1/types/document_processor_service.py @@ -42,6 +42,7 @@ "ListProcessorTypesResponse", "ListProcessorsRequest", "ListProcessorsResponse", + "GetProcessorTypeRequest", "GetProcessorRequest", "GetProcessorVersionRequest", "ListProcessorVersionsRequest", @@ -502,6 +503,20 @@ def raw_page(self): ) +class GetProcessorTypeRequest(proto.Message): + r"""Request message for get processor. + + Attributes: + name (str): + Required. The processor type resource name. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + class GetProcessorRequest(proto.Message): r"""Request message for get processor. diff --git a/google/cloud/documentai_v1beta2/gapic_version.py b/google/cloud/documentai_v1beta2/gapic_version.py index e248a9ca..60aeb18d 100644 --- a/google/cloud/documentai_v1beta2/gapic_version.py +++ b/google/cloud/documentai_v1beta2/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.8.0" # {x-release-please-version} +__version__ = "2.9.0" # {x-release-please-version} diff --git a/google/cloud/documentai_v1beta3/gapic_version.py b/google/cloud/documentai_v1beta3/gapic_version.py index e248a9ca..60aeb18d 100644 --- a/google/cloud/documentai_v1beta3/gapic_version.py +++ b/google/cloud/documentai_v1beta3/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.8.0" # {x-release-please-version} +__version__ = "2.9.0" # {x-release-please-version} diff --git a/samples/generated_samples/documentai_v1_generated_document_processor_service_get_processor_type_async.py b/samples/generated_samples/documentai_v1_generated_document_processor_service_get_processor_type_async.py new file mode 100644 index 00000000..20552d91 --- /dev/null +++ b/samples/generated_samples/documentai_v1_generated_document_processor_service_get_processor_type_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 GetProcessorType +# 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-documentai + + +# [START documentai_v1_generated_DocumentProcessorService_GetProcessorType_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 documentai_v1 + + +async def sample_get_processor_type(): + # Create a client + client = documentai_v1.DocumentProcessorServiceAsyncClient() + + # Initialize request argument(s) + request = documentai_v1.GetProcessorTypeRequest( + name="name_value", + ) + + # Make the request + response = await client.get_processor_type(request=request) + + # Handle the response + print(response) + +# [END documentai_v1_generated_DocumentProcessorService_GetProcessorType_async] diff --git a/samples/generated_samples/documentai_v1_generated_document_processor_service_get_processor_type_sync.py b/samples/generated_samples/documentai_v1_generated_document_processor_service_get_processor_type_sync.py new file mode 100644 index 00000000..ad27f0c6 --- /dev/null +++ b/samples/generated_samples/documentai_v1_generated_document_processor_service_get_processor_type_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 GetProcessorType +# 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-documentai + + +# [START documentai_v1_generated_DocumentProcessorService_GetProcessorType_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 documentai_v1 + + +def sample_get_processor_type(): + # Create a client + client = documentai_v1.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1.GetProcessorTypeRequest( + name="name_value", + ) + + # Make the request + response = client.get_processor_type(request=request) + + # Handle the response + print(response) + +# [END documentai_v1_generated_DocumentProcessorService_GetProcessorType_sync] diff --git a/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1.json b/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1.json index 7c5bc5c3..48cfeb17 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-documentai", - "version": "2.8.0" + "version": "2.9.0" }, "snippets": [ { @@ -1291,6 +1291,167 @@ ], "title": "documentai_v1_generated_document_processor_service_fetch_processor_types_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceAsyncClient.get_processor_type", + "method": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService.GetProcessorType", + "service": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService", + "shortName": "DocumentProcessorService" + }, + "shortName": "GetProcessorType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1.types.GetProcessorTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1.types.ProcessorType", + "shortName": "get_processor_type" + }, + "description": "Sample for GetProcessorType", + "file": "documentai_v1_generated_document_processor_service_get_processor_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "documentai_v1_generated_DocumentProcessorService_GetProcessorType_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": "documentai_v1_generated_document_processor_service_get_processor_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceClient.get_processor_type", + "method": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService.GetProcessorType", + "service": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService", + "shortName": "DocumentProcessorService" + }, + "shortName": "GetProcessorType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1.types.GetProcessorTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1.types.ProcessorType", + "shortName": "get_processor_type" + }, + "description": "Sample for GetProcessorType", + "file": "documentai_v1_generated_document_processor_service_get_processor_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "documentai_v1_generated_DocumentProcessorService_GetProcessorType_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": "documentai_v1_generated_document_processor_service_get_processor_type_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta2.json b/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta2.json index ccaab42e..10c94686 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta2.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-documentai", - "version": "2.8.0" + "version": "2.9.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta3.json b/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta3.json index e43cc036..c8212825 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta3.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta3.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-documentai", - "version": "2.8.0" + "version": "2.9.0" }, "snippets": [ { diff --git a/scripts/fixup_documentai_v1_keywords.py b/scripts/fixup_documentai_v1_keywords.py index 62a4c9a5..465e9dd8 100644 --- a/scripts/fixup_documentai_v1_keywords.py +++ b/scripts/fixup_documentai_v1_keywords.py @@ -48,6 +48,7 @@ class documentaiCallTransformer(cst.CSTTransformer): 'enable_processor': ('name', ), 'fetch_processor_types': ('parent', ), 'get_processor': ('name', ), + 'get_processor_type': ('name', ), 'get_processor_version': ('name', ), 'list_processors': ('parent', 'page_size', 'page_token', ), 'list_processor_types': ('parent', 'page_size', 'page_token', ), diff --git a/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/tests/unit/gapic/documentai_v1/test_document_processor_service.py index 9bb7cd97..1149b355 100644 --- a/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -24,6 +24,7 @@ import math +from google.api import launch_stage_pb2 # type: ignore from google.api_core import ( future, gapic_v1, @@ -1895,6 +1896,273 @@ async def test_list_processor_types_async_pages(): assert page_.raw_page.next_page_token == token +@pytest.mark.parametrize( + "request_type", + [ + document_processor_service.GetProcessorTypeRequest, + dict, + ], +) +def test_get_processor_type(request_type, transport: str = "grpc"): + client = DocumentProcessorServiceClient( + 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.get_processor_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = processor_type.ProcessorType( + name="name_value", + type_="type__value", + category="category_value", + allow_creation=True, + launch_stage=launch_stage_pb2.LaunchStage.UNIMPLEMENTED, + sample_document_uris=["sample_document_uris_value"], + ) + response = client.get_processor_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.GetProcessorTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, processor_type.ProcessorType) + assert response.name == "name_value" + assert response.type_ == "type__value" + assert response.category == "category_value" + assert response.allow_creation is True + assert response.launch_stage == launch_stage_pb2.LaunchStage.UNIMPLEMENTED + assert response.sample_document_uris == ["sample_document_uris_value"] + + +def test_get_processor_type_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_processor_type), "__call__" + ) as call: + client.get_processor_type() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.GetProcessorTypeRequest() + + +@pytest.mark.asyncio +async def test_get_processor_type_async( + transport: str = "grpc_asyncio", + request_type=document_processor_service.GetProcessorTypeRequest, +): + client = DocumentProcessorServiceAsyncClient( + 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.get_processor_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + processor_type.ProcessorType( + name="name_value", + type_="type__value", + category="category_value", + allow_creation=True, + launch_stage=launch_stage_pb2.LaunchStage.UNIMPLEMENTED, + sample_document_uris=["sample_document_uris_value"], + ) + ) + response = await client.get_processor_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.GetProcessorTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, processor_type.ProcessorType) + assert response.name == "name_value" + assert response.type_ == "type__value" + assert response.category == "category_value" + assert response.allow_creation is True + assert response.launch_stage == launch_stage_pb2.LaunchStage.UNIMPLEMENTED + assert response.sample_document_uris == ["sample_document_uris_value"] + + +@pytest.mark.asyncio +async def test_get_processor_type_async_from_dict(): + await test_get_processor_type_async(request_type=dict) + + +def test_get_processor_type_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.GetProcessorTypeRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_processor_type), "__call__" + ) as call: + call.return_value = processor_type.ProcessorType() + client.get_processor_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_processor_type_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.GetProcessorTypeRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_processor_type), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + processor_type.ProcessorType() + ) + await client.get_processor_type(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_processor_type_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_processor_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = processor_type.ProcessorType() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_processor_type( + 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_get_processor_type_flattened_error(): + client = DocumentProcessorServiceClient( + 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_processor_type( + document_processor_service.GetProcessorTypeRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_processor_type_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_processor_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = processor_type.ProcessorType() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + processor_type.ProcessorType() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_processor_type( + 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_get_processor_type_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_processor_type( + document_processor_service.GetProcessorTypeRequest(), + name="name_value", + ) + + @pytest.mark.parametrize( "request_type", [ @@ -5319,6 +5587,7 @@ def test_document_processor_service_base_transport(): "batch_process_documents", "fetch_processor_types", "list_processor_types", + "get_processor_type", "list_processors", "get_processor", "get_processor_version",