diff --git a/documentai-v1beta3-py.tar.gz b/documentai-v1beta3-py.tar.gz new file mode 100644 index 00000000..5b7db2c6 Binary files /dev/null and b/documentai-v1beta3-py.tar.gz differ diff --git a/google/cloud/documentai_v1beta3/__init__.py b/google/cloud/documentai_v1beta3/__init__.py index ca5d1d24..a6015e24 100644 --- a/google/cloud/documentai_v1beta3/__init__.py +++ b/google/cloud/documentai_v1beta3/__init__.py @@ -58,6 +58,7 @@ FetchProcessorTypesResponse, GetEvaluationRequest, GetProcessorRequest, + GetProcessorTypeRequest, GetProcessorVersionRequest, HumanReviewStatus, ListEvaluationsRequest, @@ -129,6 +130,7 @@ "GcsPrefix", "GetEvaluationRequest", "GetProcessorRequest", + "GetProcessorTypeRequest", "GetProcessorVersionRequest", "HumanReviewStatus", "ListEvaluationsRequest", diff --git a/google/cloud/documentai_v1beta3/gapic_metadata.json b/google/cloud/documentai_v1beta3/gapic_metadata.json index c2f2d879..f94368f8 100644 --- a/google/cloud/documentai_v1beta3/gapic_metadata.json +++ b/google/cloud/documentai_v1beta3/gapic_metadata.json @@ -65,6 +65,11 @@ "get_processor" ] }, + "GetProcessorType": { + "methods": [ + "get_processor_type" + ] + }, "GetProcessorVersion": { "methods": [ "get_processor_version" @@ -175,6 +180,11 @@ "get_processor" ] }, + "GetProcessorType": { + "methods": [ + "get_processor_type" + ] + }, "GetProcessorVersion": { "methods": [ "get_processor_version" diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py b/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py index f5bd693e..e8f34179 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py +++ b/google/cloud/documentai_v1beta3/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 @@ -753,6 +754,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_v1beta3 + + async def sample_get_processor_type(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() + + # Initialize request argument(s) + request = documentai_v1beta3.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_v1beta3.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_v1beta3.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_v1beta3/services/document_processor_service/client.py b/google/cloud/documentai_v1beta3/services/document_processor_service/client.py index 887267d8..77f1fe8e 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/client.py +++ b/google/cloud/documentai_v1beta3/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 @@ -1029,6 +1030,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_v1beta3 + + def sample_get_processor_type(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.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_v1beta3.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_v1beta3.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_v1beta3/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index ed4c7110..1e9f1f7a 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -30,6 +30,7 @@ from google.cloud.documentai_v1beta3.types import document_processor_service, evaluation from google.cloud.documentai_v1beta3.types import processor from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.cloud.documentai_v1beta3.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, @@ -322,6 +328,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_v1beta3/services/document_processor_service/transports/grpc.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py index cc21ecc8..47c8a1b1 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py @@ -27,6 +27,7 @@ from google.cloud.documentai_v1beta3.types import document_processor_service, evaluation from google.cloud.documentai_v1beta3.types import processor from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.cloud.documentai_v1beta3.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.v1beta3.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_v1beta3/services/document_processor_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py index 04d18b83..b6281f19 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py @@ -27,6 +27,7 @@ from google.cloud.documentai_v1beta3.types import document_processor_service, evaluation from google.cloud.documentai_v1beta3.types import processor from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.cloud.documentai_v1beta3.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.v1beta3.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_v1beta3/types/__init__.py b/google/cloud/documentai_v1beta3/types/__init__.py index 21e68d43..62005726 100644 --- a/google/cloud/documentai_v1beta3/types/__init__.py +++ b/google/cloud/documentai_v1beta3/types/__init__.py @@ -49,6 +49,7 @@ FetchProcessorTypesResponse, GetEvaluationRequest, GetProcessorRequest, + GetProcessorTypeRequest, GetProcessorVersionRequest, HumanReviewStatus, ListEvaluationsRequest, @@ -116,6 +117,7 @@ "FetchProcessorTypesResponse", "GetEvaluationRequest", "GetProcessorRequest", + "GetProcessorTypeRequest", "GetProcessorVersionRequest", "HumanReviewStatus", "ListEvaluationsRequest", diff --git a/google/cloud/documentai_v1beta3/types/document_processor_service.py b/google/cloud/documentai_v1beta3/types/document_processor_service.py index 32252d98..61d83f21 100644 --- a/google/cloud/documentai_v1beta3/types/document_processor_service.py +++ b/google/cloud/documentai_v1beta3/types/document_processor_service.py @@ -44,6 +44,7 @@ "ListProcessorTypesResponse", "ListProcessorsRequest", "ListProcessorsResponse", + "GetProcessorTypeRequest", "GetProcessorRequest", "GetProcessorVersionRequest", "ListProcessorVersionsRequest", @@ -625,6 +626,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/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_get_processor_type_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_get_processor_type_async.py new file mode 100644 index 00000000..6f276a69 --- /dev/null +++ b/samples/generated_samples/documentai_v1beta3_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_v1beta3_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_v1beta3 + + +async def sample_get_processor_type(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() + + # Initialize request argument(s) + request = documentai_v1beta3.GetProcessorTypeRequest( + name="name_value", + ) + + # Make the request + response = await client.get_processor_type(request=request) + + # Handle the response + print(response) + +# [END documentai_v1beta3_generated_DocumentProcessorService_GetProcessorType_async] diff --git a/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_get_processor_type_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_get_processor_type_sync.py new file mode 100644 index 00000000..1db0b26c --- /dev/null +++ b/samples/generated_samples/documentai_v1beta3_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_v1beta3_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_v1beta3 + + +def sample_get_processor_type(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.GetProcessorTypeRequest( + name="name_value", + ) + + # Make the request + response = client.get_processor_type(request=request) + + # Handle the response + print(response) + +# [END documentai_v1beta3_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 873363fb..5064960d 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.7.0" + "version": "0.1.0" }, "snippets": [ { 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 c56deb29..ef56bd7e 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.7.0" + "version": "0.1.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 ef9208fb..f02752f1 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.7.0" + "version": "0.1.0" }, "snippets": [ { @@ -1613,6 +1613,167 @@ ], "title": "documentai_v1beta3_generated_document_processor_service_get_evaluation_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.get_processor_type", + "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.GetProcessorType", + "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", + "shortName": "DocumentProcessorService" + }, + "shortName": "GetProcessorType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.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_v1beta3.types.ProcessorType", + "shortName": "get_processor_type" + }, + "description": "Sample for GetProcessorType", + "file": "documentai_v1beta3_generated_document_processor_service_get_processor_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "documentai_v1beta3_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_v1beta3_generated_document_processor_service_get_processor_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.get_processor_type", + "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.GetProcessorType", + "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", + "shortName": "DocumentProcessorService" + }, + "shortName": "GetProcessorType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.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_v1beta3.types.ProcessorType", + "shortName": "get_processor_type" + }, + "description": "Sample for GetProcessorType", + "file": "documentai_v1beta3_generated_document_processor_service_get_processor_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "documentai_v1beta3_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_v1beta3_generated_document_processor_service_get_processor_type_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/scripts/fixup_documentai_v1beta3_keywords.py b/scripts/fixup_documentai_v1beta3_keywords.py index 0cab2650..75ec155f 100644 --- a/scripts/fixup_documentai_v1beta3_keywords.py +++ b/scripts/fixup_documentai_v1beta3_keywords.py @@ -50,6 +50,7 @@ class documentaiCallTransformer(cst.CSTTransformer): 'fetch_processor_types': ('parent', ), 'get_evaluation': ('name', ), 'get_processor': ('name', ), + 'get_processor_type': ('name', ), 'get_processor_version': ('name', ), 'list_evaluations': ('parent', 'page_size', 'page_token', ), 'list_processors': ('parent', 'page_size', 'page_token', ), diff --git a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index 9d4c63ce..be4950f3 100644 --- a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1beta3/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, @@ -1902,6 +1903,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", [ @@ -6480,6 +6748,7 @@ def test_document_processor_service_base_transport(): "batch_process_documents", "fetch_processor_types", "list_processor_types", + "get_processor_type", "list_processors", "get_processor", "train_processor_version",