"""Unit tests for calendar/ticket total functions.""" from __future__ import annotations from decimal import Decimal from types import SimpleNamespace import pytest from cart.bp.cart.services.calendar_cart import calendar_total, ticket_total def _entry(cost): return SimpleNamespace(cost=cost) def _ticket(price): return SimpleNamespace(price=price) class TestCalendarTotal: def test_empty(self): assert calendar_total([]) == 0 def test_single_entry(self): assert calendar_total([_entry(25.0)]) == Decimal("25.0") def test_none_cost_excluded(self): result = calendar_total([_entry(None)]) assert result == 0 def test_zero_cost(self): # cost=0 is falsy, so it produces Decimal(0) via the else branch result = calendar_total([_entry(0)]) assert result == Decimal("0") def test_multiple(self): result = calendar_total([_entry(10.0), _entry(20.0)]) assert result == Decimal("30.0") class TestTicketTotal: def test_empty(self): assert ticket_total([]) == Decimal("0") def test_single_ticket(self): assert ticket_total([_ticket(15.0)]) == Decimal("15.0") def test_none_price_treated_as_zero(self): # ticket_total includes all tickets, None → Decimal(0) result = ticket_total([_ticket(None)]) assert result == Decimal("0") def test_multiple(self): result = ticket_total([_ticket(5.0), _ticket(10.0)]) assert result == Decimal("15.0") def test_mixed_with_none(self): result = ticket_total([_ticket(10.0), _ticket(None), _ticket(5.0)]) assert result == Decimal("15.0")