|
| 1 | +# Copyright 2020 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | + |
| 16 | +import os |
| 17 | +from uuid import uuid4 |
| 18 | + |
| 19 | +from samples.snippets import batch_process_documents_sample_v1beta3 |
| 20 | + |
| 21 | +location = "us" |
| 22 | +project_id = os.getenv("GOOGLE_CLOUD_PROJECT") |
| 23 | +processor_id = "90484cfdedb024f6" |
| 24 | +gcs_input_uri = "gs://cloud-samples-data/documentai/invoice.pdf" |
| 25 | +# following bucket contains .csv file which will cause the sample to fail. |
| 26 | +gcs_output_full_uri_with_wrong_type = "gs://documentai-beta-samples" |
| 27 | +BUCKET_NAME = f"document-ai-python-{uuid4()}" |
| 28 | + |
| 29 | + |
| 30 | +def test_batch_process_documents_with_bad_input(capsys): |
| 31 | + try: |
| 32 | + batch_process_documents_sample_v1beta3.batch_process_documents( |
| 33 | + project_id=project_id, |
| 34 | + location=location, |
| 35 | + processor_id=processor_id, |
| 36 | + gcs_input_uri=gcs_input_uri, |
| 37 | + gcs_output_uri=gcs_output_full_uri_with_wrong_type, |
| 38 | + gcs_output_uri_prefix="test", |
| 39 | + timeout=450, |
| 40 | + ) |
| 41 | + out, _ = capsys.readouterr() |
| 42 | + assert "Failed to process" in out |
| 43 | + except Exception as e: |
| 44 | + assert "Failed to process" in e.message |
0 commit comments