Skip to content

Commit

Permalink
fix UserListsRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
rogelioLpz committed Nov 22, 2023
1 parent e3c6e2a commit 73fa6d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
23 changes: 13 additions & 10 deletions cuenca_validations/types/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,19 @@ class BankAccountValidationRequest(BaseModel):


class UserListsRequest(BaseModel):
curp: Optional[CurpField]
account_number: Optional[Union[Clabe, PaymentCardNumber]]
names: Optional[str]
first_surname: Optional[str]
second_surname: Optional[str]
curp: Optional[CurpField] = None
account_number: Optional[Union[Clabe, PaymentCardNumber]] = None
names: Optional[str] = None
first_surname: Optional[str] = None
second_surname: Optional[str] = None

@root_validator()
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]):
raise ValueError("At least 1 param is required")
return values

class Config:
anystr_strip_whitespace = True
Expand All @@ -689,8 +697,3 @@ class Config:
'second_surname': 'Sola',
}
}

def has_names(self) -> bool:
if self.names and self.first_surname:
return True
return False
2 changes: 1 addition & 1 deletion cuenca_validations/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.11.20'
__version__ = '0.11.21.dev0'
7 changes: 3 additions & 4 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ def test_rfc_field():


def test_user_lists_request():
request = UserListsRequest(names='Pedro', first_surname='Paramo')
assert request.has_names()
request = UserListsRequest()
assert not request.has_names()
UserListsRequest(names='Pedro', first_surname='Paramo')
with pytest.raises(ValueError) as ex:
UserListsRequest()

0 comments on commit 73fa6d3

Please sign in to comment.