feat: add max 2 decimal places validation to Money
This commit is contained in:
@@ -37,3 +37,26 @@ def test_money_substract():
|
||||
money1 = Money(amount=Decimal("5.00"))
|
||||
money2 = Money(amount=Decimal("3.00"))
|
||||
assert (money1 - money2) == Money(amount=Decimal("2.00"))
|
||||
|
||||
|
||||
def test_money_can_not_have_more_than_two_decimals():
|
||||
try:
|
||||
Money(amount=Decimal("1.234"))
|
||||
assert False, "Should have raised ValueError"
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_money_allows_two_decimals():
|
||||
money = Money(amount=Decimal("1.23"))
|
||||
assert money.amount == Decimal("1.23")
|
||||
|
||||
|
||||
def test_money_allows_one_decimal():
|
||||
money = Money(amount=Decimal("1.2"))
|
||||
assert money.amount == Decimal("1.2")
|
||||
|
||||
|
||||
def test_money_allows_no_decimals():
|
||||
money = Money(amount=Decimal(1))
|
||||
assert money.amount == Decimal(1)
|
||||
|
||||
Reference in New Issue
Block a user