1
+ import json
2
+
1
3
import pytest
2
4
3
5
from mindee import ClientV2 , InferencePredictOptions , LocalResponse
4
6
from mindee .error .mindee_error import MindeeApiV2Error
5
7
from mindee .error .mindee_http_error_v2 import MindeeHTTPErrorV2
6
8
from mindee .input import LocalInputSource , PathInput
7
9
from mindee .mindee_http .base_settings import USER_AGENT
10
+ from mindee .parsing .v2 import Job , PollingResponse
8
11
from tests .test_inputs import FILE_TYPES_DIR , V2_DATA_DIR
9
12
from tests .utils import dummy_envvars
10
13
@@ -17,28 +20,58 @@ def env_client(monkeypatch) -> ClientV2:
17
20
18
21
@pytest .fixture
19
22
def custom_base_url_client (monkeypatch ) -> ClientV2 :
20
- class _FakeResp :
23
+ class _FakePostResp :
21
24
status_code = 400 # any non-2xx will do
22
25
ok = False
23
26
24
27
def json (self ):
25
28
# Shape must match what handle_error_v2 expects
26
29
return {"status" : - 1 , "detail" : "forced failure from test" }
27
30
31
+ class _FakeGetResp :
32
+ status_code = 200
33
+ ok = True
34
+
35
+ def json (self ):
36
+ return {
37
+ "job" : {
38
+ "id" : "12345678-1234-1234-1234-123456789ABC" ,
39
+ "model_id" : "87654321-4321-4321-4321-CBA987654321" ,
40
+ "filename" : "default_sample.jpg" ,
41
+ "alias" : "dummy-alias.jpg" ,
42
+ "created_at" : "2025-07-03T14:27:58.974451" ,
43
+ "status" : "Processing" ,
44
+ "polling_url" : "https://api-v2.mindee.net/v2/jobs/12345678-1234-1234-1234-123456789ABC" ,
45
+ "result_url" : None ,
46
+ "webhooks" : [],
47
+ "error" : None ,
48
+ }
49
+ }
50
+
51
+ @property
52
+ def content (self ) -> bytes :
53
+ """
54
+ Raw (bytes) payload, mimicking `requests.Response.content`.
55
+ """
56
+ return json .dumps (self .json ()).encode ("utf-8" )
57
+
28
58
monkeypatch .setenv ("MINDEE_V2_BASE_URL" , "https://dummy-url" )
29
59
30
- def _fake_response (* args , ** kwargs ):
31
- return _FakeResp ()
60
+ def _fake_post_error (* args , ** kwargs ):
61
+ return _FakePostResp ()
62
+
63
+ def _fake_get_error (* args , ** kwargs ):
64
+ return _FakeGetResp ()
32
65
33
66
monkeypatch .setattr (
34
67
"mindee.mindee_http.mindee_api_v2.requests.post" ,
35
- _fake_response ,
68
+ _fake_post_error ,
36
69
raising = True ,
37
70
)
38
71
39
72
monkeypatch .setattr (
40
73
"mindee.mindee_http.mindee_api_v2.requests.get" ,
41
- _fake_response ,
74
+ _fake_get_error ,
42
75
raising = True ,
43
76
)
44
77
@@ -78,12 +111,6 @@ def test_enqueue_and_parse_path_with_env_token(custom_base_url_client):
78
111
)
79
112
80
113
81
- @pytest .mark .v2
82
- def test_parse_queued6_and_parse_path_with_env_token (custom_base_url_client ):
83
- with pytest .raises (MindeeHTTPErrorV2 ):
84
- custom_base_url_client .parse_queued ("dummy-queue" )
85
-
86
-
87
114
@pytest .mark .v2
88
115
def test_loads_from_prediction (env_client ):
89
116
input_inference = LocalResponse (
@@ -104,3 +131,24 @@ def test_error_handling(custom_base_url_client):
104
131
)
105
132
assert e .status_code == - 1
106
133
assert e .detail == "forced failure from test"
134
+
135
+
136
+ def test_enqueue (custom_base_url_client ):
137
+ response = custom_base_url_client .parse_queued (
138
+ "12345678-1234-1234-1234-123456789ABC"
139
+ )
140
+ assert isinstance (response , PollingResponse )
141
+ assert isinstance (response .job , Job )
142
+ assert response .job .id == "12345678-1234-1234-1234-123456789ABC"
143
+ assert response .job .model_id == "87654321-4321-4321-4321-CBA987654321"
144
+ assert response .job .filename == "default_sample.jpg"
145
+ assert response .job .alias == "dummy-alias.jpg"
146
+ assert str (response .job .created_at ) == "2025-07-03 14:27:58.974451"
147
+ assert response .job .status == "Processing"
148
+ assert (
149
+ response .job .polling_url
150
+ == "https://api-v2.mindee.net/v2/jobs/12345678-1234-1234-1234-123456789ABC"
151
+ )
152
+ assert not response .job .result_url
153
+ assert len (response .job .webhooks ) == 0
154
+ assert not response .job .error
0 commit comments