diff --git a/src/registrar/management/commands/extend_expiration_dates.py b/src/registrar/management/commands/extend_expiration_dates.py index 84d26e544..5e203e488 100644 --- a/src/registrar/management/commands/extend_expiration_dates.py +++ b/src/registrar/management/commands/extend_expiration_dates.py @@ -74,7 +74,7 @@ class Command(BaseCommand): valid_domains = Domain.objects.filter( expiration_date__gte=self.expiration_minimum_cutoff, expiration_date__lte=self.expiration_maximum_cutoff, - state=Domain.State.READY + state=Domain.State.READY, ).order_by("name") domains_to_change_count = valid_domains.count() diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 337b6f31e..ad34d53a7 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -835,6 +835,11 @@ class MockEppLib(TestCase): ex_date=datetime.date(2023, 2, 15), ) + mockMaximumRenewedDomainExpDate = fakedEppObject( + "fakemaximum.gov", + ex_date=datetime.date(2024, 12, 31), + ) + mockRecentRenewedDomainExpDate = fakedEppObject( "waterbutpurple.gov", ex_date=datetime.date(2024, 11, 15), @@ -948,6 +953,11 @@ class MockEppLib(TestCase): res_data=[self.mockDnsNeededRenewedDomainExpDate], code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY, ) + elif getattr(_request, "name", None) == "fakemaximum.gov": + return MagicMock( + res_data=[self.mockMaximumRenewedDomainExpDate], + code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY, + ) else: return MagicMock( res_data=[self.mockRenewedDomainExpDate], diff --git a/src/registrar/tests/test_transition_domain_migrations.py b/src/registrar/tests/test_transition_domain_migrations.py index 2da42462c..363dafc2c 100644 --- a/src/registrar/tests/test_transition_domain_migrations.py +++ b/src/registrar/tests/test_transition_domain_migrations.py @@ -52,6 +52,15 @@ class TestExtendExpirationDates(MockEppLib): domain_name="fakeneeded.gov", epp_expiration_date=datetime.date(2023, 11, 15), ) + # Create a domain with a date greater than the maximum + Domain.objects.get_or_create( + name="fakemaximum.gov", state=Domain.State.READY, expiration_date=datetime.date(2024, 12, 31) + ) + TransitionDomain.objects.get_or_create( + username="fakemaximum@mail.com", + domain_name="fakemaximum.gov", + epp_expiration_date=datetime.date(2024, 12, 31), + ) def tearDown(self): """Deletes all DB objects related to migrations""" @@ -114,6 +123,25 @@ class TestExtendExpirationDates(MockEppLib): # should not be affected by the change. self.assertEqual(current_domain.expiration_date, datetime.date(2022, 5, 25)) + def test_extends_expiration_date_skips_maximum_date(self): + """ + Tests that the extend_expiration_dates method correctly skips domains + with an expiration date more than a certain threshold. + """ + desired_domain = Domain.objects.filter(name="fakemaximum.gov").get() + desired_domain.expiration_date = datetime.date(2024, 12, 31) + + # Run the expiration date script + self.run_extend_expiration_dates() + + current_domain = Domain.objects.filter(name="fakemaximum.gov").get() + self.assertEqual(desired_domain, current_domain) + + # Explicitly test the expiration date. The extend_expiration_dates script + # will skip all dates less than date(2023, 11, 15), meaning that this domain + # should not be affected by the change. + self.assertEqual(current_domain.expiration_date, datetime.date(2024, 12, 31)) + def test_extends_expiration_date_skips_non_ready(self): """ Tests that the extend_expiration_dates method correctly skips domains not in the state "ready"