Skip to content

Commit

Permalink
exclude_none=True (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipao-mx authored Feb 12, 2021
1 parent e5e2e40 commit bb35a64
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
21 changes: 14 additions & 7 deletions cuenca_validations/types/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
from .general import StrictPositiveInt


class TransferRequest(BaseModel):
class BaseRequest(BaseModel):
class Config:
extra = Extra.forbid

def dict(self, *args, **kwargs) -> DictStrAny:
kwargs.setdefault('exclude_none', True)
kwargs.setdefault('exclude_unset', True)
return super().dict(*args, **kwargs)


class TransferRequest(BaseRequest):
recipient_name: StrictStr
account_number: Union[Clabe, PaymentCardNumber]
amount: StrictPositiveInt # in centavos
Expand All @@ -21,20 +31,17 @@ class StrictTransferRequest(TransferRequest):
account_number: Union[Clabe, StrictPaymentCardNumber]


class CardUpdateRequest(BaseModel):
class CardUpdateRequest(BaseRequest):
user_id: Optional[str]
ledger_account_id: Optional[str]
status: Optional[CardStatus]

class Config:
extra = Extra.forbid


class CardRequest(BaseModel):
class CardRequest(BaseRequest):
user_id: str
ledger_account_id: str


class ApiKeyUpdateRequest(BaseModel):
class ApiKeyUpdateRequest(BaseRequest):
user_id: Optional[str]
metadata: Optional[DictStrAny]
2 changes: 1 addition & 1 deletion cuenca_validations/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.4'
__version__ = '0.7.5'
6 changes: 6 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
TransactionStatus,
digits,
)
from cuenca_validations.types.requests import CardUpdateRequest

today = dt.date.today()
now = dt.datetime.now()
Expand Down Expand Up @@ -148,3 +149,8 @@ def test_card_query_exp_cvv_if_number_set():
def test_card_query_exp_cvv_if_number_not_set(input_value):
with pytest.raises(ValueError):
CardQuery(**input_value)


def test_exclude_none_in_dict():
request = CardUpdateRequest(user_id='US123')
assert request.dict() == dict(user_id='US123')

0 comments on commit bb35a64

Please sign in to comment.