|
1 | 1 | import os |
2 | 2 | from pathlib import Path |
| 3 | +from datetime import datetime |
3 | 4 |
|
4 | 5 | import httpx |
5 | 6 | import pytest |
|
13 | 14 | ) |
14 | 15 | from mindee.v2.parsing import InferenceActiveOptions |
15 | 16 | from mindee.v2.product.extraction.extraction_response import ExtractionResponse |
| 17 | +from mindee.v2.product.split.split_response import SplitResponse |
16 | 18 | from tests.utils import FILE_TYPES_DIR, V2_PRODUCT_DATA_DIR |
17 | 19 |
|
18 | 20 |
|
@@ -166,6 +168,60 @@ def test_parse_file_filled_single_page_must_succeed( |
166 | 168 | assert len(supplier_name.locations) == 0 |
167 | 169 |
|
168 | 170 |
|
| 171 | +@pytest.mark.integration |
| 172 | +@pytest.mark.v2 |
| 173 | +@pytest.mark.parametrize( |
| 174 | + ("response_cls", "input_path", "model_id"), |
| 175 | + [ |
| 176 | + ( |
| 177 | + ExtractionResponse, |
| 178 | + V2_PRODUCT_DATA_DIR / "extraction" / "financial_document" / "default_sample.jpg", |
| 179 | + "extraction", |
| 180 | + ), |
| 181 | + ( |
| 182 | + SplitResponse, |
| 183 | + V2_PRODUCT_DATA_DIR / "split" / "default_sample.pdf", |
| 184 | + "split", |
| 185 | + ), |
| 186 | + ], |
| 187 | +) |
| 188 | +def test_enqueue_with_two_webhooks_must_complete_and_succeed( |
| 189 | + v2_client: Client, |
| 190 | + findoc_model_id: str, |
| 191 | + split_model_id: str, |
| 192 | + response_cls, |
| 193 | + input_path: Path, |
| 194 | + model_id: str, |
| 195 | +) -> None: |
| 196 | + webhook_ids = [ |
| 197 | + "a2286ed9-aa11-aa11-bdc5-2f8496c5641a", |
| 198 | + "b2286ed9-aa11-aa11-bdc5-2f8496c5641a", |
| 199 | + ] |
| 200 | + resolved_model_id = findoc_model_id if model_id == "extraction" else split_model_id |
| 201 | + |
| 202 | + input_source = PathInput(input_path) |
| 203 | + params = ExtractionParameters(model_id=resolved_model_id, webhook_ids=webhook_ids) |
| 204 | + |
| 205 | + response = v2_client.enqueue_and_get_result(response_cls, input_source, params) |
| 206 | + |
| 207 | + assert response.inference is not None |
| 208 | + assert response.inference.result is not None |
| 209 | + |
| 210 | + assert response.job is not None |
| 211 | + assert response.job.status == "Processed" |
| 212 | + assert isinstance(response.job.completed_at, datetime) |
| 213 | + assert response.job.error is None |
| 214 | + assert len(response.job.webhooks) == 2 |
| 215 | + assert all(webhook.status in {"Completed", "Failed"} for webhook in response.job.webhooks) |
| 216 | + assert {webhook.id for webhook in response.job.webhooks} == set(webhook_ids) |
| 217 | + |
| 218 | + assert response.inference.result is not None |
| 219 | + if response_cls is ExtractionResponse: |
| 220 | + assert response.inference.result.fields["supplier_name"].value == "John Smith" |
| 221 | + else: |
| 222 | + assert len(response.inference.result.splits) == 2 |
| 223 | + |
| 224 | + |
169 | 225 | @pytest.mark.integration |
170 | 226 | @pytest.mark.v2 |
171 | 227 | def test_invalid_uuid_must_throw_error(v2_client: Client) -> None: |
|
0 commit comments