test_item_collection.py 1017 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import pytest
  2. import finoex
  3. import ioex.calcex
  4. def get_item_a(currency='EUR'):
  5. return finoex.Item(
  6. name='a',
  7. price_brutto=finoex.Sum(2.0, currency),
  8. )
  9. def get_item_b():
  10. return finoex.Item(
  11. name='b',
  12. price_brutto=finoex.Sum(3.0, 'EUR'),
  13. sub_items=[get_item_a(), get_item_a()],
  14. )
  15. @pytest.mark.parametrize(('items', 'expected_total'), [
  16. [[], 0],
  17. [[get_item_a()], finoex.Sum(2.0, 'EUR')],
  18. [[get_item_b()], finoex.Sum(7.0, 'EUR')],
  19. [[get_item_a(), get_item_b()], finoex.Sum(9.0, 'EUR')],
  20. ])
  21. def test_get_items_total_price_brutto(items, expected_total):
  22. c = finoex._ItemCollection(items=items)
  23. assert expected_total == c.items_total_price_brutto
  24. @pytest.mark.parametrize(('items'), [
  25. [get_item_a(currency='EUR'), get_item_a(currency='USD')],
  26. ])
  27. def test_get_items_total_price_brutto_fail(items):
  28. c = finoex._ItemCollection(items=items)
  29. with pytest.raises(ioex.calcex.UnitMismatchError):
  30. c.items_total_price_brutto