Skip to content

Commit 205a37b

Browse files
committed
tests and coverage
1 parent 2fc554d commit 205a37b

File tree

10 files changed

+290
-33
lines changed

10 files changed

+290
-33
lines changed

mati/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def change_dict_naming_convention(dict_input, convert_function) -> dict:
3131
if not isinstance(dict_input, dict):
3232
return dict_input
3333
if isinstance(dict_input, list):
34-
return dict() # Puerely for mypy
34+
return dict() # pragma: no cover
3535
new = {}
3636
for k, v in dict_input.items():
3737
new_v = v

mati/resources/access_tokens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def create(cls, client=None) -> 'AccessToken':
3232
)
3333
try:
3434
expires_in = resp['expiresIn']
35-
except KeyError:
35+
except KeyError: # pragma: no cover
3636
expires_in = resp['expires_in']
3737
expires_at = dt.datetime.now() + dt.timedelta(
3838
seconds=expires_in - EXPIRATION_BUFFER
3939
)
4040
try:
4141
user_id = resp['payload']['user']['_id']
42-
except KeyError:
42+
except KeyError: # pragma: no cover
4343
user_id = None
4444
return cls(
4545
user_id=user_id,

mati/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.3.2.dev10' # pragma: no cover
1+
__version__ = '0.3.2.dev11' # pragma: no cover

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ isort==5.7.*
55
flake8==3.8.*
66
mypy==0.790
77
pytest-vcr==1.0.2
8+
pytest-lazy-fixture==0.6.*

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ ignore_missing_imports = true
2121
[mypy-pytest]
2222
ignore_missing_imports = true
2323
24+
[mypy-pytest_lazyfixture]
25+
ignore_missing_imports = true
26+
2427
[coverage:report]
2528
exclude_lines =
2629
pragma: no cover

tests/conftest.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from mati import Client
8+
from mati.types import VerificationDocument, VerificationDocumentStep
89

910
VERIFICATION_RESP = {
1011
'expired': False,
@@ -220,3 +221,77 @@ def identity(client: Client) -> Generator:
220221
segundo_apellido='Hegel',
221222
dob='1770-08-27',
222223
)
224+
225+
226+
@pytest.fixture
227+
def verification_document_national_id() -> VerificationDocument:
228+
return VerificationDocument(
229+
country='MX',
230+
region='mex',
231+
photos=[],
232+
steps=[
233+
VerificationDocumentStep(
234+
id='document-reading',
235+
status=200,
236+
data={'cde': {'label': 'Elector Key', 'value': 'some'}},
237+
)
238+
],
239+
type='ine',
240+
)
241+
242+
243+
@pytest.fixture
244+
def verification_document_passport() -> VerificationDocument:
245+
return VerificationDocument(
246+
country='MX',
247+
region='mex',
248+
photos=[],
249+
steps=[
250+
VerificationDocumentStep(
251+
id='document-reading',
252+
status=200,
253+
data={
254+
'documentType': {'label': 'Document Type', 'value': 'P'}
255+
},
256+
)
257+
],
258+
type='passport',
259+
)
260+
261+
262+
@pytest.fixture
263+
def verification_document_dni() -> VerificationDocument:
264+
return VerificationDocument(
265+
country='MX',
266+
region='mex',
267+
photos=[],
268+
steps=[
269+
VerificationDocumentStep(
270+
id='document-reading',
271+
status=200,
272+
data={
273+
'documentType': {'label': 'Document Type', 'value': 'C'}
274+
},
275+
)
276+
],
277+
type='national-id',
278+
)
279+
280+
281+
@pytest.fixture
282+
def verification_document_foreign_id() -> VerificationDocument:
283+
return VerificationDocument(
284+
country='MX',
285+
region='mex',
286+
photos=[],
287+
steps=[
288+
VerificationDocumentStep(
289+
id='document-reading',
290+
status=200,
291+
data={
292+
'documentType': {'label': 'Document Type', 'value': 'C'}
293+
},
294+
)
295+
],
296+
type='foreign-id',
297+
)
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
interactions:
2+
- request:
3+
body: grant_type=client_credentials
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
Content-Length:
12+
- '29'
13+
Content-Type:
14+
- application/x-www-form-urlencoded
15+
User-Agent:
16+
- mati-python/0.3.2.dev10
17+
method: POST
18+
uri: https://api.getmati.com/oauth
19+
response:
20+
body:
21+
string: '{"access_token": "ACCESS_TOKEN", "expiresIn": 3600, "payload": {"user":
22+
{"_id": "ID", "firstName": "FIRST_NAME", "lastName": "LAST_NAME"}}}'
23+
headers:
24+
Cache-Control:
25+
- no-store, no-cache, must-revalidate, proxy-revalidate
26+
Connection:
27+
- keep-alive
28+
Content-Length:
29+
- '641'
30+
Content-Security-Policy:
31+
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self''
32+
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src
33+
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests'
34+
Content-Type:
35+
- application/json; charset=utf-8
36+
Date:
37+
- Thu, 03 Mar 2022 23:34:57 GMT
38+
Expect-Ct:
39+
- max-age=0
40+
Expires:
41+
- '0'
42+
Pragma:
43+
- no-cache
44+
Referrer-Policy:
45+
- no-referrer
46+
Strict-Transport-Security:
47+
- max-age=15552000; includeSubDomains; preload
48+
Surrogate-Control:
49+
- no-store
50+
X-Content-Type-Options:
51+
- nosniff
52+
X-Dns-Prefetch-Control:
53+
- 'off'
54+
X-Download-Options:
55+
- noopen
56+
X-Frame-Options:
57+
- DENY
58+
X-Permitted-Cross-Domain-Policies:
59+
- none
60+
X-Request-Id:
61+
- e4d9d346-1dd9-4796-82ed-1a315d26a088
62+
X-Xss-Protection:
63+
- '1'
64+
status:
65+
code: 200
66+
message: OK
67+
- request:
68+
body: null
69+
headers:
70+
Accept:
71+
- '*/*'
72+
Accept-Encoding:
73+
- gzip, deflate
74+
Connection:
75+
- keep-alive
76+
User-Agent:
77+
- mati-python/0.3.2.dev10
78+
method: GET
79+
uri: https://api.getmati.com/v2/verifications/621faa3869ef6d001cf439c7
80+
response:
81+
body:
82+
string: '{"expired": false, "identity": {"status": "verified"}, "flow": {"id":
83+
"some_flow", "name": "Default flow"}, "documents": [{"country": "MX", "region":
84+
"", "type": "national-id", "photos": ["https://media.getmati.com/media/xxx",
85+
"https://media.getmati.com/media/yyy"], "steps": [{"error": null, "status":
86+
200, "id": "template-matching"}, {"error": null, "status": 200, "id": "mexican-curp-validation",
87+
"data": {"curp": "CURP", "fullName": "LAST FIRST", "birthDate": "01/01/1980",
88+
"gender": "HOMBRE", "nationality": "MEXICO", "surname": "LAST", "secondSurname":
89+
"", "name": "FIRST"}}, {"error": null, "status": 200, "id": "document-reading",
90+
"data": {"fullName": {"value": "FIRST LAST", "label": "Name", "sensitive":
91+
true}, "documentNumber": {"value": "111", "label": "Document Number"}, "dateOfBirth":
92+
{"value": "1980-01-01", "label": "Day of Birth", "format": "date"}, "expirationDate":
93+
{"value": "2030-12-31", "label": "Date of Expiration", "format": "date"},
94+
"curp": {"value": "CURP", "label": "CURP"}, "address": {"value": "Varsovia
95+
36, 06600 CDMX", "label": "Address"}, "emissionDate": {"value": "2010-01-01",
96+
"label": "Emission Date", "format": "date"}}}, {"error": null, "status": 200,
97+
"id": "alteration-detection"}, {"error": null, "status": 200, "id": "watchlists"}],
98+
"fields": {"fullName": {"value": "FIRST LAST", "label": "Name", "sensitive":
99+
true}, "documentNumber": {"value": "111", "label": "Document Number"}, "dateOfBirth":
100+
{"value": "1980-01-01", "label": "Day of Birth", "format": "date"}, "expirationDate":
101+
{"value": "2030-12-31", "label": "Date of Expiration", "format": "date"},
102+
"curp": {"value": "CURP", "label": "CURP"}, "address": {"value": "Varsovia
103+
36, 06600 CDMX", "label": "Address"}, "emissionDate": {"value": "2010-01-01",
104+
"label": "Emission Date", "format": "date"}}}, {"country": "MX", "region":
105+
null, "type": "proof-of-residency", "steps": [{"status": 200, "id": "document-reading",
106+
"data": {"fullName": {"required": true, "label": "Name", "value": "FIRST NAME"},
107+
"address": {"label": "Address", "value": "Varsovia 36, 06600 CDMX"}, "emissionDate":
108+
{"format": "date", "label": "Emission Date", "value": "1880-01-01"}}, "error":
109+
null}, {"status": 200, "id": "watchlists", "error": null}], "fields": {"address":
110+
{"value": "Varsovia 36, 06600 CDMX"}, "emissionDate": {"value": "1880-01-01"},
111+
"fullName": {"value": "FIRST LASTNAME"}}, "photos": ["https://media.getmati.com/file?location=xyc"]}],
112+
"steps": [{"status": 200, "id": "liveness", "data": {"videoUrl": "https://media.getmati.com/file?location=abc",
113+
"spriteUrl": "https://media.getmati.com/file?location=def", "selfieUrl": "https://media.getmati.com/file?location=hij"},
114+
"error": null}], "hasProblem": false, "computed": {"age": {"data": 100}, "isDocumentExpired":
115+
{"data": {"national-id": false, "proof-of-residency": false}}}, "id": "5d9fb1f5bfbfac001a349bfb",
116+
"metadata": {"name": "First Last", "dob": "1980-01-01"}}'
117+
headers:
118+
Cache-Control:
119+
- no-store, no-cache, must-revalidate, proxy-revalidate
120+
Connection:
121+
- keep-alive
122+
Content-Length:
123+
- '6082'
124+
Content-Security-Policy:
125+
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self''
126+
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src
127+
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests'
128+
Content-Type:
129+
- application/json; charset=utf-8
130+
Date:
131+
- Thu, 03 Mar 2022 23:34:57 GMT
132+
Expect-Ct:
133+
- max-age=0
134+
Expires:
135+
- '0'
136+
Pragma:
137+
- no-cache
138+
Referrer-Policy:
139+
- no-referrer
140+
Strict-Transport-Security:
141+
- max-age=15552000; includeSubDomains; preload
142+
Surrogate-Control:
143+
- no-store
144+
X-Content-Type-Options:
145+
- nosniff
146+
X-Dns-Prefetch-Control:
147+
- 'off'
148+
X-Download-Options:
149+
- noopen
150+
X-Frame-Options:
151+
- DENY
152+
X-Permitted-Cross-Domain-Policies:
153+
- none
154+
X-Request-Id:
155+
- 5142ba42-76d9-49b7-9f24-bca55a16c53f
156+
X-Xss-Protection:
157+
- '1'
158+
status:
159+
code: 200
160+
message: OK
161+
version: 1

tests/resources/test_user_verification_data.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,17 @@ def test_ine_and_liveness_upload(identity: Identity):
4545
content=live,
4646
input_type=ValidationInputType.selfie_video,
4747
)
48+
user_validation_photo = UserValidationFile(
49+
filename='selfie.jpg',
50+
content=front,
51+
input_type=ValidationInputType.selfie_photo,
52+
)
4853
resp = identity.upload_validation_data(
4954
[
5055
user_validation_file,
5156
user_validation_file_back,
5257
user_validation_live,
58+
user_validation_photo,
5359
]
5460
)
5561
assert all([resp[i]['result'] for i in range(3)]) is True

tests/resources/test_verifications.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ def test_verification_without_poa(client: Client):
4040
verification.documents = [verification.documents[0]]
4141
assert not verification.proof_of_residency_document
4242
assert not verification.proof_of_residency_validation
43+
44+
45+
@pytest.mark.vcr
46+
def test_verification_without_pol(client: Client):
47+
verification = client.verifications.retrieve('621faa3869ef6d001cf439c7')
48+
verification.steps = None
49+
assert not verification.proof_of_life_validation

tests/test_types.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
# from mati.types import (
2-
# ValidationInputType,
3-
# VerificationDocument,
4-
# VerificationDocumentStep,
5-
# )
6-
#
7-
#
8-
# def test_type_to_str():
9-
# assert str(ValidationInputType.document_photo) == 'document-photo'
10-
# assert ValidationInputType.document_photo == 'document-photo'
11-
#
12-
#
13-
# def test_document_type():
14-
# document = VerificationDocument(
15-
# country='MX',
16-
# region='mex',
17-
# photos=[],
18-
# steps=[
19-
# VerificationDocumentStep(
20-
# id='document-reading',
21-
# status=200,
22-
# data={'cde': {'label': 'Elector Key', 'value': 'some'}},
23-
# )
24-
# ],
25-
# type='ine',
26-
# )
27-
# assert document.document_type == 'ine'
28-
# document.type = 'passport'
29-
# assert document.document_type == 'passport'
1+
import pytest
2+
from pytest_lazyfixture import lazy_fixture
3+
4+
from mati.types import ValidationInputType
5+
6+
7+
def test_type_to_str():
8+
assert str(ValidationInputType.document_photo) == 'document-photo'
9+
10+
11+
@pytest.mark.parametrize(
12+
('verification_document', 'expected_type'),
13+
(
14+
(
15+
lazy_fixture('verification_document_national_id'),
16+
'ine',
17+
),
18+
(
19+
lazy_fixture('verification_document_passport'),
20+
'passport',
21+
),
22+
(
23+
lazy_fixture('verification_document_dni'),
24+
'dni',
25+
),
26+
(
27+
lazy_fixture('verification_document_foreign_id'),
28+
'foreign-id',
29+
),
30+
),
31+
)
32+
def test_document_type(verification_document, expected_type):
33+
assert verification_document.document_type == expected_type

0 commit comments

Comments
 (0)