From 428f86310f30ea26970d8ea4d32bd855c1bc4efe Mon Sep 17 00:00:00 2001 From: AlexViquez Date: Wed, 24 Jan 2024 12:03:13 -0600 Subject: [PATCH 1/6] fixing excess fields on DocumentStep --- mati/resources/verifications.py | 3 ++- mati/types/enums.py | 17 +++++++++++++++-- mati/version.py | 2 +- .../test_retrieve_full_verification.yaml | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/mati/resources/verifications.py b/mati/resources/verifications.py index 03512cc..730ef19 100644 --- a/mati/resources/verifications.py +++ b/mati/resources/verifications.py @@ -36,7 +36,8 @@ def __post_init__(self): ] for doc in self.documents: doc['steps'] = [ - VerificationDocumentStep(**step) for step in doc['steps'] + VerificationDocumentStep._from_dict(step) + for step in doc['steps'] ] docs.append(VerificationDocument(**doc)) self.documents = docs diff --git a/mati/types/enums.py b/mati/types/enums.py index 773fc55..58d0c43 100644 --- a/mati/types/enums.py +++ b/mati/types/enums.py @@ -1,6 +1,6 @@ -from dataclasses import dataclass, field +from dataclasses import dataclass, field, fields from enum import Enum -from typing import BinaryIO, Dict, List, Optional, Union +from typing import Any, BinaryIO, Dict, List, Optional, Union class SerializableEnum(str, Enum): @@ -34,6 +34,19 @@ class VerificationDocumentStep: error: Optional[Dict] = None data: Optional[Dict] = field(default_factory=dict) + @classmethod + def _filter_excess_fields(cls, obj_dict: Dict) -> None: + excess = set(obj_dict.keys()) - {f.name for f in fields(cls)} + for f in excess: + del obj_dict[f] + + @classmethod + def _from_dict( + cls, obj_dict: Dict[str, Any] + ) -> 'VerificationDocumentStep': + cls._filter_excess_fields(obj_dict) + return cls(**obj_dict) + @dataclass class Errors: diff --git a/mati/version.py b/mati/version.py index dc2f47f..780ef2e 100644 --- a/mati/version.py +++ b/mati/version.py @@ -1 +1 @@ -__version__ = '2.0.4' # pragma: no cover +__version__ = '2.0.5.dev0' # pragma: no cover diff --git a/tests/resources/cassettes/test_retrieve_full_verification.yaml b/tests/resources/cassettes/test_retrieve_full_verification.yaml index b8e9e5c..c272a75 100644 --- a/tests/resources/cassettes/test_retrieve_full_verification.yaml +++ b/tests/resources/cassettes/test_retrieve_full_verification.yaml @@ -108,7 +108,7 @@ interactions: "steps": [{"status": 200, "id": "document-reading", "data": {"fullName": {"required": true, "label": "Name", "value": "FIRST NAME"}, "address": {"label": "Address", "value": "Varsovia 36, 06600 CDMX"}, "emissionDate": {"format": "date", "label": - "Emission Date", "value": "1880-01-01"}}, "error": null}, {"status": 200, + "Emission Date", "value": "1880-01-01"}}, "error": null, "reused": false, "cacheHit": false}, {"status": 200, "id": "watchlists", "error": null}], "fields": {"address": {"value": "Varsovia 36, 06600 CDMX"}, "emissionDate": {"value": "1880-01-01"}, "fullName": {"value": "FIRST LASTNAME"}}, "photos": ["https://media.getmati.com/file?location=xyc"]}], From abcd1bf1ad41eb03d78db2428c5505bd28cb6154 Mon Sep 17 00:00:00 2001 From: AlexViquez Date: Thu, 25 Jan 2024 12:43:31 -0600 Subject: [PATCH 2/6] version --- mati/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mati/version.py b/mati/version.py index 780ef2e..838548a 100644 --- a/mati/version.py +++ b/mati/version.py @@ -1 +1 @@ -__version__ = '2.0.5.dev0' # pragma: no cover +__version__ = '2.0.5' # pragma: no cover From 03a56848aede1374b660120e5e966191d8ccda76 Mon Sep 17 00:00:00 2001 From: AlexViquez Date: Thu, 25 Jan 2024 12:47:45 -0600 Subject: [PATCH 3/6] remove pragma --- mati/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mati/version.py b/mati/version.py index 838548a..4c354e0 100644 --- a/mati/version.py +++ b/mati/version.py @@ -1 +1 @@ -__version__ = '2.0.5' # pragma: no cover +__version__ = '2.0.5' From f168de15fc5f30cd07e3aae2511b37433cf1f56b Mon Sep 17 00:00:00 2001 From: AlexViquez Date: Thu, 25 Jan 2024 12:53:59 -0600 Subject: [PATCH 4/6] fixed --- tests/test_types.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_types.py b/tests/test_types.py index 055ac9d..c8d8576 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -2,6 +2,7 @@ from pytest_lazyfixture import lazy_fixture from mati.types import ValidationInputType +from mati.types.enums import VerificationDocumentStep def test_type_to_str(): @@ -31,3 +32,9 @@ def test_type_to_str(): ) def test_document_type(verification_document, expected_type): assert verification_document.document_type == expected_type + + +def test_excess_fields(): + data = {'some': 'data', 'aditional': 'data', 'id': 'foo', 'status': 10} + step = VerificationDocumentStep._from_dict(data) + assert step From f18557e2bbab29195cc6c5ca2944edac785215bb Mon Sep 17 00:00:00 2001 From: AlexViquez Date: Thu, 25 Jan 2024 12:54:54 -0600 Subject: [PATCH 5/6] tested --- tests/test_types.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_types.py b/tests/test_types.py index c8d8576..a755cff 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -34,7 +34,13 @@ def test_document_type(verification_document, expected_type): assert verification_document.document_type == expected_type -def test_excess_fields(): +def test_from_dict(): data = {'some': 'data', 'aditional': 'data', 'id': 'foo', 'status': 10} step = VerificationDocumentStep._from_dict(data) assert step + + +def test_excess_fields(): + data = {'some': 'data', 'aditional': 'data', 'id': 'foo', 'status': 10} + VerificationDocumentStep._filter_excess_fields(data) + assert 'some' not in data \ No newline at end of file From b73033846f3c5cdd9c5f3ba9def6c4c1c2328a4b Mon Sep 17 00:00:00 2001 From: AlexViquez Date: Thu, 25 Jan 2024 12:57:32 -0600 Subject: [PATCH 6/6] eofl --- tests/test_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_types.py b/tests/test_types.py index a755cff..f5b2639 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -43,4 +43,4 @@ def test_from_dict(): def test_excess_fields(): data = {'some': 'data', 'aditional': 'data', 'id': 'foo', 'status': 10} VerificationDocumentStep._filter_excess_fields(data) - assert 'some' not in data \ No newline at end of file + assert 'some' not in data