mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 02:49:21 +02:00
Add unit tests
This commit is contained in:
parent
ea7d34907c
commit
2481e89c2a
3 changed files with 39 additions and 1 deletions
|
@ -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()
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue