33from mindee import ClientV2 , InferencePredictOptions , LocalResponse
44from mindee .error .mindee_error import MindeeApiV2Error
55from 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
78from tests .test_inputs import FILE_TYPES_DIR , V2_DATA_DIR
89from tests .utils import dummy_envvars
910
@@ -22,9 +23,7 @@ class _FakeResp:
2223
2324 def json (self ):
2425 # 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" }
2827
2928 monkeypatch .setenv ("MINDEE_V2_BASE_URL" , "https://dummy-url" )
3029
@@ -57,6 +56,8 @@ def test_enqueue_path_with_env_token(custom_base_url_client):
5756 assert custom_base_url_client .mindee_api .base_url == "https://dummy-url"
5857 assert custom_base_url_client .mindee_api .url_root == "https://dummy-url"
5958 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
6061 input_doc : LocalInputSource = custom_base_url_client .source_from_path (
6162 f"{ FILE_TYPES_DIR } /receipt.jpg"
6263 )
@@ -90,3 +91,16 @@ def test_loads_from_prediction(env_client):
9091 )
9192 prediction = env_client .load_inference (input_inference )
9293 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