add tests for money amount
This commit is contained in:
parent
a29573320e
commit
eac16b53ba
1 changed files with 49 additions and 0 deletions
49
tests/tests_unit/test_money_amount.py
Normal file
49
tests/tests_unit/test_money_amount.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
from money.currency import Currency
|
||||
|
||||
from xexe.money_amount import MoneyAmount
|
||||
|
||||
|
||||
def test_money_amount_simple_creation_works():
|
||||
|
||||
an_amount = MoneyAmount(amount=10, currency=Currency.USD)
|
||||
|
||||
assert an_amount.amount == 10
|
||||
assert an_amount.currency == Currency.USD
|
||||
|
||||
|
||||
def test_money_amount_takes_integer_amounts():
|
||||
an_amount = MoneyAmount(amount=10, currency=Currency.USD)
|
||||
|
||||
assert an_amount.amount == 10
|
||||
|
||||
|
||||
def test_money_amount_takes_decimal_amounts():
|
||||
an_amount = MoneyAmount(amount=Decimal(10.5), currency=Currency.USD)
|
||||
|
||||
assert an_amount.amount == Decimal(10.5)
|
||||
|
||||
|
||||
def test_money_amount_takes_proper_strings_amounts():
|
||||
an_amount = MoneyAmount(amount="10.55", currency=Currency.USD)
|
||||
|
||||
assert an_amount.amount == Decimal(10.55)
|
||||
|
||||
|
||||
def test_money_amount_fails_with_ugly_strings():
|
||||
with pytest.raises(ValueError):
|
||||
MoneyAmount(amount="not a nuuuuumber", currency=Currency.USD)
|
||||
|
||||
|
||||
def test_money_amount_takes_string_for_currency():
|
||||
an_amount = MoneyAmount(amount="10.55", currency="USD")
|
||||
|
||||
assert an_amount.currency == Currency.USD
|
||||
|
||||
|
||||
def test_money_amount_works_with_8_decimal_positions():
|
||||
an_amount = MoneyAmount(amount="1.12345678", currency="USD")
|
||||
|
||||
assert an_amount == Decimal(1.12345678)
|
||||
Loading…
Add table
Add a link
Reference in a new issue