diff --git a/cuenca_validations/types/requests.py b/cuenca_validations/types/requests.py index 6066238e..c293d517 100644 --- a/cuenca_validations/types/requests.py +++ b/cuenca_validations/types/requests.py @@ -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 @@ -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 diff --git a/cuenca_validations/version.py b/cuenca_validations/version.py index b250e77c..f7c313e1 100644 --- a/cuenca_validations/version.py +++ b/cuenca_validations/version.py @@ -1 +1 @@ -__version__ = '0.11.22' +__version__ = '0.11.23' diff --git a/tests/test_types.py b/tests/test_types.py index 77e6a25a..e261dba6 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -550,7 +550,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): + UserListsRequest()