Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions cuenca_validations/types/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
r'^https:\/\/(?:stage|sandbox|api)\.cuenca\.com\/files\/([a-zA-Z0-9\-_]+)$'
)

DOCS_WITH_BACK = [
KYCFileType.ine,
KYCFileType.dni,
KYCFileType.residency,
KYCFileType.matricula_consular,
]


class BaseRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
Expand Down Expand Up @@ -545,6 +552,14 @@ def validate_profession(cls, profession: Profession) -> Profession:
raise ValueError('Profession "otro" is not allowed')
return profession

@field_validator('govt_id')
@classmethod
def validate_govt_id(cls, govt_id: KYCFile) -> KYCFile:
if govt_id and govt_id.type in DOCS_WITH_BACK and not govt_id.uri_back:
error = f'uri_back must be provided for type {govt_id.type.value}'
raise ValueError(error)
return govt_id


class UserLoginRequest(BaseRequest):
password: Annotated[
Expand Down
2 changes: 1 addition & 1 deletion cuenca_validations/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.1.22'
__version__ = '2.1.23'
9 changes: 9 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ def test_extra_params_are_not_allowed():
with pytest.raises(ValueError) as ex:
UserUpdateRequest(foo='bar')
assert 'Extra inputs are not permitted' in str(ex.value)


def test_update_user_update_govt() -> None:
govt_id: DictStrAny = {
"govt_id": {"type": "ine", "uri_front": "files/123"}
}
with pytest.raises(ValueError) as ex:
UserUpdateRequest(**govt_id)
assert 'uri_back must be provided for type ine' in str(ex.value)
Loading