Skip to content

Commit 86b8e5c

Browse files
authored
🐛 fix sending financial document via the CLI (#61)
* 🐛 fix sending financial document via the CLI * having to rename to financial_doc to match the documentation
1 parent 059f087 commit 86b8e5c

File tree

5 files changed

+44
-20
lines changed

5 files changed

+44
-20
lines changed

mindee/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import argparse
22
from argparse import Namespace
33
import json
4-
from typing import Dict
4+
from typing import Dict, Any
55

66
from mindee import Client
77

8-
DOCUMENTS: Dict[str, dict] = {
8+
DOCUMENTS: Dict[str, Dict[str, Any]] = {
99
"invoice": {
1010
"help": "Invoice",
1111
"required_keys": ["invoice"],
@@ -24,7 +24,7 @@
2424
"financial": {
2525
"help": "Financial Document (receipt or invoice)",
2626
"required_keys": ["invoice", "receipt"],
27-
"doc_type": "financial",
27+
"doc_type": "financial_doc",
2828
},
2929
"custom": {
3030
"help": "Custom document type from API builder",
@@ -40,7 +40,7 @@ def _ots_client(args: Namespace, info: dict):
4040
kwargs["%s_api_key" % key] = getattr(args, "%s_api_key" % key)
4141
else:
4242
kwargs["api_key"] = getattr(args, "%s_api_key" % args.product_name)
43-
func = getattr(client, f"config_{args.product_name}")
43+
func = getattr(client, f"config_{info['doc_type']}")
4444
func(**kwargs)
4545
return client
4646

mindee/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ def parse(
3939
:param username:
4040
:param include_words: Bool, extract all words into http_response
4141
"""
42+
found = []
43+
for k in self.doc_configs.keys():
44+
if k[1] == document_type:
45+
found.append(k)
46+
47+
if len(found) == 0:
48+
raise RuntimeError(f"Unknown document type: {document_type}")
49+
4250
if not username:
43-
found = []
44-
for k in self.doc_configs.keys():
45-
if k[1] == document_type:
46-
found.append(k)
4751
if len(found) == 1:
4852
config_key = found[0]
4953
else:

mindee/documents/financial_document.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ def get_document_config():
148148
key_name="receipt",
149149
),
150150
],
151-
"document_type": "financial_document",
152-
"singular_name": "financial_document",
153-
"plural_name": "financial_documents",
151+
"document_type": "financial_doc",
152+
"singular_name": "financial_doc",
153+
"plural_name": "financial_docs",
154154
},
155155
api_type=API_TYPE_OFF_THE_SHELF,
156156
)

tests/documents/test_document.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_response_wrapper_financial_document_with_receipt(
7979
"financial",
8080
dummy_file_input,
8181
)
82-
assert parsed_financial_doc.financial_document.date.value == "2016-02-26"
82+
assert parsed_financial_doc.financial_doc.date.value == "2016-02-26"
8383

8484

8585
def test_response_wrapper_financial_document_with_invoice(
@@ -92,4 +92,4 @@ def test_response_wrapper_financial_document_with_invoice(
9292
"financial",
9393
dummy_file_input,
9494
)
95-
assert parsed_financial_doc.financial_document.date.value == "2018-09-25"
95+
assert parsed_financial_doc.financial_doc.date.value == "2018-09-25"

tests/test_cli.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
@pytest.fixture
1010
def custom_doc(monkeypatch):
1111
clear_envvars(monkeypatch)
12-
1312
return Namespace(
1413
product_name="custom",
1514
doc_type="license_plate",
@@ -25,12 +24,9 @@ def custom_doc(monkeypatch):
2524

2625

2726
@pytest.fixture
28-
def invoice_doc(monkeypatch):
27+
def ots_doc(monkeypatch):
2928
clear_envvars(monkeypatch)
30-
3129
return Namespace(
32-
product_name="invoice",
33-
invoice_api_key="",
3430
raise_on_error=True,
3531
cut_pdf=True,
3632
input_type="path",
@@ -45,6 +41,30 @@ def test_cli_custom_doc(custom_doc):
4541
call_endpoint(custom_doc)
4642

4743

48-
def test_cli_invoice_doc(invoice_doc):
44+
def test_cli_invoice(ots_doc):
45+
ots_doc.product_name = "invoice"
46+
ots_doc.invoice_api_key = ""
47+
with pytest.raises(RuntimeError):
48+
call_endpoint(ots_doc)
49+
50+
51+
def test_cli_receipt(ots_doc):
52+
ots_doc.product_name = "receipt"
53+
ots_doc.receipt_api_key = ""
54+
with pytest.raises(RuntimeError):
55+
call_endpoint(ots_doc)
56+
57+
58+
def test_cli_financial_doc(ots_doc):
59+
ots_doc.product_name = "financial"
60+
ots_doc.invoice_api_key = ""
61+
ots_doc.receipt_api_key = ""
62+
with pytest.raises(RuntimeError):
63+
call_endpoint(ots_doc)
64+
65+
66+
def test_cli_passport(ots_doc):
67+
ots_doc.product_name = "passport"
68+
ots_doc.passport_api_key = ""
4969
with pytest.raises(RuntimeError):
50-
call_endpoint(invoice_doc)
70+
call_endpoint(ots_doc)

0 commit comments

Comments
 (0)