from datetime import datetime, date, timezone from django.test import TestCase from labs.billing.utils import round_to_end_of_day, round_to_start_of_day class TestBillingUtils(TestCase): def test_round_to_end_of_day(self): self.assertEqual( round_to_end_of_day(datetime(2021, 1, 1, 12, 0, 0)), datetime(2021, 1, 2, 0, 0, 0), ) def test_round_to_start_of_day(self): self.assertEqual( round_to_start_of_day(datetime(2021, 1, 1, 12, 0, 0)), datetime(2021, 1, 1, 0, 0, 0), ) def test_round_to_end_of_day_with_timezone(self): self.assertEqual( round_to_end_of_day(datetime(2021, 1, 1, 12, 0, 0, tzinfo=timezone.utc)), datetime(2021, 1, 2, 0, 0, 0, tzinfo=timezone.utc), ) def test_round_to_start_of_day_with_timezone(self): self.assertEqual( round_to_start_of_day(datetime(2021, 1, 1, 12, 0, 0, tzinfo=timezone.utc)), datetime(2021, 1, 1, 0, 0, 0, tzinfo=timezone.utc), ) def test_round_to_end_of_day_with_date(self): self.assertEqual( round_to_end_of_day(date(2021, 1, 1)), datetime(2021, 1, 2, 0, 0, 0) ) def test_round_to_start_of_day_with_date(self): self.assertEqual( round_to_start_of_day(date(2021, 1, 1)), datetime(2021, 1, 1, 0, 0, 0) )