mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 17:01:56 +02:00
refactor status getter, add unit test
This commit is contained in:
parent
68012389a8
commit
76a2a1a6fd
3 changed files with 36 additions and 19 deletions
|
@ -336,14 +336,11 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
|
||||
A domain's status indicates various properties. See Domain.Status.
|
||||
"""
|
||||
# implementation note: the Status object from EPP stores the string in
|
||||
# a dataclass property `state`, not to be confused with the `state` field here
|
||||
if "statuses" not in self._cache:
|
||||
self._fetch_cache()
|
||||
if "statuses" not in self._cache:
|
||||
raise Exception("Can't retrieve status from domain info")
|
||||
else:
|
||||
return self._cache["statuses"]
|
||||
try:
|
||||
return self._get_property("statuses")
|
||||
except KeyError:
|
||||
logger.error("Can't retrieve status from domain info")
|
||||
|
||||
@statuses.setter # type: ignore
|
||||
def statuses(self, statuses: list[str]):
|
||||
|
|
|
@ -547,17 +547,19 @@ class MockEppLib(TestCase):
|
|||
class fakedEppObject(object):
|
||||
""""""
|
||||
|
||||
def __init__(self, auth_info=..., cr_date=..., contacts=..., hosts=...):
|
||||
def __init__(self, auth_info=..., cr_date=..., contacts=..., hosts=..., statuses=...,):
|
||||
self.auth_info = auth_info
|
||||
self.cr_date = cr_date
|
||||
self.contacts = contacts
|
||||
self.hosts = hosts
|
||||
self.statuses = statuses
|
||||
|
||||
mockDataInfoDomain = fakedEppObject(
|
||||
"fakepw",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
contacts=[common.DomainContact(contact="123", type="security")],
|
||||
hosts=["fake.host.com"],
|
||||
statuses=[common.Status(state='serverTransferProhibited', description=None, lang='en'), common.Status(state='inactive', description=None, lang='en')],
|
||||
)
|
||||
infoDomainNoContact = fakedEppObject(
|
||||
"security",
|
||||
|
|
|
@ -34,6 +34,8 @@ class TestDomainCache(MockEppLib):
|
|||
# (see InfoDomainResult)
|
||||
self.assertEquals(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
||||
self.assertEquals(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date)
|
||||
status_list = [status.state for status in self.mockDataInfoDomain.statuses]
|
||||
self.assertEquals(domain._cache["statuses"], status_list)
|
||||
self.assertFalse("avail" in domain._cache.keys())
|
||||
|
||||
# using a setter should clear the cache
|
||||
|
@ -49,7 +51,8 @@ class TestDomainCache(MockEppLib):
|
|||
),
|
||||
call(commands.InfoContact(id="123", auth_info=None), cleaned=True),
|
||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||
]
|
||||
],
|
||||
any_order=False # Ensure calls are in the specified order
|
||||
)
|
||||
|
||||
def test_cache_used_when_avail(self):
|
||||
|
@ -168,22 +171,37 @@ class TestDomainCreation(TestCase):
|
|||
with self.assertRaisesRegex(IntegrityError, "name"):
|
||||
Domain.objects.create(name="igorville.gov")
|
||||
|
||||
@skip("cannot activate a domain without mock registry")
|
||||
def test_get_status(self):
|
||||
"""Returns proper status based on `state`."""
|
||||
domain = Domain.objects.create(name="igorville.gov")
|
||||
domain.save()
|
||||
self.assertEqual(None, domain.status)
|
||||
domain.activate()
|
||||
domain.save()
|
||||
self.assertIn("ok", domain.status)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
DomainInformation.objects.all().delete()
|
||||
DomainApplication.objects.all().delete()
|
||||
Domain.objects.all().delete()
|
||||
|
||||
|
||||
class TestDomainStatuses(MockEppLib):
|
||||
|
||||
def test_get_status(self):
|
||||
"""Getter returns statuses"""
|
||||
domain, _ = Domain.objects.get_or_create(name="igorville2.gov")
|
||||
_ = domain.statuses
|
||||
status_list = [status.state for status in self.mockDataInfoDomain.statuses]
|
||||
self.assertEquals(domain._cache["statuses"], status_list)
|
||||
|
||||
# print(self.mockedSendFunction.call_args_list)
|
||||
|
||||
# Called in _fetch_cache
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
call(commands.InfoDomain(name='igorville2.gov', auth_info=None), cleaned=True),
|
||||
call(commands.InfoContact(id='123', auth_info=None), cleaned=True),
|
||||
call(commands.InfoHost(name='fake.host.com'), cleaned=True)
|
||||
],
|
||||
any_order=False # Ensure calls are in the specified order
|
||||
)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
Domain.objects.all().delete()
|
||||
|
||||
|
||||
class TestRegistrantContacts(MockEppLib):
|
||||
"""Rule: Registrants may modify their WHOIS data"""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue