-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_cli.py
223 lines (189 loc) · 6.37 KB
/
test_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import json
from argparse import Namespace
import pytest
from mindee.commands.cli_parser import MindeeParser
from mindee.error.mindee_http_error import MindeeHTTPClientError, MindeeHTTPError
from tests.utils import clear_envvars
@pytest.fixture
def custom_doc(monkeypatch):
clear_envvars(monkeypatch)
return Namespace(
product_name="custom",
endpoint_name="license_plate",
account_name="mindee",
api_key="dummy",
api_version="1",
cut_doc=False,
doc_pages=3,
input_type="path",
output_type="summary",
include_words=False,
path="./tests/data/file_types/pdf/blank.pdf",
parse_type="parse",
async_parse=False,
)
@pytest.fixture
def generated_doc_sync(monkeypatch):
clear_envvars(monkeypatch)
return Namespace(
product_name="generated",
endpoint_name="license_plate",
account_name="mindee",
api_key="dummy",
api_version="1",
cut_doc=False,
doc_pages=3,
input_type="path",
output_type="summary",
include_words=False,
path="./tests/data/file_types/pdf/blank.pdf",
parse_type="parse",
async_parse=False,
)
@pytest.fixture
def generated_doc_async(monkeypatch):
clear_envvars(monkeypatch)
return Namespace(
product_name="generated",
endpoint_name="invoice_splitter",
account_name="mindee",
api_key="dummy",
api_version="1",
cut_doc=False,
doc_pages=3,
input_type="path",
output_type="summary",
include_words=False,
path="./tests/data/file_types/pdf/blank.pdf",
parse_type="parse",
async_parse=True,
)
@pytest.fixture
def ots_doc(monkeypatch):
clear_envvars(monkeypatch)
return Namespace(
api_key="dummy",
product_name="invoice",
cut_doc=False,
doc_pages=3,
input_type="path",
output_type="summary",
include_words=False,
path="./tests/data/products/invoices/invoice.pdf",
parse_type="parse",
async_parse=False,
)
@pytest.fixture
def ots_doc_enqueue_and_parse(monkeypatch):
clear_envvars(monkeypatch)
return Namespace(
api_key="dummy",
product_name="invoice-splitter",
cut_doc=False,
doc_pages=3,
input_type="path",
include_words=False,
path="./tests/data/products/invoice_splitter/default_sample.pdf",
parse_type="parse",
async_parse=True,
)
@pytest.fixture
def ots_doc_feedback(monkeypatch):
clear_envvars(monkeypatch)
dummy_feedback = '{"feedback": {"dummy_field": {"value": "dummy"}}}'
return Namespace(
api_key="dummy",
output_type="summary",
product_name="custom",
endpoint_name="dummy-endpoint",
account_name="dummy",
api_version="dummy",
queue_id="dummy-queue-id",
call_method="parse-queued",
input_type="path",
path="./tests/data/file_types/pdf/blank.pdf",
parse_type="feedback",
feedback=json.loads(dummy_feedback),
)
def test_cli_custom_doc(custom_doc):
with pytest.raises(MindeeHTTPError):
parser = MindeeParser(parsed_args=custom_doc)
parser.call_endpoint()
def test_cli_generated_doc_sync(generated_doc_sync):
with pytest.raises(MindeeHTTPError):
parser = MindeeParser(parsed_args=generated_doc_sync)
parser.call_endpoint()
def test_cli_generated_doc_async(generated_doc_async):
with pytest.raises(MindeeHTTPError):
parser = MindeeParser(parsed_args=generated_doc_async)
parser.call_endpoint()
def test_cli_invoice(ots_doc):
ots_doc.product_name = "invoice"
ots_doc.api_key = ""
with pytest.raises(RuntimeError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
ots_doc.api_key = "dummy"
with pytest.raises(MindeeHTTPError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
def test_cli_receipt(ots_doc):
ots_doc.product_name = "receipt"
ots_doc.api_key = ""
with pytest.raises(RuntimeError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
ots_doc.api_key = "dummy"
with pytest.raises(MindeeHTTPError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
def test_cli_financial_doc(ots_doc):
ots_doc.product_name = "financial-document"
ots_doc.api_key = ""
with pytest.raises(RuntimeError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
ots_doc.api_key = "dummy"
with pytest.raises(MindeeHTTPError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
def test_cli_passport(ots_doc):
ots_doc.product_name = "passport"
ots_doc.api_key = ""
with pytest.raises(RuntimeError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
ots_doc.api_key = "dummy"
with pytest.raises(MindeeHTTPError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
def test_cli_us_bank_check(ots_doc):
ots_doc.product_name = "us-bank-check"
ots_doc.api_key = ""
with pytest.raises(RuntimeError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
ots_doc.api_key = "dummy"
with pytest.raises(MindeeHTTPError):
parser = MindeeParser(parsed_args=ots_doc)
parser.call_endpoint()
def test_cli_invoice_splitter_enqueue(ots_doc_enqueue_and_parse):
ots_doc_enqueue_and_parse.product_name = "invoice-splitter"
ots_doc_enqueue_and_parse.api_key = ""
with pytest.raises(RuntimeError):
parser = MindeeParser(parsed_args=ots_doc_enqueue_and_parse)
parser.call_endpoint()
ots_doc_enqueue_and_parse.api_key = "dummy"
with pytest.raises(MindeeHTTPError):
parser = MindeeParser(parsed_args=ots_doc_enqueue_and_parse)
parser.call_endpoint()
def test_cli_feedback(ots_doc_feedback):
ots_doc_feedback.document_id = "dummy-document-id"
ots_doc_feedback.api_key = ""
with pytest.raises(RuntimeError):
parser = MindeeParser(parsed_args=ots_doc_feedback)
parser.call_endpoint()
ots_doc_feedback.api_key = "dummy"
with pytest.raises(MindeeHTTPClientError):
parser = MindeeParser(parsed_args=ots_doc_feedback)
parser.call_endpoint()