From 71f351b7da73015dff11fd81f33b27d40278a81d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 16 Mar 2023 12:44:11 +0000 Subject: [PATCH 1/3] chore(deps): Update nox in .kokoro/requirements.in [autoapprove] (#472) Source-Link: https://togithub.com/googleapis/synthtool/commit/92006bb3cdc84677aa93c7f5235424ec2b157146 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:2e247c7bf5154df7f98cce087a20ca7605e236340c7d6d1a14447e5c06791bd6 --- .github/.OwlBot.lock.yaml | 2 +- .kokoro/requirements.in | 2 +- .kokoro/requirements.txt | 14 +++++--------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 5fc5daa3..b8edda51 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,4 +13,4 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:8555f0e37e6261408f792bfd6635102d2da5ad73f8f09bcb24f25e6afb5fac97 + digest: sha256:2e247c7bf5154df7f98cce087a20ca7605e236340c7d6d1a14447e5c06791bd6 diff --git a/.kokoro/requirements.in b/.kokoro/requirements.in index 882178ce..ec867d9f 100644 --- a/.kokoro/requirements.in +++ b/.kokoro/requirements.in @@ -5,6 +5,6 @@ typing-extensions twine wheel setuptools -nox +nox>=2022.11.21 # required to remove dependency on py charset-normalizer<3 click<8.1.0 diff --git a/.kokoro/requirements.txt b/.kokoro/requirements.txt index fa99c129..66a2172a 100644 --- a/.kokoro/requirements.txt +++ b/.kokoro/requirements.txt @@ -1,6 +1,6 @@ # -# This file is autogenerated by pip-compile with python 3.10 -# To update, run: +# This file is autogenerated by pip-compile with Python 3.9 +# by the following command: # # pip-compile --allow-unsafe --generate-hashes requirements.in # @@ -335,9 +335,9 @@ more-itertools==9.0.0 \ --hash=sha256:250e83d7e81d0c87ca6bd942e6aeab8cc9daa6096d12c5308f3f92fa5e5c1f41 \ --hash=sha256:5a6257e40878ef0520b1803990e3e22303a41b5714006c32a3fd8304b26ea1ab # via jaraco-classes -nox==2022.8.7 \ - --hash=sha256:1b894940551dc5c389f9271d197ca5d655d40bdc6ccf93ed6880e4042760a34b \ - --hash=sha256:96cca88779e08282a699d672258ec01eb7c792d35bbbf538c723172bce23212c +nox==2022.11.21 \ + --hash=sha256:0e41a990e290e274cb205a976c4c97ee3c5234441a8132c8c3fd9ea3c22149eb \ + --hash=sha256:e21c31de0711d1274ca585a2c5fde36b1aa962005ba8e9322bf5eeed16dcd684 # via -r requirements.in packaging==21.3 \ --hash=sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb \ @@ -380,10 +380,6 @@ protobuf==3.20.3 \ # gcp-docuploader # gcp-releasetool # google-api-core -py==1.11.0 \ - --hash=sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719 \ - --hash=sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378 - # via nox pyasn1==0.4.8 \ --hash=sha256:39c7e2ec30515947ff4e87fb6f456dfc6e84857d34be479c9d4a4ba4bf46aa5d \ --hash=sha256:aef77c9fb94a3ac588e87841208bdec464471d9871bd5050a287cc9a475cd0ba From f3aa28574881e093d2e8432960e0a8bc24080ddb Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 24 Mar 2023 06:11:15 -0400 Subject: [PATCH 2/3] docs: Fix formatting of request arg in docstring (#473) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Update gapic-generator-python to v1.9.0 PiperOrigin-RevId: 517425588 Source-Link: https://github.com/googleapis/googleapis/commit/33c93eb8b4d3aaf88e44a1be197811052be62282 Source-Link: https://github.com/googleapis/googleapis-gen/commit/d5f59789d19fc43270ff2124967d4ec8992b8e8f Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDVmNTk3ODlkMTlmYzQzMjcwZmYyMTI0OTY3ZDRlYzg5OTJiOGU4ZiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: Add ImportProcessorVersion in v1beta3 PiperOrigin-RevId: 517997886 Source-Link: https://github.com/googleapis/googleapis/commit/ae3e6130091c0a9887d13d3b7261e2cfc15c466f Source-Link: https://github.com/googleapis/googleapis-gen/commit/a9e1daab141f302a3320478d22c07aa65b80d8eb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYTllMWRhYWIxNDFmMzAyYTMzMjA0NzhkMjJjMDdhYTY1YjgwZDhlYiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * docs: Fix formatting of request arg in docstring chore: Update gapic-generator-python to v1.9.1 PiperOrigin-RevId: 518604533 Source-Link: https://github.com/googleapis/googleapis/commit/8a085aeddfa010af5bcef090827aac5255383d7e Source-Link: https://github.com/googleapis/googleapis-gen/commit/b2ab4b0a0ae2907e812c209198a74e0898afcb04 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjJhYjRiMGEwYWUyOTA3ZTgxMmMyMDkxOThhNzRlMDg5OGFmY2IwNCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- .../async_client.py | 14 +- .../document_processor_service/client.py | 14 +- .../transports/rest.py | 19 - .../async_client.py | 6 +- .../document_understanding_service/client.py | 6 +- google/cloud/documentai_v1beta3/__init__.py | 6 + .../documentai_v1beta3/gapic_metadata.json | 15 + .../async_client.py | 147 ++++- .../document_processor_service/client.py | 149 ++++- .../transports/base.py | 14 + .../transports/grpc.py | 30 + .../transports/grpc_asyncio.py | 30 + .../transports/rest.py | 175 +++++- .../documentai_v1beta3/types/__init__.py | 6 + .../types/document_processor_service.py | 71 +++ ..._service_import_processor_version_async.py | 57 ++ ...r_service_import_processor_version_sync.py | 57 ++ ...t_metadata_google.cloud.documentai.v1.json | 2 +- ...adata_google.cloud.documentai.v1beta2.json | 2 +- ...adata_google.cloud.documentai.v1beta3.json | 163 +++++- scripts/fixup_documentai_v1beta3_keywords.py | 1 + testing/constraints-3.10.txt | 1 - testing/constraints-3.11.txt | 1 - testing/constraints-3.12.txt | 1 - testing/constraints-3.8.txt | 1 - testing/constraints-3.9.txt | 1 - .../test_document_processor_service.py | 514 ++++++++++++++++++ 27 files changed, 1427 insertions(+), 76 deletions(-) create mode 100644 samples/generated_samples/documentai_v1beta3_generated_document_processor_service_import_processor_version_async.py create mode 100644 samples/generated_samples/documentai_v1beta3_generated_document_processor_service_import_processor_version_sync.py 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 2360e046..3372ae56 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 @@ -1364,7 +1364,8 @@ async def sample_list_processor_versions(): Args: request (Optional[Union[google.cloud.documentai_v1.types.ListProcessorVersionsRequest, dict]]): The request object. Request message for list all - processor versions belongs to a processor. + processor versions belongs to a + processor. parent (:class:`str`): Required. The parent (project, location and processor) to list all versions. Format: @@ -1850,9 +1851,10 @@ async def sample_create_processor(): Args: request (Optional[Union[google.cloud.documentai_v1.types.CreateProcessorRequest, dict]]): The request object. Request message for create a - processor. Notice this request is sent to a regionalized - backend service, and if the processor type is not - available on that region, the creation will fail. + processor. Notice this request is sent + to a regionalized backend service, and + if the processor type is not available + on that region, the creation will fail. parent (:class:`str`): Required. The parent (project and location) under which to create the processor. Format: @@ -2764,8 +2766,8 @@ async def sample_list_evaluations(): Args: request (Optional[Union[google.cloud.documentai_v1.types.ListEvaluationsRequest, dict]]): - The request object. Retrieves a list of evaluations for - a given ProcessorVersion. + The request object. Retrieves a list of evaluations for a + given ProcessorVersion. parent (:class:`str`): Required. The resource name of the [ProcessorVersion][google.cloud.documentai.v1.ProcessorVersion] 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 e5c7e883..5b7fa897 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/client.py +++ b/google/cloud/documentai_v1/services/document_processor_service/client.py @@ -1646,7 +1646,8 @@ def sample_list_processor_versions(): Args: request (Union[google.cloud.documentai_v1.types.ListProcessorVersionsRequest, dict]): The request object. Request message for list all - processor versions belongs to a processor. + processor versions belongs to a + processor. parent (str): Required. The parent (project, location and processor) to list all versions. Format: @@ -2144,9 +2145,10 @@ def sample_create_processor(): Args: request (Union[google.cloud.documentai_v1.types.CreateProcessorRequest, dict]): The request object. Request message for create a - processor. Notice this request is sent to a regionalized - backend service, and if the processor type is not - available on that region, the creation will fail. + processor. Notice this request is sent + to a regionalized backend service, and + if the processor type is not available + on that region, the creation will fail. parent (str): Required. The parent (project and location) under which to create the processor. Format: @@ -3063,8 +3065,8 @@ def sample_list_evaluations(): Args: request (Union[google.cloud.documentai_v1.types.ListEvaluationsRequest, dict]): - The request object. Retrieves a list of evaluations for - a given ProcessorVersion. + The request object. Retrieves a list of evaluations for a + given ProcessorVersion. parent (str): Required. The resource name of the [ProcessorVersion][google.cloud.documentai.v1.ProcessorVersion] diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py b/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py index 5c742266..a6f8bf1d 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py @@ -1116,7 +1116,6 @@ def __call__( request (~.document_processor_service.BatchProcessRequest): The request object. Request message for batch process document method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1224,7 +1223,6 @@ def __call__( to a regionalized backend service, and if the processor type is not available on that region, the creation will fail. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1327,7 +1325,6 @@ def __call__( request (~.document_processor_service.DeleteProcessorRequest): The request object. Request message for the delete processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1418,7 +1415,6 @@ def __call__( request (~.document_processor_service.DeleteProcessorVersionRequest): The request object. Request message for the delete processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1511,7 +1507,6 @@ def __call__( request (~.document_processor_service.DeployProcessorVersionRequest): The request object. Request message for the deploy processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1613,7 +1608,6 @@ def __call__( request (~.document_processor_service.DisableProcessorRequest): The request object. Request message for the disable processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1713,7 +1707,6 @@ def __call__( request (~.document_processor_service.EnableProcessorRequest): The request object. Request message for the enable processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1814,7 +1807,6 @@ def __call__( request (~.document_processor_service.EvaluateProcessorVersionRequest): The request object. Evaluates the given ProcessorVersion against the supplied documents. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1916,7 +1908,6 @@ def __call__( request (~.document_processor_service.FetchProcessorTypesRequest): The request object. Request message for fetch processor types. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2280,7 +2271,6 @@ def __call__( request (~.document_processor_service.GetProcessorVersionRequest): The request object. Request message for get processor version. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2381,7 +2371,6 @@ def __call__( request (~.document_processor_service.ListEvaluationsRequest): The request object. Retrieves a list of evaluations for a given ProcessorVersion. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2471,7 +2460,6 @@ def __call__( request (~.document_processor_service.ListProcessorsRequest): The request object. Request message for list all processors belongs to a project. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2559,7 +2547,6 @@ def __call__( request (~.document_processor_service.ListProcessorTypesRequest): The request object. Request message for list processor types. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2654,7 +2641,6 @@ def __call__( The request object. Request message for list all processor versions belongs to a processor. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2746,7 +2732,6 @@ def __call__( request (~.document_processor_service.ProcessRequest): The request object. Request message for the process document method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2852,7 +2837,6 @@ def __call__( request (~.document_processor_service.ReviewDocumentRequest): The request object. Request message for review document method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2951,7 +2935,6 @@ def __call__( request (~.document_processor_service.SetDefaultProcessorVersionRequest): The request object. Request message for the set default processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -3053,7 +3036,6 @@ def __call__( request (~.document_processor_service.TrainProcessorVersionRequest): The request object. Request message for the create processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -3156,7 +3138,6 @@ def __call__( request (~.document_processor_service.UndeployProcessorVersionRequest): The request object. Request message for the undeploy processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py index 6d836f08..786d2ab2 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py @@ -277,9 +277,9 @@ async def sample_batch_process_documents(): Args: request (Optional[Union[google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest, dict]]): - The request object. Request to batch process documents - as an asynchronous operation. The output is written to - Cloud Storage as JSON in the [Document] format. + The request object. Request to batch process documents as an asynchronous + operation. The output is written to Cloud Storage as + JSON in the [Document] format. requests (:class:`MutableSequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]`): Required. Individual requests for each document. diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py index 1e1496e9..872ced65 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py @@ -481,9 +481,9 @@ def sample_batch_process_documents(): Args: request (Union[google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest, dict]): - The request object. Request to batch process documents - as an asynchronous operation. The output is written to - Cloud Storage as JSON in the [Document] format. + The request object. Request to batch process documents as an asynchronous + operation. The output is written to Cloud Storage as + JSON in the [Document] format. requests (MutableSequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]): Required. Individual requests for each document. diff --git a/google/cloud/documentai_v1beta3/__init__.py b/google/cloud/documentai_v1beta3/__init__.py index 7067ada4..5ca9c959 100644 --- a/google/cloud/documentai_v1beta3/__init__.py +++ b/google/cloud/documentai_v1beta3/__init__.py @@ -61,6 +61,9 @@ GetProcessorTypeRequest, GetProcessorVersionRequest, HumanReviewStatus, + ImportProcessorVersionMetadata, + ImportProcessorVersionRequest, + ImportProcessorVersionResponse, ListEvaluationsRequest, ListEvaluationsResponse, ListProcessorsRequest, @@ -134,6 +137,9 @@ "GetProcessorTypeRequest", "GetProcessorVersionRequest", "HumanReviewStatus", + "ImportProcessorVersionMetadata", + "ImportProcessorVersionRequest", + "ImportProcessorVersionResponse", "ListEvaluationsRequest", "ListEvaluationsResponse", "ListProcessorTypesRequest", diff --git a/google/cloud/documentai_v1beta3/gapic_metadata.json b/google/cloud/documentai_v1beta3/gapic_metadata.json index 95c46773..bf1c66e3 100644 --- a/google/cloud/documentai_v1beta3/gapic_metadata.json +++ b/google/cloud/documentai_v1beta3/gapic_metadata.json @@ -75,6 +75,11 @@ "get_processor_version" ] }, + "ImportProcessorVersion": { + "methods": [ + "import_processor_version" + ] + }, "ListEvaluations": { "methods": [ "list_evaluations" @@ -190,6 +195,11 @@ "get_processor_version" ] }, + "ImportProcessorVersion": { + "methods": [ + "import_processor_version" + ] + }, "ListEvaluations": { "methods": [ "list_evaluations" @@ -305,6 +315,11 @@ "get_processor_version" ] }, + "ImportProcessorVersion": { + "methods": [ + "import_processor_version" + ] + }, "ListEvaluations": { "methods": [ "list_evaluations" 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 e8f34179..d7aca41c 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 @@ -1366,7 +1366,8 @@ async def sample_list_processor_versions(): Args: request (Optional[Union[google.cloud.documentai_v1beta3.types.ListProcessorVersionsRequest, dict]]): The request object. Request message for list all - processor versions belongs to a processor. + processor versions belongs to a + processor. parent (:class:`str`): Required. The parent (project, location and processor) to list all versions. Format: @@ -1852,9 +1853,10 @@ async def sample_create_processor(): Args: request (Optional[Union[google.cloud.documentai_v1beta3.types.CreateProcessorRequest, dict]]): The request object. Request message for create a - processor. Notice this request is sent to a regionalized - backend service, and if the processor type is not - available on that region, the creation will fail. + processor. Notice this request is sent + to a regionalized backend service, and + if the processor type is not available + on that region, the creation will fail. parent (:class:`str`): Required. The parent (project and location) under which to create the processor. Format: @@ -2766,8 +2768,8 @@ async def sample_list_evaluations(): Args: request (Optional[Union[google.cloud.documentai_v1beta3.types.ListEvaluationsRequest, dict]]): - The request object. Retrieves a list of evaluations for - a given ProcessorVersion. + The request object. Retrieves a list of evaluations for a + given ProcessorVersion. parent (:class:`str`): Required. The resource name of the [ProcessorVersion][google.cloud.documentai.v1beta3.ProcessorVersion] @@ -2842,6 +2844,139 @@ async def sample_list_evaluations(): # Done; return the response. return response + async def import_processor_version( + self, + request: Optional[ + Union[document_processor_service.ImportProcessorVersionRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Imports a processor version from source processor + version. + + .. 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_import_processor_version(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() + + # Initialize request argument(s) + request = documentai_v1beta3.ImportProcessorVersionRequest( + processor_version_source="processor_version_source_value", + parent="parent_value", + ) + + # Make the request + operation = client.import_processor_version(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.documentai_v1beta3.types.ImportProcessorVersionRequest, dict]]): + The request object. The request message for the ImportProcessorVersion + method. This method requires Document AI Service Agent + of the destination project in the source project's IAM + with `Document AI Editor + role `__. + + The destination project is specified as part of the + ``parent`` field. The source project is specified as + part of ``source`` field. + + The Service Agent for Document AI can be found in + https://cloud.google.com/iam/docs/service-agents. + parent (:class:`str`): + Required. The destination processor name to create the + processor version in. Format: + ``projects/{project}/locations/{location}/processors/{processor}`` + + 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, str]]): Strings which should be + sent along with the request as metadata. + + 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.documentai_v1beta3.types.ImportProcessorVersionResponse` + The response message for the ImportProcessorVersion + method. + + """ + # 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([parent]) + 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.ImportProcessorVersionRequest(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 = gapic_v1.method_async.wrap_method( + self._client._transport.import_processor_version, + 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((("parent", request.parent),)), + ) + + # 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, + document_processor_service.ImportProcessorVersionResponse, + metadata_type=document_processor_service.ImportProcessorVersionMetadata, + ) + + # Done; return the response. + return response + async def list_operations( self, request: Optional[operations_pb2.ListOperationsRequest] = None, 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 21585c91..3f915d37 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/client.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/client.py @@ -1648,7 +1648,8 @@ def sample_list_processor_versions(): Args: request (Union[google.cloud.documentai_v1beta3.types.ListProcessorVersionsRequest, dict]): The request object. Request message for list all - processor versions belongs to a processor. + processor versions belongs to a + processor. parent (str): Required. The parent (project, location and processor) to list all versions. Format: @@ -2146,9 +2147,10 @@ def sample_create_processor(): Args: request (Union[google.cloud.documentai_v1beta3.types.CreateProcessorRequest, dict]): The request object. Request message for create a - processor. Notice this request is sent to a regionalized - backend service, and if the processor type is not - available on that region, the creation will fail. + processor. Notice this request is sent + to a regionalized backend service, and + if the processor type is not available + on that region, the creation will fail. parent (str): Required. The parent (project and location) under which to create the processor. Format: @@ -3065,8 +3067,8 @@ def sample_list_evaluations(): Args: request (Union[google.cloud.documentai_v1beta3.types.ListEvaluationsRequest, dict]): - The request object. Retrieves a list of evaluations for - a given ProcessorVersion. + The request object. Retrieves a list of evaluations for a + given ProcessorVersion. parent (str): Required. The resource name of the [ProcessorVersion][google.cloud.documentai.v1beta3.ProcessorVersion] @@ -3141,6 +3143,141 @@ def sample_list_evaluations(): # Done; return the response. return response + def import_processor_version( + self, + request: Optional[ + Union[document_processor_service.ImportProcessorVersionRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Imports a processor version from source processor + version. + + .. 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_import_processor_version(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.ImportProcessorVersionRequest( + processor_version_source="processor_version_source_value", + parent="parent_value", + ) + + # Make the request + operation = client.import_processor_version(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.documentai_v1beta3.types.ImportProcessorVersionRequest, dict]): + The request object. The request message for the ImportProcessorVersion + method. This method requires Document AI Service Agent + of the destination project in the source project's IAM + with `Document AI Editor + role `__. + + The destination project is specified as part of the + ``parent`` field. The source project is specified as + part of ``source`` field. + + The Service Agent for Document AI can be found in + https://cloud.google.com/iam/docs/service-agents. + parent (str): + Required. The destination processor name to create the + processor version in. Format: + ``projects/{project}/locations/{location}/processors/{processor}`` + + 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, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1beta3.types.ImportProcessorVersionResponse` + The response message for the ImportProcessorVersion + method. + + """ + # 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([parent]) + 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.ImportProcessorVersionRequest. + # 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.ImportProcessorVersionRequest + ): + request = document_processor_service.ImportProcessorVersionRequest(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.import_processor_version] + + # 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),)), + ) + + # 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, + document_processor_service.ImportProcessorVersionResponse, + metadata_type=document_processor_service.ImportProcessorVersionMetadata, + ) + + # Done; return the response. + return response + def __enter__(self) -> "DocumentProcessorServiceClient": return self 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 1e9f1f7a..2f5928b0 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 @@ -267,6 +267,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.import_processor_version: gapic_v1.method.wrap_method( + self.import_processor_version, + default_timeout=None, + client_info=client_info, + ), } def close(self): @@ -499,6 +504,15 @@ def list_evaluations( ]: raise NotImplementedError() + @property + def import_processor_version( + self, + ) -> Callable[ + [document_processor_service.ImportProcessorVersionRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def list_operations( 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 47c8a1b1..4166a7de 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 @@ -900,6 +900,36 @@ def list_evaluations( ) return self._stubs["list_evaluations"] + @property + def import_processor_version( + self, + ) -> Callable[ + [document_processor_service.ImportProcessorVersionRequest], + operations_pb2.Operation, + ]: + r"""Return a callable for the import processor version method over gRPC. + + Imports a processor version from source processor + version. + + Returns: + Callable[[~.ImportProcessorVersionRequest], + ~.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 "import_processor_version" not in self._stubs: + self._stubs["import_processor_version"] = self.grpc_channel.unary_unary( + "/google.cloud.documentai.v1beta3.DocumentProcessorService/ImportProcessorVersion", + request_serializer=document_processor_service.ImportProcessorVersionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["import_processor_version"] + def close(self): self.grpc_channel.close() 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 b6281f19..7e0421a9 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 @@ -912,6 +912,36 @@ def list_evaluations( ) return self._stubs["list_evaluations"] + @property + def import_processor_version( + self, + ) -> Callable[ + [document_processor_service.ImportProcessorVersionRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the import processor version method over gRPC. + + Imports a processor version from source processor + version. + + Returns: + Callable[[~.ImportProcessorVersionRequest], + 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 "import_processor_version" not in self._stubs: + self._stubs["import_processor_version"] = self.grpc_channel.unary_unary( + "/google.cloud.documentai.v1beta3.DocumentProcessorService/ImportProcessorVersion", + request_serializer=document_processor_service.ImportProcessorVersionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["import_processor_version"] + def close(self): return self.grpc_channel.close() diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py index 21dd9be2..416be1e4 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py @@ -180,6 +180,14 @@ def post_get_processor_version(self, response): logging.log(f"Received response: {response}") return response + def pre_import_processor_version(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_import_processor_version(self, response): + logging.log(f"Received response: {response}") + return response + def pre_list_evaluations(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -584,6 +592,32 @@ def post_get_processor_version( """ return response + def pre_import_processor_version( + self, + request: document_processor_service.ImportProcessorVersionRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + document_processor_service.ImportProcessorVersionRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for import_processor_version + + Override in a subclass to manipulate the request or metadata + before they are sent to the DocumentProcessorService server. + """ + return request, metadata + + def post_import_processor_version( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for import_processor_version + + Override in a subclass to manipulate the response + after it is returned by the DocumentProcessorService server but before + it is returned to user code. + """ + return response + def pre_list_evaluations( self, request: document_processor_service.ListEvaluationsRequest, @@ -1112,7 +1146,6 @@ def __call__( request (~.document_processor_service.BatchProcessRequest): The request object. Request message for batch process document method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1220,7 +1253,6 @@ def __call__( to a regionalized backend service, and if the processor type is not available on that region, the creation will fail. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1323,7 +1355,6 @@ def __call__( request (~.document_processor_service.DeleteProcessorRequest): The request object. Request message for the delete processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1414,7 +1445,6 @@ def __call__( request (~.document_processor_service.DeleteProcessorVersionRequest): The request object. Request message for the delete processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1507,7 +1537,6 @@ def __call__( request (~.document_processor_service.DeployProcessorVersionRequest): The request object. Request message for the deploy processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1609,7 +1638,6 @@ def __call__( request (~.document_processor_service.DisableProcessorRequest): The request object. Request message for the disable processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1709,7 +1737,6 @@ def __call__( request (~.document_processor_service.EnableProcessorRequest): The request object. Request message for the enable processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1810,7 +1837,6 @@ def __call__( request (~.document_processor_service.EvaluateProcessorVersionRequest): The request object. Evaluates the given ProcessorVersion against the supplied documents. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1912,7 +1938,6 @@ def __call__( request (~.document_processor_service.FetchProcessorTypesRequest): The request object. Request message for fetch processor types. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2276,7 +2301,6 @@ def __call__( request (~.document_processor_service.GetProcessorVersionRequest): The request object. Request message for get processor version. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2349,6 +2373,117 @@ def __call__( resp = self._interceptor.post_get_processor_version(resp) return resp + class _ImportProcessorVersion(DocumentProcessorServiceRestStub): + def __hash__(self): + return hash("ImportProcessorVersion") + + __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 + } + + def __call__( + self, + request: document_processor_service.ImportProcessorVersionRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Call the import processor version method over HTTP. + + Args: + request (~.document_processor_service.ImportProcessorVersionRequest): + The request object. The request message for the ImportProcessorVersion + method. This method requires Document AI Service Agent + of the destination project in the source project's IAM + with `Document AI Editor + role `__. + + The destination project is specified as part of the + ``parent`` field. The source project is specified as + part of ``source`` field. + + The Service Agent for Document AI can be found in + https://cloud.google.com/iam/docs/service-agents. + 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: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1beta3/{parent=projects/*/locations/*/processors/*}/processorVersions:importProcessorVersion", + "body": "*", + }, + ] + request, metadata = self._interceptor.pre_import_processor_version( + request, metadata + ) + pb_request = document_processor_service.ImportProcessorVersionRequest.pb( + request + ) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=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_import_processor_version(resp) + return resp + class _ListEvaluations(DocumentProcessorServiceRestStub): def __hash__(self): return hash("ListEvaluations") @@ -2377,7 +2512,6 @@ def __call__( request (~.document_processor_service.ListEvaluationsRequest): The request object. Retrieves a list of evaluations for a given ProcessorVersion. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2467,7 +2601,6 @@ def __call__( request (~.document_processor_service.ListProcessorsRequest): The request object. Request message for list all processors belongs to a project. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2555,7 +2688,6 @@ def __call__( request (~.document_processor_service.ListProcessorTypesRequest): The request object. Request message for list processor types. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2650,7 +2782,6 @@ def __call__( The request object. Request message for list all processor versions belongs to a processor. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2742,7 +2873,6 @@ def __call__( request (~.document_processor_service.ProcessRequest): The request object. Request message for the process document method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2848,7 +2978,6 @@ def __call__( request (~.document_processor_service.ReviewDocumentRequest): The request object. Request message for review document method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2947,7 +3076,6 @@ def __call__( request (~.document_processor_service.SetDefaultProcessorVersionRequest): The request object. Request message for the set default processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -3049,7 +3177,6 @@ def __call__( request (~.document_processor_service.TrainProcessorVersionRequest): The request object. Request message for the create processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -3152,7 +3279,6 @@ def __call__( request (~.document_processor_service.UndeployProcessorVersionRequest): The request object. Request message for the undeploy processor version method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -3362,6 +3488,17 @@ def get_processor_version( # In C++ this would require a dynamic_cast return self._GetProcessorVersion(self._session, self._host, self._interceptor) # type: ignore + @property + def import_processor_version( + self, + ) -> Callable[ + [document_processor_service.ImportProcessorVersionRequest], + 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._ImportProcessorVersion(self._session, self._host, self._interceptor) # type: ignore + @property def list_evaluations( self, diff --git a/google/cloud/documentai_v1beta3/types/__init__.py b/google/cloud/documentai_v1beta3/types/__init__.py index 641aeb56..24b33af3 100644 --- a/google/cloud/documentai_v1beta3/types/__init__.py +++ b/google/cloud/documentai_v1beta3/types/__init__.py @@ -52,6 +52,9 @@ GetProcessorTypeRequest, GetProcessorVersionRequest, HumanReviewStatus, + ImportProcessorVersionMetadata, + ImportProcessorVersionRequest, + ImportProcessorVersionResponse, ListEvaluationsRequest, ListEvaluationsResponse, ListProcessorsRequest, @@ -120,6 +123,9 @@ "GetProcessorTypeRequest", "GetProcessorVersionRequest", "HumanReviewStatus", + "ImportProcessorVersionMetadata", + "ImportProcessorVersionRequest", + "ImportProcessorVersionResponse", "ListEvaluationsRequest", "ListEvaluationsResponse", "ListProcessorsRequest", diff --git a/google/cloud/documentai_v1beta3/types/document_processor_service.py b/google/cloud/documentai_v1beta3/types/document_processor_service.py index fd06499a..1a08c915 100644 --- a/google/cloud/documentai_v1beta3/types/document_processor_service.py +++ b/google/cloud/documentai_v1beta3/types/document_processor_service.py @@ -83,6 +83,9 @@ "GetEvaluationRequest", "ListEvaluationsRequest", "ListEvaluationsResponse", + "ImportProcessorVersionRequest", + "ImportProcessorVersionResponse", + "ImportProcessorVersionMetadata", }, ) @@ -1541,4 +1544,72 @@ def raw_page(self): ) +class ImportProcessorVersionRequest(proto.Message): + r"""The request message for the ImportProcessorVersion method. This + method requires Document AI Service Agent of the destination project + in the source project's IAM with `Document AI Editor + role `__. + + The destination project is specified as part of the ``parent`` + field. The source project is specified as part of ``source`` field. + + The Service Agent for Document AI can be found in + https://cloud.google.com/iam/docs/service-agents. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + processor_version_source (str): + The source processor version to import from. + + This field is a member of `oneof`_ ``source``. + parent (str): + Required. The destination processor name to create the + processor version in. Format: + ``projects/{project}/locations/{location}/processors/{processor}`` + """ + + processor_version_source: str = proto.Field( + proto.STRING, + number=2, + oneof="source", + ) + parent: str = proto.Field( + proto.STRING, + number=1, + ) + + +class ImportProcessorVersionResponse(proto.Message): + r"""The response message for the ImportProcessorVersion method. + + Attributes: + processor_version (str): + The destination processor version name. + """ + + processor_version: str = proto.Field( + proto.STRING, + number=1, + ) + + +class ImportProcessorVersionMetadata(proto.Message): + r"""The long running operation metadata for the + ImportProcessorVersion method. + + Attributes: + common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): + The basic metadata for the long running + operation. + """ + + common_metadata: operation_metadata.CommonOperationMetadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation_metadata.CommonOperationMetadata, + ) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_import_processor_version_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_import_processor_version_async.py new file mode 100644 index 00000000..5f6c055f --- /dev/null +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_import_processor_version_async.py @@ -0,0 +1,57 @@ +# -*- 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 ImportProcessorVersion +# 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_ImportProcessorVersion_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_import_processor_version(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() + + # Initialize request argument(s) + request = documentai_v1beta3.ImportProcessorVersionRequest( + processor_version_source="processor_version_source_value", + parent="parent_value", + ) + + # Make the request + operation = client.import_processor_version(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END documentai_v1beta3_generated_DocumentProcessorService_ImportProcessorVersion_async] diff --git a/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_import_processor_version_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_import_processor_version_sync.py new file mode 100644 index 00000000..261ff1fe --- /dev/null +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_import_processor_version_sync.py @@ -0,0 +1,57 @@ +# -*- 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 ImportProcessorVersion +# 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_ImportProcessorVersion_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_import_processor_version(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.ImportProcessorVersionRequest( + processor_version_source="processor_version_source_value", + parent="parent_value", + ) + + # Make the request + operation = client.import_processor_version(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END documentai_v1beta3_generated_DocumentProcessorService_ImportProcessorVersion_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 8adb0fef..96d60af2 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.14.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 b90fba04..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.14.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 b8da17bf..7b608dee 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.14.0" + "version": "0.1.0" }, "snippets": [ { @@ -2096,6 +2096,167 @@ ], "title": "documentai_v1beta3_generated_document_processor_service_get_processor_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.import_processor_version", + "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.ImportProcessorVersion", + "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", + "shortName": "DocumentProcessorService" + }, + "shortName": "ImportProcessorVersion" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.ImportProcessorVersionRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "import_processor_version" + }, + "description": "Sample for ImportProcessorVersion", + "file": "documentai_v1beta3_generated_document_processor_service_import_processor_version_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ImportProcessorVersion_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "documentai_v1beta3_generated_document_processor_service_import_processor_version_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.import_processor_version", + "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.ImportProcessorVersion", + "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", + "shortName": "DocumentProcessorService" + }, + "shortName": "ImportProcessorVersion" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.ImportProcessorVersionRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "import_processor_version" + }, + "description": "Sample for ImportProcessorVersion", + "file": "documentai_v1beta3_generated_document_processor_service_import_processor_version_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ImportProcessorVersion_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "documentai_v1beta3_generated_document_processor_service_import_processor_version_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/scripts/fixup_documentai_v1beta3_keywords.py b/scripts/fixup_documentai_v1beta3_keywords.py index 75ec155f..44cd7958 100644 --- a/scripts/fixup_documentai_v1beta3_keywords.py +++ b/scripts/fixup_documentai_v1beta3_keywords.py @@ -52,6 +52,7 @@ class documentaiCallTransformer(cst.CSTTransformer): 'get_processor': ('name', ), 'get_processor_type': ('name', ), 'get_processor_version': ('name', ), + 'import_processor_version': ('parent', 'processor_version_source', ), 'list_evaluations': ('parent', 'page_size', 'page_token', ), 'list_processors': ('parent', 'page_size', 'page_token', ), 'list_processor_types': ('parent', 'page_size', 'page_token', ), diff --git a/testing/constraints-3.10.txt b/testing/constraints-3.10.txt index 45ffc899..ed7f9aed 100644 --- a/testing/constraints-3.10.txt +++ b/testing/constraints-3.10.txt @@ -4,4 +4,3 @@ google-api-core proto-plus protobuf -google-cloud-documentai diff --git a/testing/constraints-3.11.txt b/testing/constraints-3.11.txt index 45ffc899..ed7f9aed 100644 --- a/testing/constraints-3.11.txt +++ b/testing/constraints-3.11.txt @@ -4,4 +4,3 @@ google-api-core proto-plus protobuf -google-cloud-documentai diff --git a/testing/constraints-3.12.txt b/testing/constraints-3.12.txt index 45ffc899..ed7f9aed 100644 --- a/testing/constraints-3.12.txt +++ b/testing/constraints-3.12.txt @@ -4,4 +4,3 @@ google-api-core proto-plus protobuf -google-cloud-documentai diff --git a/testing/constraints-3.8.txt b/testing/constraints-3.8.txt index 45ffc899..ed7f9aed 100644 --- a/testing/constraints-3.8.txt +++ b/testing/constraints-3.8.txt @@ -4,4 +4,3 @@ google-api-core proto-plus protobuf -google-cloud-documentai diff --git a/testing/constraints-3.9.txt b/testing/constraints-3.9.txt index 45ffc899..ed7f9aed 100644 --- a/testing/constraints-3.9.txt +++ b/testing/constraints-3.9.txt @@ -4,4 +4,3 @@ google-api-core proto-plus protobuf -google-cloud-documentai 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 6e61b4e7..d4fd2380 100644 --- a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -6652,6 +6652,247 @@ async def test_list_evaluations_async_pages(): assert page_.raw_page.next_page_token == token +@pytest.mark.parametrize( + "request_type", + [ + document_processor_service.ImportProcessorVersionRequest, + dict, + ], +) +def test_import_processor_version(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.import_processor_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.import_processor_version(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.ImportProcessorVersionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_import_processor_version_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.import_processor_version), "__call__" + ) as call: + client.import_processor_version() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ImportProcessorVersionRequest() + + +@pytest.mark.asyncio +async def test_import_processor_version_async( + transport: str = "grpc_asyncio", + request_type=document_processor_service.ImportProcessorVersionRequest, +): + 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.import_processor_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") + ) + response = await client.import_processor_version(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.ImportProcessorVersionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_import_processor_version_async_from_dict(): + await test_import_processor_version_async(request_type=dict) + + +def test_import_processor_version_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.ImportProcessorVersionRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_processor_version), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.import_processor_version(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", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_import_processor_version_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.ImportProcessorVersionRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_processor_version), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.import_processor_version(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_import_processor_version_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.import_processor_version), "__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.import_processor_version( + parent="parent_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].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_import_processor_version_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.import_processor_version( + document_processor_service.ImportProcessorVersionRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_import_processor_version_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.import_processor_version), "__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.import_processor_version( + parent="parent_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 + + +@pytest.mark.asyncio +async def test_import_processor_version_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.import_processor_version( + document_processor_service.ImportProcessorVersionRequest(), + parent="parent_value", + ) + + @pytest.mark.parametrize( "request_type", [ @@ -12880,6 +13121,275 @@ def test_list_evaluations_rest_pager(transport: str = "rest"): assert page_.raw_page.next_page_token == token +@pytest.mark.parametrize( + "request_type", + [ + document_processor_service.ImportProcessorVersionRequest, + dict, + ], +) +def test_import_processor_version_rest(request_type): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/processors/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") + + # 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 + response = client.import_processor_version(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_import_processor_version_rest_required_fields( + request_type=document_processor_service.ImportProcessorVersionRequest, +): + transport_class = transports.DocumentProcessorServiceRestTransport + + 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, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).import_processor_version._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() + ).import_processor_version._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" + + client = DocumentProcessorServiceClient( + 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 + + 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 + + response = client.import_processor_version(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_import_processor_version_rest_unset_required_fields(): + transport = transports.DocumentProcessorServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.import_processor_version._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("parent",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_import_processor_version_rest_interceptors(null_interceptor): + transport = transports.DocumentProcessorServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.DocumentProcessorServiceRestInterceptor(), + ) + client = DocumentProcessorServiceClient(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.DocumentProcessorServiceRestInterceptor, + "post_import_processor_version", + ) as post, mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_import_processor_version", + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = document_processor_service.ImportProcessorVersionRequest.pb( + document_processor_service.ImportProcessorVersionRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) + + request = document_processor_service.ImportProcessorVersionRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.import_processor_version( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_import_processor_version_rest_bad_request( + transport: str = "rest", + request_type=document_processor_service.ImportProcessorVersionRequest, +): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/processors/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 = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.import_processor_version(request) + + +def test_import_processor_version_rest_flattened(): + client = DocumentProcessorServiceClient( + 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 = { + "parent": "projects/sample1/locations/sample2/processors/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_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 + + client.import_processor_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/v1beta3/{parent=projects/*/locations/*/processors/*}/processorVersions:importProcessorVersion" + % client.transport._host, + args[1], + ) + + +def test_import_processor_version_rest_flattened_error(transport: str = "rest"): + client = DocumentProcessorServiceClient( + 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.import_processor_version( + document_processor_service.ImportProcessorVersionRequest(), + parent="parent_value", + ) + + +def test_import_processor_version_rest_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( @@ -13041,6 +13551,7 @@ def test_document_processor_service_base_transport(): "evaluate_processor_version", "get_evaluation", "list_evaluations", + "import_processor_version", "get_location", "list_locations", "get_operation", @@ -13396,6 +13907,9 @@ def test_document_processor_service_client_transport_session_collision(transport session1 = client1.transport.list_evaluations._session session2 = client2.transport.list_evaluations._session assert session1 != session2 + session1 = client1.transport.import_processor_version._session + session2 = client2.transport.import_processor_version._session + assert session1 != session2 def test_document_processor_service_grpc_transport_channel(): From 20e6079207ce08c18b739f55b092e8984183f450 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Fri, 24 Mar 2023 09:57:41 -0500 Subject: [PATCH 3/3] chore(main): release 2.15.0 (#474) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- .release-please-manifest.json | 2 +- CHANGELOG.md | 12 ++++++++++++ google/cloud/documentai/gapic_version.py | 2 +- google/cloud/documentai_v1/gapic_version.py | 2 +- google/cloud/documentai_v1beta2/gapic_version.py | 2 +- google/cloud/documentai_v1beta3/gapic_version.py | 2 +- .../snippet_metadata_google.cloud.documentai.v1.json | 2 +- ...pet_metadata_google.cloud.documentai.v1beta2.json | 2 +- ...pet_metadata_google.cloud.documentai.v1beta3.json | 2 +- 9 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 109b6d3c..fcc47ff7 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.14.0" + ".": "2.15.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index a1213ad8..9b5b87e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [2.15.0](https://github.com/googleapis/python-documentai/compare/v2.14.0...v2.15.0) (2023-03-24) + + +### Features + +* **v1beta3:** Add ImportProcessorVersion ([f3aa285](https://github.com/googleapis/python-documentai/commit/f3aa28574881e093d2e8432960e0a8bc24080ddb)) + + +### Documentation + +* Fix formatting of request arg in docstring ([f3aa285](https://github.com/googleapis/python-documentai/commit/f3aa28574881e093d2e8432960e0a8bc24080ddb)) + ## [2.14.0](https://github.com/googleapis/python-documentai/compare/v2.13.0...v2.14.0) (2023-03-09) diff --git a/google/cloud/documentai/gapic_version.py b/google/cloud/documentai/gapic_version.py index 8be00290..2788e5e5 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.14.0" # {x-release-please-version} +__version__ = "2.15.0" # {x-release-please-version} diff --git a/google/cloud/documentai_v1/gapic_version.py b/google/cloud/documentai_v1/gapic_version.py index 8be00290..2788e5e5 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.14.0" # {x-release-please-version} +__version__ = "2.15.0" # {x-release-please-version} diff --git a/google/cloud/documentai_v1beta2/gapic_version.py b/google/cloud/documentai_v1beta2/gapic_version.py index 8be00290..2788e5e5 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.14.0" # {x-release-please-version} +__version__ = "2.15.0" # {x-release-please-version} diff --git a/google/cloud/documentai_v1beta3/gapic_version.py b/google/cloud/documentai_v1beta3/gapic_version.py index 8be00290..2788e5e5 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.14.0" # {x-release-please-version} +__version__ = "2.15.0" # {x-release-please-version} 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 96d60af2..95100d45 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": "0.1.0" + "version": "2.15.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 ef56bd7e..b92b9049 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": "0.1.0" + "version": "2.15.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 7b608dee..35eb436f 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": "0.1.0" + "version": "2.15.0" }, "snippets": [ {