Skip to content

Commit 4b1f5f3

Browse files
committed
add expiration date field
1 parent 554d1c4 commit 4b1f5f3

3 files changed

Lines changed: 96 additions & 2 deletions

File tree

mati/types/enums.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,40 @@ def ocr_number(self) -> str:
184184
return self.fields['ocr_number']['value']
185185
return ''
186186

187+
@property
188+
def expiration_date(self) -> None:
189+
"""
190+
This property fills the expiration date direct from the ocr
191+
fields `expiration_date`.
192+
193+
Returns None if the field is missing or fields is None.
194+
Unlike other fields that return empty strings, dates return None
195+
to indicate absence of a date value.
196+
"""
197+
if self.fields is None:
198+
return None
199+
try:
200+
return self.fields['expiration_date']['value']
201+
except (KeyError, TypeError):
202+
return None
203+
204+
@property
205+
def emission_date(self) -> None:
206+
"""
207+
This property fills the emission date direct from the ocr
208+
fields `emission_date`.
209+
210+
Returns None if the field is missing or fields is None.
211+
Unlike other fields that return empty strings, dates return None
212+
to indicate absence of a date value.
213+
"""
214+
if self.fields is None:
215+
return None
216+
try:
217+
return self.fields['emission_date']['value']
218+
except (KeyError, TypeError):
219+
return None
220+
187221
def add_expired_step(self) -> None:
188222
'''
189223
Appends an expired error step to the document if missing.

mati/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.8'
1+
__version__ = '2.0.9.dev3'

tests/test_types.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pytest_lazyfixture import lazy_fixture
33

44
from mati.types import ValidationInputType
5-
from mati.types.enums import VerificationDocumentStep
5+
from mati.types.enums import VerificationDocument, VerificationDocumentStep
66

77

88
def test_type_to_str():
@@ -44,3 +44,63 @@ def test_excess_fields():
4444
data = {'some': 'data', 'aditional': 'data', 'id': 'foo', 'status': 10}
4545
VerificationDocumentStep._filter_excess_fields(data)
4646
assert 'some' not in data
47+
48+
49+
@pytest.mark.parametrize(
50+
('fields', 'expected'),
51+
[
52+
(
53+
{
54+
'expiration_date': {
55+
'value': '2030-12-31',
56+
'label': 'Date of Expiration',
57+
'format': 'date',
58+
}
59+
},
60+
'2030-12-31',
61+
),
62+
(None, None),
63+
({'address': {'value': 'Test Address', 'label': 'Address'}}, None),
64+
({'expiration_date': {'label': 'Date of Expiration'}}, None),
65+
],
66+
)
67+
def test_expiration_date_property(fields, expected):
68+
doc = VerificationDocument(
69+
country='MX',
70+
region='',
71+
photos=[],
72+
steps=[],
73+
type='national-id',
74+
fields=fields,
75+
)
76+
assert doc.expiration_date == expected
77+
78+
79+
@pytest.mark.parametrize(
80+
('fields', 'expected'),
81+
[
82+
(
83+
{
84+
'emission_date': {
85+
'value': '2023-01-15',
86+
'label': 'Emission Date',
87+
'format': 'date',
88+
}
89+
},
90+
'2023-01-15',
91+
),
92+
(None, None),
93+
({'address': {'value': 'Test Address', 'label': 'Address'}}, None),
94+
({'emission_date': {'label': 'Emission Date'}}, None),
95+
],
96+
)
97+
def test_emission_date_property(fields, expected):
98+
doc = VerificationDocument(
99+
country='MX',
100+
region='',
101+
photos=[],
102+
steps=[],
103+
type='proof-of-residency',
104+
fields=fields,
105+
)
106+
assert doc.emission_date == expected

0 commit comments

Comments
 (0)