|
2 | 2 |
|
3 | 3 | import pytest
|
4 | 4 |
|
5 |
| -from mindee import Client, PageOptions, product |
6 |
| -from mindee.error.mindee_error import MindeeClientError |
| 5 | +from mindee import AsyncPredictResponse, Client, PageOptions, PredictResponse, product |
| 6 | +from mindee.error.mindee_error import MindeeClientError, MindeeError |
7 | 7 | from mindee.error.mindee_http_error import MindeeHTTPError
|
| 8 | +from mindee.input import LocalResponse |
8 | 9 | from mindee.input.sources import LocalInputSource
|
| 10 | +from mindee.product import InternationalIdV2, InvoiceV4 |
9 | 11 | from mindee.product.invoice_splitter.invoice_splitter_v1 import InvoiceSplitterV1
|
10 | 12 | from mindee.product.receipt.receipt_v4 import ReceiptV4
|
11 |
| -from tests.test_inputs import FILE_TYPES_DIR |
| 13 | +from tests.mindee_http.test_error import ERROR_DATA_DIR |
| 14 | +from tests.test_inputs import FILE_TYPES_DIR, PRODUCT_DATA_DIR |
12 | 15 | from tests.utils import clear_envvars, dummy_envvars
|
13 | 16 |
|
14 | 17 |
|
@@ -113,3 +116,40 @@ def test_async_wrong_polling_delay(dummy_client: Client):
|
113 | 116 | input_doc = dummy_client.source_from_path(FILE_TYPES_DIR / "pdf" / "blank.pdf")
|
114 | 117 | with pytest.raises(MindeeClientError):
|
115 | 118 | dummy_client.enqueue_and_parse(InvoiceSplitterV1, input_doc, delay_sec=0)
|
| 119 | + |
| 120 | + |
| 121 | +def test_local_response_from_sync_json(dummy_client: Client): |
| 122 | + input_file = LocalResponse( |
| 123 | + PRODUCT_DATA_DIR / "invoices" / "response_v4" / "complete.json" |
| 124 | + ) |
| 125 | + with open(PRODUCT_DATA_DIR / "invoices" / "response_v4" / "summary_full.rst") as f: |
| 126 | + reference_doc = f.read() |
| 127 | + result = dummy_client.load_prediction(InvoiceV4, input_file) |
| 128 | + assert isinstance(result, PredictResponse) |
| 129 | + assert str(result.document) == reference_doc |
| 130 | + |
| 131 | + |
| 132 | +def test_local_response_from_async_json(dummy_client: Client): |
| 133 | + input_file = LocalResponse( |
| 134 | + PRODUCT_DATA_DIR / "international_id" / "response_v2" / "complete.json" |
| 135 | + ) |
| 136 | + with open( |
| 137 | + PRODUCT_DATA_DIR / "international_id" / "response_v2" / "summary_full.rst" |
| 138 | + ) as f: |
| 139 | + reference_doc = f.read() |
| 140 | + result = dummy_client.load_prediction(InternationalIdV2, input_file) |
| 141 | + assert isinstance(result, AsyncPredictResponse) |
| 142 | + assert str(result.document) == reference_doc |
| 143 | + |
| 144 | + |
| 145 | +def test_local_response_from_invalid_file(dummy_client: Client): |
| 146 | + with pytest.raises(MindeeError): |
| 147 | + LocalResponse( |
| 148 | + PRODUCT_DATA_DIR / "invoices" / "response_v4" / "summary_full.rst" |
| 149 | + ) |
| 150 | + |
| 151 | + |
| 152 | +def test_local_response_from_invalid_dict(dummy_client: Client): |
| 153 | + input_file = LocalResponse(ERROR_DATA_DIR / "error_400_no_details.json") |
| 154 | + with pytest.raises(MindeeError): |
| 155 | + dummy_client.load_prediction(InvoiceV4, input_file) |
0 commit comments