Skip to content

Commit b80bcd9

Browse files
committed
Uri back required for types
1 parent 95f8482 commit b80bcd9

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

cuenca_validations/types/requests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime as dt
2+
from errno import EROFS
23
from typing import Annotated, Any, Optional, Union
34

45
from clabe import Clabe
@@ -94,6 +95,13 @@
9495
r'^https:\/\/(?:stage|sandbox|api)\.cuenca\.com\/files\/([a-zA-Z0-9\-_]+)$'
9596
)
9697

98+
DOCS_WITH_BACK = [
99+
KYCFileType.ine,
100+
KYCFileType.dni,
101+
KYCFileType.residency,
102+
KYCFileType.matricula_consular,
103+
]
104+
97105

98106
class BaseRequest(BaseModel):
99107
model_config = ConfigDict(extra="forbid")
@@ -545,6 +553,14 @@ def validate_profession(cls, profession: Profession) -> Profession:
545553
raise ValueError('Profession "otro" is not allowed')
546554
return profession
547555

556+
@field_validator('govt_id')
557+
@classmethod
558+
def validate_govt_id(cls, govt_id: KYCFile):
559+
if govt_id and govt_id.type in DOCS_WITH_BACK and not govt_id.uri_back:
560+
error = f'uri_back must be provided for type {govt_id.type.value}'
561+
raise ValueError(error)
562+
return govt_id
563+
548564

549565
class UserLoginRequest(BaseRequest):
550566
password: Annotated[

cuenca_validations/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.1.22'
1+
__version__ = '2.1.23'

tests/test_requests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ def test_extra_params_are_not_allowed():
4444
with pytest.raises(ValueError) as ex:
4545
UserUpdateRequest(foo='bar')
4646
assert 'Extra inputs are not permitted' in str(ex.value)
47+
48+
49+
def test_update_user_update_govt():
50+
with pytest.raises(ValueError) as ex:
51+
UserUpdateRequest(govt_id={'type': 'ine', 'uri_front': 'files/123'})
52+
assert 'uri_back must be provided for type ine' in str(ex.value)

0 commit comments

Comments
 (0)