From b80bcd9431ce96e48c8e55aea3fb03fcbd412c82 Mon Sep 17 00:00:00 2001 From: Roger Date: Mon, 24 Nov 2025 20:28:52 -0600 Subject: [PATCH 1/5] Uri back required for types --- cuenca_validations/types/requests.py | 16 ++++++++++++++++ cuenca_validations/version.py | 2 +- tests/test_requests.py | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cuenca_validations/types/requests.py b/cuenca_validations/types/requests.py index 63f08cc5..a9353ea6 100644 --- a/cuenca_validations/types/requests.py +++ b/cuenca_validations/types/requests.py @@ -1,4 +1,5 @@ import datetime as dt +from errno import EROFS from typing import Annotated, Any, Optional, Union from clabe import Clabe @@ -94,6 +95,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") @@ -545,6 +553,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): + 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[ diff --git a/cuenca_validations/version.py b/cuenca_validations/version.py index c6d8fc9b..648bf487 100644 --- a/cuenca_validations/version.py +++ b/cuenca_validations/version.py @@ -1 +1 @@ -__version__ = '2.1.22' +__version__ = '2.1.23' diff --git a/tests/test_requests.py b/tests/test_requests.py index 9ca6ae90..8906b874 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -44,3 +44,9 @@ 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(): + with pytest.raises(ValueError) as ex: + UserUpdateRequest(govt_id={'type': 'ine', 'uri_front': 'files/123'}) + assert 'uri_back must be provided for type ine' in str(ex.value) From 312ced87554faac1b4823abe301095ee98ca46c7 Mon Sep 17 00:00:00 2001 From: Roger Date: Mon, 24 Nov 2025 20:30:09 -0600 Subject: [PATCH 2/5] lint --- cuenca_validations/types/requests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cuenca_validations/types/requests.py b/cuenca_validations/types/requests.py index a9353ea6..ce21aa6d 100644 --- a/cuenca_validations/types/requests.py +++ b/cuenca_validations/types/requests.py @@ -1,5 +1,4 @@ import datetime as dt -from errno import EROFS from typing import Annotated, Any, Optional, Union from clabe import Clabe From 4da62cf3fbe67ca885ea09f7da043bfdbfbc1382 Mon Sep 17 00:00:00 2001 From: Roger Date: Tue, 25 Nov 2025 11:41:41 -0600 Subject: [PATCH 3/5] comments --- cuenca_validations/types/requests.py | 2 +- tests/test_requests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cuenca_validations/types/requests.py b/cuenca_validations/types/requests.py index ce21aa6d..9b50df4d 100644 --- a/cuenca_validations/types/requests.py +++ b/cuenca_validations/types/requests.py @@ -554,7 +554,7 @@ def validate_profession(cls, profession: Profession) -> Profession: @field_validator('govt_id') @classmethod - def validate_govt_id(cls, govt_id: KYCFile): + 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) diff --git a/tests/test_requests.py b/tests/test_requests.py index 8906b874..64349152 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -46,7 +46,7 @@ def test_extra_params_are_not_allowed(): assert 'Extra inputs are not permitted' in str(ex.value) -def test_update_user_update_govt(): +def test_update_user_update_govt() -> None: with pytest.raises(ValueError) as ex: UserUpdateRequest(govt_id={'type': 'ine', 'uri_front': 'files/123'}) assert 'uri_back must be provided for type ine' in str(ex.value) From 58420a714e18b70b20521348a476a698185912cc Mon Sep 17 00:00:00 2001 From: Roger Date: Tue, 25 Nov 2025 12:20:05 -0600 Subject: [PATCH 4/5] gabino hack --- tests/test_requests.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index 64349152..6a723a8d 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -47,6 +47,10 @@ def test_extra_params_are_not_allowed(): 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={'type': 'ine', 'uri_front': 'files/123'}) + UserUpdateRequest(**govt_id) + assert 'uri_back must be provided for type ine' in str(ex.value) From aa08e767f17f89078f40263ef3758e743d9e6df5 Mon Sep 17 00:00:00 2001 From: Roger Date: Tue, 25 Nov 2025 12:20:16 -0600 Subject: [PATCH 5/5] blank --- tests/test_requests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index 6a723a8d..c70ab90a 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -52,5 +52,4 @@ def test_update_user_update_govt() -> None: } with pytest.raises(ValueError) as ex: UserUpdateRequest(**govt_id) - assert 'uri_back must be provided for type ine' in str(ex.value)