Merge pull request #1391 from cisagov/dk/1218-update-expiration-date

Issue #1218 - Update the stored expiration date value anytime it's received (STAGED ON BL)
This commit is contained in:
dave-kennedy-ecs 2023-11-27 20:08:59 -05:00 committed by GitHub
commit 211d22da6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View file

@ -212,11 +212,9 @@ class Domain(TimeStampedModel, DomainHelper):
@Cache @Cache
def registry_expiration_date(self) -> date: def registry_expiration_date(self) -> date:
"""Get or set the `ex_date` element from the registry. """Get or set the `ex_date` element from the registry.
Additionally, update the expiration date in the registrar""" Additionally, _get_property updates the expiration date in the registrar"""
try: try:
self.expiration_date = self._get_property("ex_date") return self._get_property("ex_date")
self.save()
return self.expiration_date
except Exception as e: except Exception as e:
# exception raised during the save to registrar # exception raised during the save to registrar
logger.error(f"error updating expiration date in registrar: {e}") logger.error(f"error updating expiration date in registrar: {e}")
@ -1610,6 +1608,12 @@ class Domain(TimeStampedModel, DomainHelper):
if old_cache_contacts is not None: if old_cache_contacts is not None:
cleaned["contacts"] = old_cache_contacts cleaned["contacts"] = old_cache_contacts
# if expiration date from registry does not match what is in db,
# update the db
if "ex_date" in cleaned and cleaned["ex_date"] != self.expiration_date:
self.expiration_date = cleaned["ex_date"]
self.save()
self._cache = cleaned self._cache = cleaned
except RegistryError as e: except RegistryError as e:

View file

@ -617,6 +617,7 @@ class MockEppLib(TestCase):
common.Status(state="serverTransferProhibited", description="", lang="en"), common.Status(state="serverTransferProhibited", description="", lang="en"),
common.Status(state="inactive", description="", lang="en"), common.Status(state="inactive", description="", lang="en"),
], ],
ex_date=datetime.date(2023, 5, 25),
) )
mockDataInfoContact = mockDataInfoDomain.dummyInfoContactResultData( mockDataInfoContact = mockDataInfoDomain.dummyInfoContactResultData(
"123", "123@mail.gov", datetime.datetime(2023, 5, 25, 19, 45, 35), "lastPw" "123", "123@mail.gov", datetime.datetime(2023, 5, 25, 19, 45, 35), "lastPw"

View file

@ -1987,6 +1987,13 @@ class TestExpirationDate(MockEppLib):
with self.assertRaises(RegistryError): with self.assertRaises(RegistryError):
self.domain_w_error.renew_domain() self.domain_w_error.renew_domain()
def test_expiration_date_updated_on_info_domain_call(self):
"""assert that expiration date in db is updated on info domain call"""
# force fetch_cache to be called
self.domain.statuses
test_date = datetime.date(2023, 5, 25)
self.assertEquals(self.domain.expiration_date, test_date)
class TestAnalystClientHold(MockEppLib): class TestAnalystClientHold(MockEppLib):
"""Rule: Analysts may suspend or restore a domain by using client hold""" """Rule: Analysts may suspend or restore a domain by using client hold"""