Files

65 lines
1.5 KiB
Python

from datetime import date
from utils import get_billing_period
def test_get_billing_period():
assert get_billing_period(
billing_day=15,
date_=date(2023, 3, 20),
) == (date(2023, 3, 15), date(2023, 4, 14))
assert get_billing_period(
billing_day=15,
date_=date(2023, 3, 10),
) == (date(2023, 2, 15), date(2023, 3, 14))
# Leap year
assert get_billing_period(
billing_day=30,
date_=date(year=2028, month=2, day=1),
) == (
date(2028, 1, 30),
date(2028, 2, 28),
)
# Leap year
assert get_billing_period(
billing_day=29,
date_=date(year=2028, month=3, day=1),
) == (
date(2028, 2, 29),
date(2028, 3, 28),
)
assert get_billing_period(
billing_day=28,
date_=date(year=2025, month=2, day=28),
) == (
date(2025, 2, 28),
date(2025, 3, 27),
)
assert get_billing_period(
billing_day=5,
date_=date(year=2025, month=12, day=1),
) == (
date(2025, 11, 5),
date(2025, 12, 4),
)
assert get_billing_period(billing_day=25, date_=date(2025, 12, 14)) == (
date(2025, 11, 25),
date(2025, 12, 24),
)
assert get_billing_period(billing_day=25, date_=date(2025, 1, 14)) == (
date(2024, 12, 25),
date(2025, 1, 24),
)
assert get_billing_period(10, date(2024, 1, 5)) == (
date(2023, 12, 10),
date(2024, 1, 9),
)