Skip to content

Commit c28cfe9

Browse files
🧪 add webhook test to Python integration tests
1 parent 7464b0a commit c28cfe9

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎tests/v2/test_client_integration.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from pathlib import Path
3+
from datetime import datetime
34

45
import httpx
56
import pytest
@@ -13,6 +14,7 @@
1314
)
1415
from mindee.v2.parsing import InferenceActiveOptions
1516
from mindee.v2.product.extraction.extraction_response import ExtractionResponse
17+
from mindee.v2.product.split.split_response import SplitResponse
1618
from tests.utils import FILE_TYPES_DIR, V2_PRODUCT_DATA_DIR
1719

1820

@@ -166,6 +168,60 @@ def test_parse_file_filled_single_page_must_succeed(
166168
assert len(supplier_name.locations) == 0
167169

168170

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+
169225
@pytest.mark.integration
170226
@pytest.mark.v2
171227
def test_invalid_uuid_must_throw_error(v2_client: Client) -> None:

0 commit comments

Comments
 (0)