Skip to content

Commit

Permalink
test: get_from_and_to_date
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Sep 14, 2024
1 parent 6884846 commit fafc39b
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from .simple_subscription import (
get_calendar_period,
get_date_period,
get_from_and_to_date,
Frequency,
PeriodType,
BillingTime,
)


Expand Down Expand Up @@ -52,3 +55,54 @@ def test_get_date_period(self):
self.assertEqual(from_date, date(2022, 6, 25))
self.assertEqual(to_date, date(2023, 6, 24))

def test_get_from_and_to_date(self):
from_date, to_date = get_from_and_to_date(
frequency=Frequency.Monthly,
period_type=PeriodType.CalendarMonths,
billing_time=BillingTime.AtBeginningOfPeriod,
eval_date=date(2022, 11, 7),
start_date=date(2022, 11, 7),
)
self.assertEqual(from_date, date(2022, 11, 1))
self.assertEqual(to_date, date(2022, 11, 30))

from_date, to_date = get_from_and_to_date(
frequency=Frequency.Monthly,
period_type=PeriodType.CalendarMonths,
billing_time=BillingTime.AfterEndOfPeriod,
eval_date=date(2022, 11, 7),
start_date=date(2022, 10, 1),
)
self.assertEqual(from_date, date(2022, 10, 1))
self.assertEqual(to_date, date(2022, 10, 31))

# previous behavior should be the default
from_date, to_date = get_from_and_to_date(
frequency=Frequency.Monthly,
period_type=None,
billing_time=None,
eval_date=date(2022, 11, 7),
start_date=date(2022, 10, 1),
)
self.assertEqual(from_date, date(2022, 10, 1))
self.assertEqual(to_date, date(2022, 10, 31))

from_date, to_date = get_from_and_to_date(
frequency=Frequency.Monthly,
period_type=PeriodType.StartDate,
billing_time=BillingTime.AtBeginningOfPeriod,
eval_date=date(2022, 11, 7),
start_date=date(2022, 11, 5),
)
self.assertEqual(from_date, date(2022, 11, 5))
self.assertEqual(to_date, date(2022, 12, 4))

from_date, to_date = get_from_and_to_date(
frequency=Frequency.Monthly,
period_type=PeriodType.StartDate,
billing_time=BillingTime.AfterEndOfPeriod,
eval_date=date(2022, 11, 7),
start_date=date(2022, 10, 5),
)
self.assertEqual(from_date, date(2022, 10, 5))
self.assertEqual(to_date, date(2022, 11, 4))

0 comments on commit fafc39b

Please sign in to comment.