mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-14 05:29:43 +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.
|
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:
|
if "statuses" not in self._cache:
|
||||||
self._fetch_cache()
|
try:
|
||||||
if "statuses" not in self._cache:
|
return self._get_property("statuses")
|
||||||
raise Exception("Can't retrieve status from domain info")
|
except KeyError:
|
||||||
else:
|
logger.error("Can't retrieve status from domain info")
|
||||||
return self._cache["statuses"]
|
|
||||||
|
|
||||||
@statuses.setter # type: ignore
|
@statuses.setter # type: ignore
|
||||||
def statuses(self, statuses: list[str]):
|
def statuses(self, statuses: list[str]):
|
||||||
|
|
|
@ -547,17 +547,19 @@ class MockEppLib(TestCase):
|
||||||
class fakedEppObject(object):
|
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.auth_info = auth_info
|
||||||
self.cr_date = cr_date
|
self.cr_date = cr_date
|
||||||
self.contacts = contacts
|
self.contacts = contacts
|
||||||
self.hosts = hosts
|
self.hosts = hosts
|
||||||
|
self.statuses = statuses
|
||||||
|
|
||||||
mockDataInfoDomain = fakedEppObject(
|
mockDataInfoDomain = fakedEppObject(
|
||||||
"fakepw",
|
"fakepw",
|
||||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||||
contacts=[common.DomainContact(contact="123", type="security")],
|
contacts=[common.DomainContact(contact="123", type="security")],
|
||||||
hosts=["fake.host.com"],
|
hosts=["fake.host.com"],
|
||||||
|
statuses=[common.Status(state='serverTransferProhibited', description=None, lang='en'), common.Status(state='inactive', description=None, lang='en')],
|
||||||
)
|
)
|
||||||
infoDomainNoContact = fakedEppObject(
|
infoDomainNoContact = fakedEppObject(
|
||||||
"security",
|
"security",
|
||||||
|
|
|
@ -34,6 +34,8 @@ class TestDomainCache(MockEppLib):
|
||||||
# (see InfoDomainResult)
|
# (see InfoDomainResult)
|
||||||
self.assertEquals(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
self.assertEquals(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
||||||
self.assertEquals(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date)
|
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())
|
self.assertFalse("avail" in domain._cache.keys())
|
||||||
|
|
||||||
# using a setter should clear the cache
|
# 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.InfoContact(id="123", auth_info=None), cleaned=True),
|
||||||
call(commands.InfoHost(name="fake.host.com"), 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):
|
def test_cache_used_when_avail(self):
|
||||||
|
@ -168,22 +171,37 @@ class TestDomainCreation(TestCase):
|
||||||
with self.assertRaisesRegex(IntegrityError, "name"):
|
with self.assertRaisesRegex(IntegrityError, "name"):
|
||||||
Domain.objects.create(name="igorville.gov")
|
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:
|
def tearDown(self) -> None:
|
||||||
DomainInformation.objects.all().delete()
|
DomainInformation.objects.all().delete()
|
||||||
DomainApplication.objects.all().delete()
|
DomainApplication.objects.all().delete()
|
||||||
Domain.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):
|
class TestRegistrantContacts(MockEppLib):
|
||||||
"""Rule: Registrants may modify their WHOIS data"""
|
"""Rule: Registrants may modify their WHOIS data"""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue