Revision fc7747df7177f2f610c55c9709a81e7b0b618806 authored by Jochen Kupperschmidt on 03 January 2026, 00:21:02 UTC, committed by Jochen Kupperschmidt on 03 January 2026, 00:21:02 UTC
1 parent 2e587a4
test_calculate_total_amount.py
"""
:Copyright: 2014-2025 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""
from moneyed import EUR, Money
import pytest
from byceps.services.shop.product import product_domain_service
from byceps.services.shop.product.models import ProductWithQuantity
def test_calculate_total_amount_without_products():
with pytest.raises(ValueError):
product_domain_service.calculate_total_amount([])
@pytest.mark.parametrize(
('price_strs_and_quantities', 'expected_total_str'),
[
(
[
('0.00', 3),
],
'0.00',
),
(
[
('1.99', 2),
],
'3.98',
),
(
[
('1.99', 3),
('3.50', 1),
('16.25', 8),
],
'139.47',
),
],
)
def test_calculate_total_amount_with_products(
make_product, price_strs_and_quantities, expected_total_str: str
):
products_with_quantities = [
ProductWithQuantity(make_product(price=Money(price, EUR)), quantity)
for price, quantity in price_strs_and_quantities
]
expected = Money(expected_total_str, EUR)
actual = product_domain_service.calculate_total_amount(
products_with_quantities
)
assert actual == expected

Computing file changes ...