diff --git a/document_ai/snippets/batch_process_documents_sample.py b/document_ai/snippets/batch_process_documents_sample.py index ec335b814d41..f3e0193620f9 100644 --- a/document_ai/snippets/batch_process_documents_sample.py +++ b/document_ai/snippets/batch_process_documents_sample.py @@ -17,13 +17,13 @@ import re from google.api_core.client_options import ClientOptions -from google.cloud import documentai_v1 as documentai -from google.cloud import storage +from google.cloud import documentai, storage # TODO(developer): Uncomment these variables before running the sample. # project_id = 'YOUR_PROJECT_ID' # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' -# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console +# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample +# processor_version = "pretrained" # Optional. Processor version to use # gcs_input_uri = "YOUR_INPUT_URI" # Format: gs://bucket/directory/file.pdf # input_mime_type = "application/pdf" # gcs_output_bucket = "YOUR_OUTPUT_BUCKET_NAME" # Format: gs://bucket @@ -76,6 +76,14 @@ def batch_process_documents( # You must create new processors in the Cloud Console first name = client.processor_path(project_id, location, processor_id) + # NOTE: Alternatively, specify the processor_version to specify a particular version of the processor to use + # projects/{project_id}/locations/{location}/processors/{processor_id}/processorVersions/{processorVersion} + # + # name = client.processor_version_path( + # project_id, location, processor_id, processor_version + # ) + # + request = documentai.BatchProcessRequest( name=name, input_documents=input_config, diff --git a/document_ai/snippets/batch_process_documents_sample_bad_input_test.py b/document_ai/snippets/batch_process_documents_sample_bad_input_test.py index 20e1fb1cb7ce..7d2ffd75eb05 100644 --- a/document_ai/snippets/batch_process_documents_sample_bad_input_test.py +++ b/document_ai/snippets/batch_process_documents_sample_bad_input_test.py @@ -42,6 +42,6 @@ def test_batch_process_documents_with_bad_input(capsys): timeout=450, ) out, _ = capsys.readouterr() - assert "Failed to process" in out + assert "Failed" in out except Exception as e: - assert "Failed to process" in e.message + assert "Internal error" in e.message diff --git a/document_ai/snippets/cancel_operation_sample.py b/document_ai/snippets/cancel_operation_sample.py new file mode 100644 index 000000000000..c5797d6eb3a3 --- /dev/null +++ b/document_ai/snippets/cancel_operation_sample.py @@ -0,0 +1,44 @@ +# 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. +# + +# [START documentai_cancel_operation] + +from google.api_core.client_options import ClientOptions +from google.api_core.exceptions import FailedPrecondition, NotFound +from google.cloud import documentai +from google.longrunning.operations_pb2 import CancelOperationRequest + +# TODO(developer): Uncomment these variables before running the sample. +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' +# operation_name = 'YOUR_OPERATION_NAME' # Format is 'projects/project_id/locations/location/operations/operation_id' + + +def cancel_operation_sample(location: str, operation_name: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + request = CancelOperationRequest(name=operation_name) + + # Make CancelOperation request + try: + client.cancel_operation(request=request) + print(f"Operation {operation_name} cancelled") + except (FailedPrecondition, NotFound) as e: + print(e.message) + + +# [END documentai_cancel_operation] diff --git a/document_ai/snippets/cancel_operation_sample_test.py b/document_ai/snippets/cancel_operation_sample_test.py new file mode 100644 index 000000000000..5d403be07632 --- /dev/null +++ b/document_ai/snippets/cancel_operation_sample_test.py @@ -0,0 +1,33 @@ +# 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. +# + +import os + +from samples.snippets import cancel_operation_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +operation_id = "4311241022337572151" +operation_name = f"projects/{project_id}/locations/{location}/operations/{operation_id}" + + +def test_cancel_operation(capsys): + cancel_operation_sample.cancel_operation_sample( + location=location, operation_name=operation_name + ) + out, _ = capsys.readouterr() + + assert "Operation" in out + assert "cancelled" in out diff --git a/document_ai/snippets/create_processor_sample.py b/document_ai/snippets/create_processor_sample.py new file mode 100644 index 000000000000..916dbe4ac028 --- /dev/null +++ b/document_ai/snippets/create_processor_sample.py @@ -0,0 +1,54 @@ +# 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. +# + +# [START documentai_create_processor] + +from google.api_core.client_options import ClientOptions +from google.cloud import documentai + +# TODO(developer): Uncomment these variables before running the sample. +# project_id = 'YOUR_PROJECT_ID' +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' +# processor_display_name = 'YOUR_PROCESSOR_DISPLAY_NAME' # Must be unique per project, e.g.: 'My Processor' +# processor_type = 'YOUR_PROCESSOR_TYPE' # Use fetch_processor_types to get available processor types + + +def create_processor_sample( + project_id: str, location: str, processor_display_name: str, processor_type: str +): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + # The full resource name of the location + # e.g.: projects/project_id/locations/location + parent = client.common_location_path(project_id, location) + + # Create a processor + processor = client.create_processor( + parent=parent, + processor=documentai.Processor( + display_name=processor_display_name, type_=processor_type + ), + ) + + # Print the processor information + print(f"Processor Name: {processor.name}") + print(f"Processor Display Name: {processor.display_name}") + print(f"Processor Type: {processor.type_}") + + +# [END documentai_create_processor] diff --git a/document_ai/snippets/create_processor_sample_test.py b/document_ai/snippets/create_processor_sample_test.py new file mode 100644 index 000000000000..4c4fd7ff1510 --- /dev/null +++ b/document_ai/snippets/create_processor_sample_test.py @@ -0,0 +1,47 @@ +# 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. +# + +import os +from uuid import uuid4 + +import mock + +from samples.snippets import create_processor_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +processor_display_name = f"test-processor-{uuid4()}" +processor_type = "OCR_PROCESSOR" + + +@mock.patch("google.cloud.documentai.DocumentProcessorServiceClient.create_processor") +@mock.patch("google.cloud.documentai.Processor") +def test_create_processor(create_processor_mock, processor_mock, capsys): + create_processor_mock.return_value = processor_mock + + create_processor_sample.create_processor_sample( + project_id=project_id, + location=location, + processor_display_name=processor_display_name, + processor_type=processor_type, + ) + + create_processor_mock.assert_called_once() + + out, _ = capsys.readouterr() + + assert "Processor Name:" in out + assert "Processor Display Name:" in out + assert "Processor Type:" in out diff --git a/document_ai/snippets/delete_processor_sample.py b/document_ai/snippets/delete_processor_sample.py new file mode 100644 index 000000000000..fe86b57aad42 --- /dev/null +++ b/document_ai/snippets/delete_processor_sample.py @@ -0,0 +1,49 @@ +# 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. +# + +# [START documentai_delete_processor] + +from google.api_core.client_options import ClientOptions +from google.api_core.exceptions import NotFound +from google.cloud import documentai + +# TODO(developer): Uncomment these variables before running the sample. +# project_id = 'YOUR_PROJECT_ID' +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' +# processor_id = 'YOUR_PROCESSOR_ID' + + +def delete_processor_sample(project_id: str, location: str, processor_id: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + # The full resource name of the processor + # e.g.: projects/project_id/locations/location/processors/processor_id + processor_name = client.processor_path(project_id, location, processor_id) + + # Delete a processor + try: + operation = client.delete_processor(name=processor_name) + # Print operation details + print(operation.operation.name) + # Wait for operation to complete + operation.result() + except NotFound as e: + print(e.message) + + +# [END documentai_delete_processor] diff --git a/document_ai/snippets/delete_processor_sample_test.py b/document_ai/snippets/delete_processor_sample_test.py new file mode 100644 index 000000000000..1a2ed3f4c4ff --- /dev/null +++ b/document_ai/snippets/delete_processor_sample_test.py @@ -0,0 +1,41 @@ +# 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. +# + +import os + +import mock + +from samples.snippets import delete_processor_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +processor_id = "aaaaaaaaa" +parent = f"projects/{project_id}/locations/{location}/processors/{processor_id}" + + +@mock.patch("google.cloud.documentai.DocumentProcessorServiceClient.delete_processor") +@mock.patch("google.api_core.operation.Operation") +def test_delete_processor(operation_mock, delete_processor_mock, capsys): + delete_processor_mock.return_value = operation_mock + + delete_processor_sample.delete_processor_sample( + project_id=project_id, location=location, processor_id=processor_id + ) + + delete_processor_mock.assert_called_once() + + out, _ = capsys.readouterr() + + assert "operation" in out diff --git a/document_ai/snippets/disable_processor_sample.py b/document_ai/snippets/disable_processor_sample.py new file mode 100644 index 000000000000..2b99e7d8aa19 --- /dev/null +++ b/document_ai/snippets/disable_processor_sample.py @@ -0,0 +1,52 @@ +# 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. +# + +# [START documentai_disable_processor] + +from google.api_core.client_options import ClientOptions +from google.api_core.exceptions import FailedPrecondition +from google.cloud import documentai + +# TODO(developer): Uncomment these variables before running the sample. +# project_id = 'YOUR_PROJECT_ID' +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' +# processor_id = 'YOUR_PROCESSOR_ID' + + +def disable_processor_sample(project_id: str, location: str, processor_id: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + # The full resource name of the processor + # e.g.: projects/project_id/locations/location/processors/processor_id + processor_name = client.processor_path(project_id, location, processor_id) + request = documentai.DisableProcessorRequest(name=processor_name) + + # Make DisableProcessor request + try: + operation = client.disable_processor(request=request) + + # Print operation name + print(operation.operation.name) + # Wait for operation to complete + operation.result() + # Cannot disable a processor that is already disabled + except FailedPrecondition as e: + print(e.message) + + +# [END documentai_disable_processor] diff --git a/document_ai/snippets/disable_processor_sample_test.py b/document_ai/snippets/disable_processor_sample_test.py new file mode 100644 index 000000000000..0420ee483c53 --- /dev/null +++ b/document_ai/snippets/disable_processor_sample_test.py @@ -0,0 +1,38 @@ +# 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. +# + +import os + +from samples.snippets import disable_processor_sample, enable_processor_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +processor_id = "5e32eb3e1d0237c0" + + +def test_disable_processor(capsys): + disable_processor_sample.disable_processor_sample( + project_id=project_id, location=location, processor_id=processor_id + ) + out, _ = capsys.readouterr() + + assert "projects" in out + assert "locations" in out + assert "operations" in out + + # Re-Enable Processor + enable_processor_sample.enable_processor_sample( + project_id=project_id, location=location, processor_id=processor_id + ) diff --git a/document_ai/snippets/enable_processor_sample.py b/document_ai/snippets/enable_processor_sample.py new file mode 100644 index 000000000000..42fddf77a79c --- /dev/null +++ b/document_ai/snippets/enable_processor_sample.py @@ -0,0 +1,52 @@ +# 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. +# + +# [START documentai_enable_processor] + +from google.api_core.client_options import ClientOptions +from google.api_core.exceptions import FailedPrecondition +from google.cloud import documentai + +# TODO(developer): Uncomment these variables before running the sample. +# project_id = 'YOUR_PROJECT_ID' +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' +# processor_id = 'YOUR_PROCESSOR_ID' + + +def enable_processor_sample(project_id: str, location: str, processor_id: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + # The full resource name of the location + # e.g.: projects/project_id/locations/location/processors/processor_id + processor_name = client.processor_path(project_id, location, processor_id) + request = documentai.EnableProcessorRequest(name=processor_name) + + # Make EnableProcessor request + try: + operation = client.enable_processor(request=request) + + # Print operation name + print(operation.operation.name) + # Wait for operation to complete + operation.result() + # Cannot enable a processor that is already enabled + except FailedPrecondition as e: + print(e.message) + + +# [END documentai_enable_processor] diff --git a/document_ai/snippets/enable_processor_sample_test.py b/document_ai/snippets/enable_processor_sample_test.py new file mode 100644 index 000000000000..0a238cd0102b --- /dev/null +++ b/document_ai/snippets/enable_processor_sample_test.py @@ -0,0 +1,38 @@ +# 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. +# + +import os + +from samples.snippets import disable_processor_sample, enable_processor_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +processor_id = "351535be16606fe3" + + +def test_enable_processor(capsys): + enable_processor_sample.enable_processor_sample( + project_id=project_id, location=location, processor_id=processor_id + ) + out, _ = capsys.readouterr() + + assert "projects" in out + assert "locations" in out + assert "operations" in out + + # Re-Disable Processor + disable_processor_sample.disable_processor_sample( + project_id=project_id, location=location, processor_id=processor_id + ) diff --git a/document_ai/snippets/fetch_processor_types_sample.py b/document_ai/snippets/fetch_processor_types_sample.py new file mode 100644 index 000000000000..cd6ead86efba --- /dev/null +++ b/document_ai/snippets/fetch_processor_types_sample.py @@ -0,0 +1,46 @@ +# 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. +# + +# [START documentai_fetch_processor_types] + +from google.api_core.client_options import ClientOptions +from google.cloud import documentai + +# TODO(developer): Uncomment these variables before running the sample. +# project_id = 'YOUR_PROJECT_ID' +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' + + +def fetch_processor_types_sample(project_id: str, location: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + # The full resource name of the location + # e.g.: projects/project_id/locations/location + parent = client.common_location_path(project_id, location) + + # Fetch all processor types + response = client.fetch_processor_types(parent=parent) + + print("Processor types:") + # Print the available processor types + for processor_type in response.processor_types: + if processor_type.allow_creation: + print(processor_type.type_) + + +# [END documentai_fetch_processor_types] diff --git a/document_ai/snippets/fetch_processor_types_sample_test.py b/document_ai/snippets/fetch_processor_types_sample_test.py new file mode 100644 index 000000000000..752e904525bd --- /dev/null +++ b/document_ai/snippets/fetch_processor_types_sample_test.py @@ -0,0 +1,31 @@ +# 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. +# + +import os + +from samples.snippets import fetch_processor_types_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] + + +def test_fetch_processor_types(capsys): + fetch_processor_types_sample.fetch_processor_types_sample( + project_id=project_id, location=location + ) + out, _ = capsys.readouterr() + + assert "OCR_PROCESSOR" in out + assert "FORM_PARSER_PROCESSOR" in out diff --git a/document_ai/snippets/get_operation_sample.py b/document_ai/snippets/get_operation_sample.py new file mode 100644 index 000000000000..a569e816e4cf --- /dev/null +++ b/document_ai/snippets/get_operation_sample.py @@ -0,0 +1,42 @@ +# 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. +# + +# [START documentai_get_operation] + +from google.api_core.client_options import ClientOptions +from google.cloud import documentai +from google.longrunning.operations_pb2 import GetOperationRequest + +# TODO(developer): Uncomment these variables before running the sample. +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' +# operation_name = 'YOUR_OPERATION_NAME' # Format is 'projects/project_id/locations/location/operations/operation_id' + + +def get_operation_sample(location: str, operation_name: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + request = GetOperationRequest(name=operation_name) + + # Make GetOperation request + operation = client.get_operation(request=request) + + # Print the Operation Information + print(operation) + + +# [END documentai_get_operation] diff --git a/document_ai/snippets/get_operation_sample_test.py b/document_ai/snippets/get_operation_sample_test.py new file mode 100644 index 000000000000..77219f64d9fe --- /dev/null +++ b/document_ai/snippets/get_operation_sample_test.py @@ -0,0 +1,32 @@ +# 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. +# + +import os + +from samples.snippets import get_operation_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +operation_id = "10828996427112056798" +operation_name = f"projects/{project_id}/locations/{location}/operations/{operation_id}" + + +def test_get_operation(capsys): + get_operation_sample.get_operation_sample( + location=location, operation_name=operation_name + ) + out, _ = capsys.readouterr() + + assert "operation" in out diff --git a/document_ai/snippets/get_processor_sample.py b/document_ai/snippets/get_processor_sample.py new file mode 100644 index 000000000000..580b7e71dd34 --- /dev/null +++ b/document_ai/snippets/get_processor_sample.py @@ -0,0 +1,46 @@ +# 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. +# + +# [START documentai_get_processor] + +from google.api_core.client_options import ClientOptions +from google.cloud import documentai + +# TODO(developer): Uncomment these variables before running the sample. +# project_id = 'YOUR_PROJECT_ID' +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' +# processor_id = 'YOUR_PROCESSOR_ID' + + +def get_processor_sample(project_id: str, location: str, processor_id: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + # The full resource name of the processor, e.g.: + # projects/project_id/locations/location/processor/processor_id + name = client.processor_path(project_id, location, processor_id) + + # Make GetProcessor request + processor = client.get_processor(name=name) + + # Print the processor information + print(f"Processor Name: {processor.name}") + print(f"Processor Display Name: {processor.display_name}") + print(f"Processor Type: {processor.type_}") + + +# [END documentai_get_processor] diff --git a/document_ai/snippets/get_processor_sample_test.py b/document_ai/snippets/get_processor_sample_test.py new file mode 100644 index 000000000000..b18484222beb --- /dev/null +++ b/document_ai/snippets/get_processor_sample_test.py @@ -0,0 +1,34 @@ +# 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. +# + +import os + +from samples.snippets import get_processor_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +processor_id = "91e072f8626a76b7" + + +def test_get_processor(capsys): + get_processor_sample.get_processor_sample( + project_id=project_id, location=location, processor_id=processor_id + ) + out, _ = capsys.readouterr() + + assert "Processor Name:" in out + assert "Processor Display Name:" in out + assert "OCR_PROCESSOR" in out + assert processor_id in out diff --git a/document_ai/snippets/list_operations_sample.py b/document_ai/snippets/list_operations_sample.py new file mode 100644 index 000000000000..5235e757a68d --- /dev/null +++ b/document_ai/snippets/list_operations_sample.py @@ -0,0 +1,55 @@ +# 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. +# + +# [START documentai_list_operations] + +from google.api_core.client_options import ClientOptions +from google.cloud import documentai +from google.longrunning.operations_pb2 import ListOperationsRequest + +# TODO(developer): Uncomment these variables before running the sample. +# project_id = 'YOUR_PROJECT_ID' +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' + +# Create filter in https://google.aip.dev/160 syntax +# For full options, refer to: +# https://cloud.google.com/document-ai/docs/long-running-operations#listing_long-running_operations +# operations_filter = 'YOUR_FILTER' + +# Example: +# operations_filter = "TYPE=BATCH_PROCESS_DOCUMENTS AND STATE=RUNNING" + + +def list_operations_sample(project_id: str, location: str, operations_filter: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + # Format: projects/project_id/locations/location + name = client.common_location_path(project=project_id, location=location) + request = ListOperationsRequest( + name=f"{name}/operations", + filter=operations_filter, + ) + + # Make ListOperations request + operations = client.list_operations(request=request) + + # Print the Operation Information + print(operations) + + +# [END documentai_list_operations] diff --git a/document_ai/snippets/list_operations_sample_test.py b/document_ai/snippets/list_operations_sample_test.py new file mode 100644 index 000000000000..e82e6dab2910 --- /dev/null +++ b/document_ai/snippets/list_operations_sample_test.py @@ -0,0 +1,32 @@ +# 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. +# + +import os + +from samples.snippets import list_operations_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +operations_filter = "TYPE=BATCH_PROCESS_DOCUMENTS AND STATE=DONE" + + +def test_list_operations(capsys): + list_operations_sample.list_operations_sample( + project_id=project_id, location=location, operations_filter=operations_filter + ) + out, _ = capsys.readouterr() + + assert "operations" in out + assert "BatchProcessMetadata" in out diff --git a/document_ai/snippets/list_processors_sample.py b/document_ai/snippets/list_processors_sample.py new file mode 100644 index 000000000000..06515171688b --- /dev/null +++ b/document_ai/snippets/list_processors_sample.py @@ -0,0 +1,47 @@ +# 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. +# + +# [START documentai_list_processors] + +from google.api_core.client_options import ClientOptions +from google.cloud import documentai + +# TODO(developer): Uncomment these variables before running the sample. +# project_id = 'YOUR_PROJECT_ID' +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' + + +def list_processors_sample(project_id: str, location: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + # The full resource name of the location + # e.g.: projects/project_id/locations/location + parent = client.common_location_path(project_id, location) + + # Make ListProcessors request + processor_list = client.list_processors(parent=parent) + + # Print the processor information + for processor in processor_list: + print(f"Processor Name: {processor.name}") + print(f"Processor Display Name: {processor.display_name}") + print(f"Processor Type: {processor.type_}") + print("") + + +# [END documentai_list_processors] diff --git a/document_ai/snippets/list_processors_sample_test.py b/document_ai/snippets/list_processors_sample_test.py new file mode 100644 index 000000000000..09da9262fb58 --- /dev/null +++ b/document_ai/snippets/list_processors_sample_test.py @@ -0,0 +1,33 @@ +# 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. +# + +import os + +from samples.snippets import list_processors_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] + + +def test_list_processors(capsys): + list_processors_sample.list_processors_sample( + project_id=project_id, location=location + ) + out, _ = capsys.readouterr() + + assert "Processor Name:" in out + assert "Processor Display Name:" in out + assert "OCR_PROCESSOR" in out + assert "FORM_PARSER_PROCESSOR" in out diff --git a/document_ai/snippets/poll_operation_sample.py b/document_ai/snippets/poll_operation_sample.py new file mode 100644 index 000000000000..c3e7cc60a78a --- /dev/null +++ b/document_ai/snippets/poll_operation_sample.py @@ -0,0 +1,52 @@ +# 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. +# + +# [START documentai_poll_operation] + +from time import sleep + +from google.api_core.client_options import ClientOptions +from google.cloud import documentai +from google.longrunning.operations_pb2 import GetOperationRequest + +# TODO(developer): Uncomment these variables before running the sample. +# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' +# operation_name = 'YOUR_OPERATION_NAME' # Format is 'projects/project_id/locations/location/operations/operation_id' + + +def poll_operation_sample(location: str, operation_name: str): + # You must set the api_endpoint if you use a location other than 'us', e.g.: + opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") + + client = documentai.DocumentProcessorServiceClient(client_options=opts) + + request = GetOperationRequest(name=operation_name) + + while True: + # Make GetOperation request + operation = client.get_operation(request=request) + + # Print the Operation Information + print(operation) + + # Stop Polling when Operation is no longer running + if operation.done: + break + + # Wait 10 seconds before polling again + sleep(10) + + +# [END documentai_poll_operation] diff --git a/document_ai/snippets/poll_operation_sample_test.py b/document_ai/snippets/poll_operation_sample_test.py new file mode 100644 index 000000000000..4f481b5cf920 --- /dev/null +++ b/document_ai/snippets/poll_operation_sample_test.py @@ -0,0 +1,32 @@ +# 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. +# + +import os + +from samples.snippets import poll_operation_sample + +location = "us" +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +operation_id = "10828996427112056798" +operation_name = f"projects/{project_id}/locations/{location}/operations/{operation_id}" + + +def test_poll_operation(capsys): + poll_operation_sample.poll_operation_sample( + location=location, operation_name=operation_name + ) + out, _ = capsys.readouterr() + + assert "operation" in out diff --git a/document_ai/snippets/process_document_form_sample.py b/document_ai/snippets/process_document_form_sample.py index 78e8bad9bf56..7922490f6771 100644 --- a/document_ai/snippets/process_document_form_sample.py +++ b/document_ai/snippets/process_document_form_sample.py @@ -18,14 +18,14 @@ from typing import Sequence from google.api_core.client_options import ClientOptions -from google.cloud import documentai_v1 as documentai +from google.cloud import documentai # TODO(developer): Uncomment these variables before running the sample. # project_id = 'YOUR_PROJECT_ID' # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' -# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console +# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample # file_path = '/path/to/local/pdf' -# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/processors-list for supported file types +# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types def process_document_form_sample( diff --git a/document_ai/snippets/process_document_ocr_sample.py b/document_ai/snippets/process_document_ocr_sample.py index 1966ebe318d5..a48d2178ed87 100644 --- a/document_ai/snippets/process_document_ocr_sample.py +++ b/document_ai/snippets/process_document_ocr_sample.py @@ -18,14 +18,14 @@ from typing import Sequence from google.api_core.client_options import ClientOptions -from google.cloud import documentai_v1 as documentai +from google.cloud import documentai # TODO(developer): Uncomment these variables before running the sample. # project_id = 'YOUR_PROJECT_ID' # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' -# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console +# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample # file_path = '/path/to/local/pdf' -# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/processors-list for supported file types +# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types def process_document_ocr_sample( @@ -63,7 +63,7 @@ def process_document( # The full resource name of the processor, e.g.: # projects/project_id/locations/location/processor/processor_id - # You must create new processors in the Cloud Console first + # You must create processors before running sample code. name = client.processor_path(project_id, location, processor_id) # Read the file into memory diff --git a/document_ai/snippets/process_document_quality_sample.py b/document_ai/snippets/process_document_quality_sample.py index 463718860f38..0bbca75db7b8 100644 --- a/document_ai/snippets/process_document_quality_sample.py +++ b/document_ai/snippets/process_document_quality_sample.py @@ -16,14 +16,14 @@ # [START documentai_process_quality_document] from google.api_core.client_options import ClientOptions -from google.cloud import documentai_v1 as documentai +from google.cloud import documentai # TODO(developer): Uncomment these variables before running the sample. # project_id = 'YOUR_PROJECT_ID' # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' -# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console +# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample # file_path = '/path/to/local/pdf' -# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/processors-list for supported file types +# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types def process_document_quality_sample( diff --git a/document_ai/snippets/process_document_sample.py b/document_ai/snippets/process_document_sample.py index 0f804777194b..13d7850e67bc 100644 --- a/document_ai/snippets/process_document_sample.py +++ b/document_ai/snippets/process_document_sample.py @@ -16,18 +16,25 @@ # [START documentai_process_document] from google.api_core.client_options import ClientOptions -from google.cloud import documentai_v1 as documentai +from google.cloud import documentai # TODO(developer): Uncomment these variables before running the sample. # project_id = 'YOUR_PROJECT_ID' # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' -# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console +# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample +# processor_version = "pretrained" # Optional. Processor version to use # file_path = '/path/to/local/pdf' -# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/processors-list for supported file types +# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types +# field_mask = "text,entities,pages.pageNumber" # Optional. The fields to return in the Document object. def process_document_sample( - project_id: str, location: str, processor_id: str, file_path: str, mime_type: str + project_id: str, + location: str, + processor_id: str, + file_path: str, + mime_type: str, + field_mask: str = None, ): # You must set the api_endpoint if you use a location other than 'us', e.g.: opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com") @@ -35,10 +42,18 @@ def process_document_sample( client = documentai.DocumentProcessorServiceClient(client_options=opts) # The full resource name of the processor, e.g.: - # projects/project_id/locations/location/processor/processor_id + # projects/{project_id}/locations/{location}/processors/{processor_id} # You must create new processors in the Cloud Console first name = client.processor_path(project_id, location, processor_id) + # NOTE: Alternatively, specify the processor_version to specify a particular version of the processor to use + # projects/{project_id}/locations/{location}/processors/{processor_id}/processorVersions/{processorVersion} + # + # name = client.processor_version_path( + # project_id, location, processor_id, processor_version + # ) + # + # Read the file into memory with open(file_path, "rb") as image: image_content = image.read() @@ -47,7 +62,9 @@ def process_document_sample( raw_document = documentai.RawDocument(content=image_content, mime_type=mime_type) # Configure the process request - request = documentai.ProcessRequest(name=name, raw_document=raw_document) + request = documentai.ProcessRequest( + name=name, raw_document=raw_document, field_mask=field_mask + ) result = client.process_document(request=request) diff --git a/document_ai/snippets/process_document_specialized_sample.py b/document_ai/snippets/process_document_specialized_sample.py index e2b3b0b020a5..c78ca7047aa0 100644 --- a/document_ai/snippets/process_document_specialized_sample.py +++ b/document_ai/snippets/process_document_specialized_sample.py @@ -17,14 +17,14 @@ from google.api_core.client_options import ClientOptions -from google.cloud import documentai_v1 as documentai +from google.cloud import documentai # TODO(developer): Uncomment these variables before running the sample. # project_id = 'YOUR_PROJECT_ID' # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' -# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console +# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample # file_path = '/path/to/local/pdf' -# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/processors-list for supported file types +# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types def process_document_specialized_sample( diff --git a/document_ai/snippets/process_document_splitter_sample.py b/document_ai/snippets/process_document_splitter_sample.py index a726acd0370b..b78c557c378d 100644 --- a/document_ai/snippets/process_document_splitter_sample.py +++ b/document_ai/snippets/process_document_splitter_sample.py @@ -18,14 +18,14 @@ from typing import Sequence from google.api_core.client_options import ClientOptions -from google.cloud import documentai_v1 as documentai +from google.cloud import documentai # TODO(developer): Uncomment these variables before running the sample. # project_id = 'YOUR_PROJECT_ID' # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' -# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console +# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample # file_path = '/path/to/local/pdf' -# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/processors-list for supported file types +# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types def process_document_splitter_sample( diff --git a/document_ai/snippets/quickstart_sample.py b/document_ai/snippets/quickstart_sample.py index a300f543a992..23dcf0847a19 100644 --- a/document_ai/snippets/quickstart_sample.py +++ b/document_ai/snippets/quickstart_sample.py @@ -18,14 +18,14 @@ from google.api_core.client_options import ClientOptions -from google.cloud import documentai_v1 as documentai +from google.cloud import documentai # TODO(developer): Uncomment these variables before running the sample. # project_id = 'YOUR_PROJECT_ID' # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' -# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console +# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample # file_path = '/path/to/local/pdf' -# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/processors-list for supported file types +# mime_type = 'application/pdf' # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types def quickstart( diff --git a/document_ai/snippets/requirements-test.txt b/document_ai/snippets/requirements-test.txt index e07168502ea9..6f722c66e151 100644 --- a/document_ai/snippets/requirements-test.txt +++ b/document_ai/snippets/requirements-test.txt @@ -1 +1,2 @@ pytest==7.1.3 +mock==4.0.3 diff --git a/document_ai/snippets/review_document_sample.py b/document_ai/snippets/review_document_sample.py index 6e96a1ea0df1..2bfa4dcd3a41 100644 --- a/document_ai/snippets/review_document_sample.py +++ b/document_ai/snippets/review_document_sample.py @@ -16,12 +16,12 @@ # [START documentai_review_document] from google.api_core.client_options import ClientOptions -from google.cloud import documentai_v1 as documentai +from google.cloud import documentai # TODO(developer): Uncomment these variables before running the sample. # project_id = 'YOUR_PROJECT_ID' # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu' -# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console +# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample # file_path = '/path/to/local/pdf' # mime_type = 'application/pdf' # https://cloud.google.com/document-ai/docs/file-types diff --git a/document_ai/snippets/review_document_sample_test.py b/document_ai/snippets/review_document_sample_test.py index 2ce0f47853ae..78fcc8fa2fb4 100644 --- a/document_ai/snippets/review_document_sample_test.py +++ b/document_ai/snippets/review_document_sample_test.py @@ -24,7 +24,7 @@ mime_type = "application/pdf" -def test_process_documents(capsys): +def test_review_document(capsys): review_document_sample.review_document_sample( project_id=project_id, location=location,