Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing excess fields on DocumentStep #119

Merged
merged 6 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mati/resources/verifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions mati/types/enums.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -34,6 +34,19 @@
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]

Check warning on line 41 in mati/types/enums.py

View check run for this annotation

Codecov / codecov/patch

mati/types/enums.py#L41

Added line #L41 was not covered by tests

@classmethod
def _from_dict(
cls, obj_dict: Dict[str, Any]
) -> 'VerificationDocumentStep':
cls._filter_excess_fields(obj_dict)
return cls(**obj_dict)


@dataclass
class Errors:
Expand Down
2 changes: 1 addition & 1 deletion mati/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.4' # pragma: no cover
__version__ = '2.0.5'
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}],
Expand Down
Loading