Skip to content

Commit

Permalink
Add RFC support to UserListsRequest validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabino committed Feb 26, 2025
1 parent 70f4fcb commit cd17123
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
10 changes: 8 additions & 2 deletions cuenca_validations/types/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ class BankAccountValidationRequest(BaseModel):

class UserListsRequest(BaseModel):
curp: Optional[Curp] = Field(None, description='Curp to review on lists')
rfc: Optional[Rfc] = Field(None, description='Rfc to review on lists')
account_number: Optional[Union[Clabe, PaymentCardNumber]] = Field(
None, description='Account to review on lists'
)
Expand All @@ -648,8 +649,12 @@ class UserListsRequest(BaseModel):
@classmethod
def check_request(cls, values):
has_name = all(values.get(f) for f in ['names', 'first_surname'])
curp, account = values.get('curp'), values.get('account_number')
if not any([curp, account, has_name]):
curp, account, rfc = (
values.get('curp'),
values.get('account_number'),
values.get('rfc'),
)
if not any([curp, account, rfc, has_name]):
raise ValueError("At least 1 param is required")
return values

Expand All @@ -658,6 +663,7 @@ def check_request(cls, values):
json_schema_extra={
'example': {
'curp': 'GOCG650418HVZNML08',
'rfc': 'GOCG650418TJ1',
'account_number': '9203929392939292392',
'names': 'Pedrito',
'first_surname': 'Sola',
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.2'
__version__ = '2.1.3.dev1'
24 changes: 21 additions & 3 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,28 @@ def test_bank_account_validation_clabe_request():
assert BankAccountValidationRequest(account_number='646180157098510917')


def test_user_lists_request():
UserListsRequest(names='Pedro', first_surname='Paramo')
@pytest.mark.parametrize(
'input_data',
[
{'names': 'Pedro', 'first_surname': 'Paramo'},
{'curp': 'GOCG650418HVZNML08'},
{'rfc': 'GOCG650418TJ1'},
{'account_number': '646180157034181180'},
{
'curp': 'GOCG650418HVZNML08',
'rfc': 'GOCG650418TJ1',
'names': 'Pedro',
'first_surname': 'Paramo',
},
],
)
def test_user_lists_request_valid_params(input_data):
UserListsRequest(**input_data)


def test_user_lists_request_invalid_params():
with pytest.raises(ValueError):
UserListsRequest()
UserListsRequest(first_surname='Paramo', second_surname='Paramo')


class IntModel(BaseModel):
Expand Down

0 comments on commit cd17123

Please sign in to comment.