-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_financial_document_v1.py
More file actions
119 lines (95 loc) · 4.63 KB
/
test_financial_document_v1.py
File metadata and controls
119 lines (95 loc) · 4.63 KB
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
import json
import pytest
from mindee.parsing.common.document import Document
from mindee.parsing.common.page import Page
from mindee.product.financial_document.financial_document_v1 import FinancialDocumentV1
from mindee.product.financial_document.financial_document_v1_document import (
FinancialDocumentV1Document,
)
from tests.product import PRODUCT_DATA_DIR
RESPONSE_DIR = PRODUCT_DATA_DIR / "financial_document" / "response_v1"
FinancialDocumentV1DocumentType = Document[
FinancialDocumentV1Document,
Page[FinancialDocumentV1Document],
]
@pytest.fixture
def complete_doc_invoice() -> FinancialDocumentV1DocumentType:
file_path = RESPONSE_DIR / "complete_invoice.json"
with open(file_path, "r", encoding="utf-8") as open_file:
json_data = json.load(open_file)
return Document(FinancialDocumentV1, json_data["document"])
@pytest.fixture
def complete_doc_receipt() -> FinancialDocumentV1DocumentType:
file_path = RESPONSE_DIR / "complete_receipt.json"
with open(file_path, "r", encoding="utf-8") as open_file:
json_data = json.load(open_file)
return Document(FinancialDocumentV1, json_data["document"])
@pytest.fixture
def empty_doc() -> FinancialDocumentV1DocumentType:
file_path = RESPONSE_DIR / "empty.json"
with open(file_path, "r", encoding="utf-8") as open_file:
json_data = json.load(open_file)
return Document(FinancialDocumentV1, json_data["document"])
@pytest.fixture
def complete_page0_invoice() -> Page[FinancialDocumentV1Document]:
file_path = RESPONSE_DIR / "complete_invoice.json"
with open(file_path, "r", encoding="utf-8") as open_file:
json_data = json.load(open_file)
page_0 = json_data["document"]["inference"]["pages"][0]
return Page(FinancialDocumentV1Document, page_0)
@pytest.fixture
def complete_page0_receipt() -> Page[FinancialDocumentV1Document]:
file_path = RESPONSE_DIR / "complete_receipt.json"
with open(file_path, "r", encoding="utf-8") as open_file:
json_data = json.load(open_file)
page_0 = json_data["document"]["inference"]["pages"][0]
return Page(FinancialDocumentV1Document, page_0)
def test_complete_invoice(complete_doc_invoice: FinancialDocumentV1DocumentType):
file_path = RESPONSE_DIR / "summary_full_invoice.rst"
with open(file_path, "r", encoding="utf-8") as open_file:
reference_str = open_file.read()
assert str(complete_doc_invoice) == reference_str
def test_complete_receipt(
complete_doc_receipt: FinancialDocumentV1DocumentType,
):
file_path = RESPONSE_DIR / "summary_full_receipt.rst"
with open(file_path, "r", encoding="utf-8") as open_file:
reference_str = open_file.read()
assert str(complete_doc_receipt) == reference_str
def test_empty_doc(empty_doc: FinancialDocumentV1DocumentType):
prediction = empty_doc.inference.prediction
assert prediction.locale.value is None
assert prediction.invoice_number.value is None
assert len(prediction.reference_numbers) == 0
assert prediction.billing_address.value is None
assert len(prediction.customer_company_registrations) == 0
assert prediction.customer_id.value is None
assert prediction.customer_name.value is None
assert prediction.date.value is None
assert prediction.due_date.value is None
assert prediction.document_type.value is not None
assert prediction.document_type_extended.value is not None
assert prediction.document_number.value is None
assert prediction.total_net.value is None
assert prediction.total_amount.value is None
assert len(prediction.taxes) == 0
assert len(prediction.supplier_payment_details) == 0
assert prediction.supplier_name.value is None
assert len(prediction.supplier_company_registrations) == 0
assert prediction.supplier_address.value is None
assert prediction.customer_name.value is None
assert len(prediction.customer_company_registrations) == 0
assert prediction.customer_address.value is None
assert len(prediction.line_items) == 0
def test_page0_invoice(complete_page0_invoice: Page[FinancialDocumentV1Document]):
file_path = RESPONSE_DIR / "summary_page0_invoice.rst"
with open(file_path, "r", encoding="utf-8") as open_file:
reference_str = open_file.read()
assert complete_page0_invoice.id == 0
assert str(complete_page0_invoice) == reference_str
def test_page0_receipt(complete_page0_receipt: Page[FinancialDocumentV1Document]):
file_path = RESPONSE_DIR / "summary_page0_receipt.rst"
with open(file_path, "r", encoding="utf-8") as open_file:
reference_str = open_file.read()
assert complete_page0_receipt.id == 0
assert str(complete_page0_receipt) == reference_str