3
3
from mindee import ClientV2 , InferencePredictOptions , LocalResponse
4
4
from mindee .error .mindee_error import MindeeApiV2Error
5
5
from mindee .error .mindee_http_error_v2 import MindeeHTTPErrorV2
6
- from mindee .input import LocalInputSource
6
+ from mindee .input import LocalInputSource , PathInput
7
+ from mindee .mindee_http .base_settings import USER_AGENT
7
8
from tests .test_inputs import FILE_TYPES_DIR , V2_DATA_DIR
8
9
from tests .utils import dummy_envvars
9
10
@@ -22,9 +23,7 @@ class _FakeResp:
22
23
23
24
def json (self ):
24
25
# Shape must match what handle_error_v2 expects
25
- return {
26
- "error" : {"status" : - 1 , "detail" : "forced failure from test" },
27
- }
26
+ return {"status" : - 1 , "detail" : "forced failure from test" }
28
27
29
28
monkeypatch .setenv ("MINDEE_V2_BASE_URL" , "https://dummy-url" )
30
29
@@ -57,6 +56,8 @@ def test_enqueue_path_with_env_token(custom_base_url_client):
57
56
assert custom_base_url_client .mindee_api .base_url == "https://dummy-url"
58
57
assert custom_base_url_client .mindee_api .url_root == "https://dummy-url"
59
58
assert custom_base_url_client .mindee_api .api_key == "dummy"
59
+ assert custom_base_url_client .mindee_api .base_headers ["Authorization" ] == "dummy"
60
+ assert custom_base_url_client .mindee_api .base_headers ["User-Agent" ] == USER_AGENT
60
61
input_doc : LocalInputSource = custom_base_url_client .source_from_path (
61
62
f"{ FILE_TYPES_DIR } /receipt.jpg"
62
63
)
@@ -90,3 +91,16 @@ def test_loads_from_prediction(env_client):
90
91
)
91
92
prediction = env_client .load_inference (input_inference )
92
93
assert prediction .inference .model .id == "12345678-1234-1234-1234-123456789abc"
94
+
95
+
96
+ @pytest .mark .v2
97
+ def test_error_handling (custom_base_url_client ):
98
+ with pytest .raises (MindeeHTTPErrorV2 ) as e :
99
+ custom_base_url_client .enqueue (
100
+ PathInput (
101
+ V2_DATA_DIR / "products" / "financial_document" / "default_sample.jpg"
102
+ ),
103
+ InferencePredictOptions ("dummy-model" ),
104
+ )
105
+ assert e .status_code == - 1
106
+ assert e .detail == "forced failure from test"
0 commit comments