mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-14 21:44:08 +02:00
Fix test interference issue
This commit is contained in:
parent
4a561ad4c6
commit
d9679cf010
3 changed files with 288 additions and 169 deletions
|
@ -695,7 +695,8 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
streets = {}
|
streets = {}
|
||||||
if addr is not None and addr.street is not None:
|
if addr is not None and addr.street is not None:
|
||||||
# 'zips' two lists together.
|
# 'zips' two lists together.
|
||||||
# For instance, (('street1', 'some_value_here'), ('street2', 'some_value_here'))
|
# For instance, (('street1', 'some_value_here'),
|
||||||
|
# ('street2', 'some_value_here'))
|
||||||
# Dict then converts this to a useable kwarg which we can pass in
|
# Dict then converts this to a useable kwarg which we can pass in
|
||||||
streets = dict(
|
streets = dict(
|
||||||
zip_longest(
|
zip_longest(
|
||||||
|
@ -734,7 +735,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
contact.contact_type,
|
contact.contact_type,
|
||||||
error.code,
|
error.code,
|
||||||
error,
|
error,
|
||||||
)
|
) # noqa
|
||||||
raise error
|
raise error
|
||||||
|
|
||||||
def get_contact_default(
|
def get_contact_default(
|
||||||
|
@ -776,17 +777,18 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
or cache_contact_helper("security")
|
or cache_contact_helper("security")
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# TODO - refactor
|
||||||
desired_property = "contacts"
|
desired_property = "contacts"
|
||||||
# The contact type 'registrant' is stored under a different property
|
# The contact type 'registrant' is stored under a different property
|
||||||
if contact_type_choice == PublicContact.ContactTypeChoices.REGISTRANT:
|
if contact_type_choice == PublicContact.ContactTypeChoices.REGISTRANT:
|
||||||
desired_property = "registrant"
|
desired_property = "registrant"
|
||||||
logger.debug(f"generic domain getter was called. Wanting contacts on {contact_type_choice}")
|
|
||||||
contacts = self._get_property(desired_property)
|
contacts = self._get_property(desired_property)
|
||||||
if contact_type_choice == PublicContact.ContactTypeChoices.REGISTRANT:
|
if contact_type_choice == PublicContact.ContactTypeChoices.REGISTRANT:
|
||||||
contacts = [contacts]
|
contacts = [contacts]
|
||||||
except KeyError as error:
|
except KeyError as error:
|
||||||
logger.warning("generic_contact_getter -> Contact does not exist")
|
logger.warning("generic_contact_getter -> Contact does not exist")
|
||||||
logger.warning(error)
|
logger.warning(error)
|
||||||
|
# Should we just raise an error instead?
|
||||||
return self.get_contact_default(contact_type_choice)
|
return self.get_contact_default(contact_type_choice)
|
||||||
else:
|
else:
|
||||||
print(f"generic_contact_getter -> contacts?? {contacts}")
|
print(f"generic_contact_getter -> contacts?? {contacts}")
|
||||||
|
@ -1123,38 +1125,27 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
"tr_date": getattr(data, "tr_date", ...),
|
"tr_date": getattr(data, "tr_date", ...),
|
||||||
"up_date": getattr(data, "up_date", ...),
|
"up_date": getattr(data, "up_date", ...),
|
||||||
}
|
}
|
||||||
print(f"precleaned stuff {cache}")
|
|
||||||
# remove null properties (to distinguish between "a value of None" and null)
|
# remove null properties (to distinguish between "a value of None" and null)
|
||||||
cleaned = {k: v for k, v in cache.items() if v is not ...}
|
cleaned = {k: v for k, v in cache.items() if v is not ...}
|
||||||
l = getattr(data, "contacts", ...)
|
|
||||||
logger.debug(f"here are the contacts {l}")
|
|
||||||
# statuses can just be a list no need to keep the epp object
|
# statuses can just be a list no need to keep the epp object
|
||||||
if "statuses" in cleaned.keys():
|
if "statuses" in cleaned.keys():
|
||||||
cleaned["statuses"] = [status.state for status in cleaned["statuses"]]
|
cleaned["statuses"] = [status.state for status in cleaned["statuses"]]
|
||||||
|
|
||||||
# Registrant should be of type PublicContact
|
# Registrant should be of type PublicContact
|
||||||
if "registrant" in cleaned.keys():
|
if "registrant" in cleaned.keys():
|
||||||
try:
|
# For linter...
|
||||||
contact = PublicContact(
|
_ = cleaned["registrant"]
|
||||||
registry_id=cleaned["registrant"],
|
# Registrant, if it exists, should always exist in EppLib.
|
||||||
contact_type=PublicContact.ContactTypeChoices.REGISTRANT,
|
# If it doesn't, that is bad. We expect this to exist, always.
|
||||||
)
|
cleaned["registrant"] = self._registrant_to_public_contact(_)
|
||||||
# Grabs the expanded contact
|
|
||||||
full_object = self._request_contact_info(contact)
|
|
||||||
# Maps it to type PublicContact
|
|
||||||
cleaned["registrant"] = self.map_epp_contact_to_public_contact(
|
|
||||||
full_object, contact.registry_id, contact.contact_type
|
|
||||||
)
|
|
||||||
except RegistryError:
|
|
||||||
cleaned["registrant"] = None
|
|
||||||
# get contact info, if there are any
|
|
||||||
if (
|
if (
|
||||||
# fetch_contacts and
|
# fetch_contacts and
|
||||||
"_contacts" in cleaned
|
"_contacts" in cleaned.keys()
|
||||||
and isinstance(cleaned["_contacts"], list)
|
and isinstance(cleaned["_contacts"], list)
|
||||||
and len(cleaned["_contacts"])
|
and len(cleaned["_contacts"]) > 0
|
||||||
):
|
):
|
||||||
logger.debug("hit!")
|
|
||||||
cleaned["contacts"] = []
|
cleaned["contacts"] = []
|
||||||
for domainContact in cleaned["_contacts"]:
|
for domainContact in cleaned["_contacts"]:
|
||||||
# we do not use _get_or_create_* because we expect the object we
|
# we do not use _get_or_create_* because we expect the object we
|
||||||
|
@ -1162,7 +1153,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
# if not, that's a problem
|
# if not, that's a problem
|
||||||
|
|
||||||
# TODO- discuss-should we check if contact is in public contacts
|
# TODO- discuss-should we check if contact is in public contacts
|
||||||
# and add it if not- this is really to keep in mine the transisiton
|
# and add it if not- this is really to keep in mind for the transition
|
||||||
req = commands.InfoContact(id=domainContact.contact)
|
req = commands.InfoContact(id=domainContact.contact)
|
||||||
data = registry.send(req, cleaned=True).res_data[0]
|
data = registry.send(req, cleaned=True).res_data[0]
|
||||||
|
|
||||||
|
@ -1183,30 +1174,62 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
# no point in removing
|
# no point in removing
|
||||||
cleaned["hosts"] = []
|
cleaned["hosts"] = []
|
||||||
for name in cleaned["_hosts"]:
|
for name in cleaned["_hosts"]:
|
||||||
|
# For reviewers - slight refactor here
|
||||||
|
# as we may need this for future hosts tickets
|
||||||
|
# (potential host mapper?).
|
||||||
|
# Can remove if unnecessary
|
||||||
|
cleaned["hosts"].append(self._get_host_as_dict(name))
|
||||||
|
# replace the prior cache with new data
|
||||||
|
self._cache = cleaned
|
||||||
|
|
||||||
|
except RegistryError as e:
|
||||||
|
logger.error(e)
|
||||||
|
|
||||||
|
def _registrant_to_public_contact(self, registry_id: str):
|
||||||
|
""" EPPLib returns the registrant as a string,
|
||||||
|
which is the registrants associated registry_id. This function is used to
|
||||||
|
convert that id to a useable object by calling commands.InfoContact
|
||||||
|
on that ID, then mapping that object to type PublicContact. """
|
||||||
|
contact = PublicContact(
|
||||||
|
registry_id=registry_id,
|
||||||
|
contact_type=PublicContact.ContactTypeChoices.REGISTRANT,
|
||||||
|
)
|
||||||
|
# Grabs the expanded contact
|
||||||
|
full_object = self._request_contact_info(contact)
|
||||||
|
# Maps it to type PublicContact
|
||||||
|
return self.map_epp_contact_to_public_contact(
|
||||||
|
full_object, contact.registry_id, contact.contact_type
|
||||||
|
)
|
||||||
|
|
||||||
|
def _get_host_as_dict(self, host_name):
|
||||||
|
"""Returns the result of commands.InfoHost as a dictionary
|
||||||
|
|
||||||
|
Returns the following, excluding null fields:
|
||||||
|
{
|
||||||
|
"name": name,
|
||||||
|
"addrs": addr,
|
||||||
|
"cr_date": cr_date,
|
||||||
|
"statuses": statuses,
|
||||||
|
"tr_date": tr_date,
|
||||||
|
"up_date": up_date,
|
||||||
|
}
|
||||||
|
"""
|
||||||
# we do not use _get_or_create_* because we expect the object we
|
# we do not use _get_or_create_* because we expect the object we
|
||||||
# just asked the registry for still exists --
|
# just asked the registry for still exists --
|
||||||
# if not, that's a problem
|
# if not, that's a problem
|
||||||
req = commands.InfoHost(name=name)
|
req = commands.InfoHost(name=host_name)
|
||||||
data = registry.send(req, cleaned=True).res_data[0]
|
data = registry.send(req, cleaned=True).res_data[0]
|
||||||
# extract properties from response
|
# extract properties from response
|
||||||
# (Ellipsis is used to mean "null")
|
# (Ellipsis is used to mean "null")
|
||||||
host = {
|
host = {
|
||||||
"name": name,
|
"name": host_name,
|
||||||
"addrs": getattr(data, "addrs", ...),
|
"addrs": getattr(data, "addrs", ...),
|
||||||
"cr_date": getattr(data, "cr_date", ...),
|
"cr_date": getattr(data, "cr_date", ...),
|
||||||
"statuses": getattr(data, "statuses", ...),
|
"statuses": getattr(data, "statuses", ...),
|
||||||
"tr_date": getattr(data, "tr_date", ...),
|
"tr_date": getattr(data, "tr_date", ...),
|
||||||
"up_date": getattr(data, "up_date", ...),
|
"up_date": getattr(data, "up_date", ...),
|
||||||
}
|
}
|
||||||
cleaned["hosts"].append(
|
return {k: v for k, v in host.items() if v is not ...}
|
||||||
{k: v for k, v in host.items() if v is not ...}
|
|
||||||
)
|
|
||||||
|
|
||||||
# replace the prior cache with new data
|
|
||||||
self._cache = cleaned
|
|
||||||
|
|
||||||
except RegistryError as e:
|
|
||||||
logger.error(e)
|
|
||||||
|
|
||||||
def _invalidate_cache(self):
|
def _invalidate_cache(self):
|
||||||
"""Remove cache data when updates are made."""
|
"""Remove cache data when updates are made."""
|
||||||
|
|
|
@ -557,7 +557,12 @@ class MockEppLib(TestCase):
|
||||||
self.hosts = hosts
|
self.hosts = hosts
|
||||||
self.registrant = registrant
|
self.registrant = registrant
|
||||||
|
|
||||||
def dummyInfoContactResultData(id, email, cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35), pw="thisisnotapassword"):
|
def dummyInfoContactResultData(
|
||||||
|
id,
|
||||||
|
email,
|
||||||
|
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||||
|
pw="thisisnotapassword",
|
||||||
|
):
|
||||||
fake = info.InfoContactResultData(
|
fake = info.InfoContactResultData(
|
||||||
id=id,
|
id=id,
|
||||||
postal_info=common.PostalInfo(
|
postal_info=common.PostalInfo(
|
||||||
|
@ -591,10 +596,18 @@ class MockEppLib(TestCase):
|
||||||
)
|
)
|
||||||
return fake
|
return fake
|
||||||
|
|
||||||
mockSecurityContact = dummyInfoContactResultData("securityContact", "security@mail.gov")
|
mockSecurityContact = dummyInfoContactResultData(
|
||||||
mockTechnicalContact = dummyInfoContactResultData("technicalContact", "tech@mail.gov")
|
"securityContact", "security@mail.gov"
|
||||||
mockAdministrativeContact = dummyInfoContactResultData("administrativeContact", "admin@mail.gov")
|
)
|
||||||
mockRegistrantContact = dummyInfoContactResultData("registrantContact", "registrant@mail.gov")
|
mockTechnicalContact = dummyInfoContactResultData(
|
||||||
|
"technicalContact", "tech@mail.gov"
|
||||||
|
)
|
||||||
|
mockAdministrativeContact = dummyInfoContactResultData(
|
||||||
|
"administrativeContact", "admin@mail.gov"
|
||||||
|
)
|
||||||
|
mockRegistrantContact = dummyInfoContactResultData(
|
||||||
|
"registrantContact", "registrant@mail.gov"
|
||||||
|
)
|
||||||
mockDataInfoDomain = fakedEppObject(
|
mockDataInfoDomain = fakedEppObject(
|
||||||
"lastPw",
|
"lastPw",
|
||||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||||
|
@ -618,7 +631,9 @@ class MockEppLib(TestCase):
|
||||||
contacts=[],
|
contacts=[],
|
||||||
hosts=["fake.host.com"],
|
hosts=["fake.host.com"],
|
||||||
)
|
)
|
||||||
mockDataInfoContact = dummyInfoContactResultData("123", "123@mail.gov", datetime.datetime(2023, 5, 25, 19, 45, 35), "lastPw")
|
mockDataInfoContact = dummyInfoContactResultData(
|
||||||
|
"123", "123@mail.gov", datetime.datetime(2023, 5, 25, 19, 45, 35), "lastPw"
|
||||||
|
)
|
||||||
mockDataInfoHosts = fakedEppObject(
|
mockDataInfoHosts = fakedEppObject(
|
||||||
"lastPw", cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35)
|
"lastPw", cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35)
|
||||||
)
|
)
|
||||||
|
@ -633,6 +648,8 @@ class MockEppLib(TestCase):
|
||||||
return MagicMock(res_data=[self.infoDomainNoContact])
|
return MagicMock(res_data=[self.infoDomainNoContact])
|
||||||
elif getattr(_request, "name", None) == "freeman.gov":
|
elif getattr(_request, "name", None) == "freeman.gov":
|
||||||
return MagicMock(res_data=[self.InfoDomainWithContacts])
|
return MagicMock(res_data=[self.InfoDomainWithContacts])
|
||||||
|
else:
|
||||||
|
return MagicMock(res_data=[self.mockDataInfoDomain])
|
||||||
elif isinstance(_request, commands.InfoContact):
|
elif isinstance(_request, commands.InfoContact):
|
||||||
# Default contact return
|
# Default contact return
|
||||||
mocked_result = self.mockDataInfoContact
|
mocked_result = self.mockDataInfoContact
|
||||||
|
@ -646,6 +663,8 @@ class MockEppLib(TestCase):
|
||||||
mocked_result = self.mockAdministrativeContact
|
mocked_result = self.mockAdministrativeContact
|
||||||
case "registrantContact":
|
case "registrantContact":
|
||||||
mocked_result = self.mockRegistrantContact
|
mocked_result = self.mockRegistrantContact
|
||||||
|
case "123":
|
||||||
|
mocked_result = self.mockDataInfoContact
|
||||||
|
|
||||||
return MagicMock(res_data=[mocked_result])
|
return MagicMock(res_data=[mocked_result])
|
||||||
elif (
|
elif (
|
||||||
|
|
|
@ -29,14 +29,15 @@ logger = logging.getLogger(__name__)
|
||||||
class TestDomainCache(MockEppLib):
|
class TestDomainCache(MockEppLib):
|
||||||
def test_cache_sets_resets(self):
|
def test_cache_sets_resets(self):
|
||||||
"""Cache should be set on getter and reset on setter calls"""
|
"""Cache should be set on getter and reset on setter calls"""
|
||||||
domain, _ = Domain.objects.get_or_create(name="freeman.gov")
|
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||||
# trigger getter
|
# trigger getter
|
||||||
_ = domain.creation_date
|
_ = domain.creation_date
|
||||||
|
logger.debug(f"what is the cache here? {domain._cache}")
|
||||||
domain._get_property("contacts")
|
domain._get_property("contacts")
|
||||||
# getter should set the domain cache with a InfoDomain object
|
# getter should set the domain cache with a InfoDomain object
|
||||||
# (see InfoDomainResult)
|
# (see InfoDomainResult)
|
||||||
self.assertEquals(domain._cache["auth_info"], self.InfoDomainWithContacts.auth_info)
|
self.assertEquals(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
||||||
self.assertEquals(domain._cache["cr_date"], self.InfoDomainWithContacts.cr_date)
|
self.assertEquals(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date)
|
||||||
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
|
||||||
|
@ -47,16 +48,15 @@ class TestDomainCache(MockEppLib):
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
call(
|
call(
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
commands.InfoDomain(name="igorville.gov", auth_info=None),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
call(commands.InfoContact(id='registrantContact', auth_info=None), cleaned=True),
|
call(commands.InfoContact(id="123", auth_info=None), cleaned=True),
|
||||||
call(commands.InfoContact(id='securityContact', auth_info=None), cleaned=True),
|
|
||||||
call(commands.InfoContact(id='administrativeContact', auth_info=None), cleaned=True),
|
|
||||||
call(commands.InfoContact(id='technicalContact', auth_info=None), cleaned=True),
|
|
||||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
# Clear the cache
|
||||||
|
domain._invalidate_cache()
|
||||||
|
|
||||||
def test_cache_used_when_avail(self):
|
def test_cache_used_when_avail(self):
|
||||||
"""Cache is pulled from if the object has already been accessed"""
|
"""Cache is pulled from if the object has already been accessed"""
|
||||||
|
@ -80,45 +80,39 @@ class TestDomainCache(MockEppLib):
|
||||||
]
|
]
|
||||||
|
|
||||||
self.mockedSendFunction.assert_has_calls(expectedCalls)
|
self.mockedSendFunction.assert_has_calls(expectedCalls)
|
||||||
|
# Clear the cache
|
||||||
|
domain._invalidate_cache()
|
||||||
|
|
||||||
def test_cache_nested_elements(self):
|
def test_cache_nested_elements(self):
|
||||||
"""Cache works correctly with the nested objects cache and hosts"""
|
"""Cache works correctly with the nested objects cache and hosts"""
|
||||||
domain, _ = Domain.objects.get_or_create(name="freeman.gov")
|
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||||
|
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
# The contact list will initally contain objects of type 'DomainContact'
|
# The contact list will initally contain objects of type 'DomainContact'
|
||||||
# this is then transformed into PublicContact, and cache should NOT
|
# this is then transformed into PublicContact, and cache should NOT
|
||||||
# hold onto the DomainContact object
|
# hold onto the DomainContact object
|
||||||
expectedUnfurledContactsList = [
|
expectedUnfurledContactsList = [
|
||||||
common.DomainContact(contact="securityContact", type="security"),
|
common.DomainContact(contact="123", type="security"),
|
||||||
common.DomainContact(contact="administrativeContact", type="admin"),
|
|
||||||
common.DomainContact(contact="technicalContact", type="tech"),
|
|
||||||
]
|
]
|
||||||
expectedContactsList = [
|
expectedContactsList = [
|
||||||
domain.map_epp_contact_to_public_contact(
|
domain.map_epp_contact_to_public_contact(
|
||||||
self.mockSecurityContact, "securityContact", "security"
|
self.mockDataInfoContact, "123", "security"
|
||||||
),
|
)
|
||||||
domain.map_epp_contact_to_public_contact(
|
|
||||||
self.mockAdministrativeContact, "administrativeContact", "admin"
|
|
||||||
),
|
|
||||||
domain.map_epp_contact_to_public_contact(
|
|
||||||
self.mockTechnicalContact, "technicalContact", "tech"
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
expectedHostsDict = {
|
expectedHostsDict = {
|
||||||
"name": self.InfoDomainWithContacts.hosts[0],
|
"name": self.mockDataInfoDomain.hosts[0],
|
||||||
"cr_date": self.InfoDomainWithContacts.cr_date,
|
"cr_date": self.mockDataInfoDomain.cr_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
# this can be changed when the getter for contacts is implemented
|
# this can be changed when the getter for contacts is implemented
|
||||||
domain._get_property("contacts")
|
domain._get_property("contacts")
|
||||||
|
|
||||||
# check domain info is still correct and not overridden
|
# check domain info is still correct and not overridden
|
||||||
self.assertEqual(domain._cache["auth_info"], self.InfoDomainWithContacts.auth_info)
|
self.assertEqual(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
||||||
self.assertEqual(domain._cache["cr_date"], self.InfoDomainWithContacts.cr_date)
|
self.assertEqual(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date)
|
||||||
|
|
||||||
# check contacts
|
# check contacts
|
||||||
self.assertEqual(domain._cache["_contacts"], self.InfoDomainWithContacts.contacts)
|
self.assertEqual(domain._cache["_contacts"], self.mockDataInfoDomain.contacts)
|
||||||
# The contact list should not contain what is sent by the registry by default,
|
# The contact list should not contain what is sent by the registry by default,
|
||||||
# as _fetch_cache will transform the type to PublicContact
|
# as _fetch_cache will transform the type to PublicContact
|
||||||
self.assertNotEqual(domain._cache["contacts"], expectedUnfurledContactsList)
|
self.assertNotEqual(domain._cache["contacts"], expectedUnfurledContactsList)
|
||||||
|
@ -129,15 +123,24 @@ class TestDomainCache(MockEppLib):
|
||||||
# This should be a problem only exclusive to our mocks, since we are not
|
# This should be a problem only exclusive to our mocks, since we are not
|
||||||
# replicating the same item twice outside this context. That said, we want to check
|
# replicating the same item twice outside this context. That said, we want to check
|
||||||
# for data integrity, but do not care if they are of the same _state or not
|
# for data integrity, but do not care if they are of the same _state or not
|
||||||
for cached_contact, expected_contact in zip(domain._cache["contacts"], expectedContactsList):
|
for cached_contact, expected_contact in zip(
|
||||||
|
domain._cache["contacts"], expectedContactsList
|
||||||
|
):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
{k: v for k, v in vars(cached_contact).items() if k != '_state'},
|
{k: v for k, v in vars(cached_contact).items() if k != "_state"},
|
||||||
{k: v for k, v in vars(expected_contact).items() if k != '_state'}
|
{k: v for k, v in vars(expected_contact).items() if k != "_state"},
|
||||||
)
|
)
|
||||||
|
|
||||||
# get and check hosts is set correctly
|
# get and check hosts is set correctly
|
||||||
domain._get_property("hosts")
|
domain._get_property("hosts")
|
||||||
self.assertEqual(domain._cache["hosts"], [expectedHostsDict])
|
self.assertEqual(domain._cache["hosts"], [expectedHostsDict])
|
||||||
|
# Clear the cache
|
||||||
|
domain._invalidate_cache()
|
||||||
|
|
||||||
|
@skip("Not implemented yet")
|
||||||
|
def test_map_epp_contact_to_public_contact(self):
|
||||||
|
# Tests that the mapper is working how we expect
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
class TestDomainCreation(TestCase):
|
class TestDomainCreation(TestCase):
|
||||||
|
@ -171,6 +174,7 @@ class TestDomainCreation(TestCase):
|
||||||
domain = Domain.objects.get(name="igorville.gov")
|
domain = Domain.objects.get(name="igorville.gov")
|
||||||
self.assertTrue(domain)
|
self.assertTrue(domain)
|
||||||
mocked_domain_creation.assert_not_called()
|
mocked_domain_creation.assert_not_called()
|
||||||
|
patcher.stop()
|
||||||
|
|
||||||
@skip("not implemented yet")
|
@skip("not implemented yet")
|
||||||
def test_accessing_domain_properties_creates_domain_in_registry(self):
|
def test_accessing_domain_properties_creates_domain_in_registry(self):
|
||||||
|
@ -229,15 +233,15 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
And the registrant is the admin on a domain
|
And the registrant is the admin on a domain
|
||||||
"""
|
"""
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
# Creates a domain with no contact associated to it
|
||||||
self.domain, _ = Domain.objects.get_or_create(name="security.gov")
|
self.domain, _ = Domain.objects.get_or_create(name="security.gov")
|
||||||
|
# Creates a domain with an associated contact
|
||||||
|
self.domain_contact, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
PublicContact.objects.all().delete()
|
self.domain._invalidate_cache()
|
||||||
DomainInformation.objects.all().delete()
|
self.domain_contact._invalidate_cache()
|
||||||
DomainApplication.objects.all().delete()
|
|
||||||
Domain.objects.all().delete()
|
|
||||||
self.domain._cache = {}
|
|
||||||
# self.contactMailingAddressPatch.stop()
|
# self.contactMailingAddressPatch.stop()
|
||||||
# self.createContactPatch.stop()
|
# self.createContactPatch.stop()
|
||||||
|
|
||||||
|
@ -492,29 +496,29 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
When each contact is retrieved from cache
|
When each contact is retrieved from cache
|
||||||
Then the user retrieves the correct contact objects
|
Then the user retrieves the correct contact objects
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@skip("not implemented yet")
|
@skip("not implemented yet")
|
||||||
def test_epp_public_contact_mapper(self):
|
def test_epp_public_contact_mapper(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_contact_getter_security(self):
|
def test_contact_getter_security(self):
|
||||||
domain_contacts, _ = Domain.objects.get_or_create(name="freeman.gov")
|
|
||||||
|
|
||||||
security = PublicContact.get_default_security()
|
security = PublicContact.get_default_security()
|
||||||
security.email = "security@mail.gov"
|
security.email = "security@mail.gov"
|
||||||
security.domain = domain_contacts
|
security.domain = self.domain_contact
|
||||||
security.save()
|
security.save()
|
||||||
domain_contacts.security_contact = security
|
self.domain_contact.security_contact = security
|
||||||
|
|
||||||
expected_security_contact = domain_contacts.map_epp_contact_to_public_contact(
|
expected_security_contact = (
|
||||||
|
self.domain_contact.map_epp_contact_to_public_contact(
|
||||||
self.mockSecurityContact, "securityContact", "security"
|
self.mockSecurityContact, "securityContact", "security"
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
contact_dict = self.domain_contact.security_contact.__dict__
|
||||||
contact_dict = domain_contacts.security_contact.__dict__
|
|
||||||
expected_dict = expected_security_contact.__dict__
|
expected_dict = expected_security_contact.__dict__
|
||||||
|
|
||||||
contact_dict.pop('_state')
|
contact_dict.pop("_state")
|
||||||
expected_dict.pop('_state')
|
expected_dict.pop("_state")
|
||||||
|
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
|
@ -522,10 +526,22 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
call(commands.InfoContact(id='registrantContact', auth_info=None), cleaned=True),
|
call(
|
||||||
call(commands.InfoContact(id='securityContact', auth_info=None), cleaned=True),
|
commands.InfoContact(id="registrantContact", auth_info=None),
|
||||||
call(commands.InfoContact(id='administrativeContact', auth_info=None), cleaned=True),
|
cleaned=True,
|
||||||
call(commands.InfoContact(id='technicalContact', auth_info=None), cleaned=True),
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="securityContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="administrativeContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="technicalContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -533,18 +549,17 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
self.assertEqual(contact_dict, expected_dict)
|
self.assertEqual(contact_dict, expected_dict)
|
||||||
|
|
||||||
def test_setter_getter_security_email(self):
|
def test_setter_getter_security_email(self):
|
||||||
domain_contacts, _ = Domain.objects.get_or_create(name="freeman.gov")
|
expected_security_contact = (
|
||||||
|
self.domain_contact.map_epp_contact_to_public_contact(
|
||||||
expected_security_contact = domain_contacts.map_epp_contact_to_public_contact(
|
|
||||||
self.mockSecurityContact, "securityContact", "security"
|
self.mockSecurityContact, "securityContact", "security"
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
contact_dict = self.domain_contact.security_contact.__dict__
|
||||||
contact_dict = domain_contacts.security_contact.__dict__
|
|
||||||
expected_dict = expected_security_contact.__dict__
|
expected_dict = expected_security_contact.__dict__
|
||||||
|
|
||||||
contact_dict.pop('_state')
|
contact_dict.pop("_state")
|
||||||
expected_dict.pop('_state')
|
expected_dict.pop("_state")
|
||||||
|
|
||||||
# Getter functions properly...
|
# Getter functions properly...
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
|
@ -553,10 +568,22 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
call(commands.InfoContact(id='registrantContact', auth_info=None), cleaned=True),
|
call(
|
||||||
call(commands.InfoContact(id='securityContact', auth_info=None), cleaned=True),
|
commands.InfoContact(id="registrantContact", auth_info=None),
|
||||||
call(commands.InfoContact(id='administrativeContact', auth_info=None), cleaned=True),
|
cleaned=True,
|
||||||
call(commands.InfoContact(id='technicalContact', auth_info=None), cleaned=True),
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="securityContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="administrativeContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="technicalContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -564,7 +591,7 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
self.assertEqual(contact_dict, expected_dict)
|
self.assertEqual(contact_dict, expected_dict)
|
||||||
|
|
||||||
# Setter functions properly...
|
# Setter functions properly...
|
||||||
domain_contacts.security_contact.email = "converge@mail.com"
|
self.domain_contact.security_contact.email = "converge@mail.com"
|
||||||
expected_security_contact.email = "converge@mail.com"
|
expected_security_contact.email = "converge@mail.com"
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
|
@ -572,14 +599,28 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
call(commands.InfoContact(id='registrantContact', auth_info=None), cleaned=True),
|
call(
|
||||||
call(commands.InfoContact(id='securityContact', auth_info=None), cleaned=True),
|
commands.InfoContact(id="registrantContact", auth_info=None),
|
||||||
call(commands.InfoContact(id='administrativeContact', auth_info=None), cleaned=True),
|
cleaned=True,
|
||||||
call(commands.InfoContact(id='technicalContact', auth_info=None), cleaned=True),
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="securityContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="administrativeContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="technicalContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
self.assertEqual(domain_contacts.security_contact.email, expected_security_contact.email)
|
self.assertEqual(
|
||||||
|
self.domain_contact.security_contact.email, expected_security_contact.email
|
||||||
|
)
|
||||||
|
|
||||||
@skip("not implemented yet")
|
@skip("not implemented yet")
|
||||||
def test_setter_getter_security_email_mock_user(self):
|
def test_setter_getter_security_email_mock_user(self):
|
||||||
|
@ -588,28 +629,28 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def test_contact_getter_technical(self):
|
def test_contact_getter_technical(self):
|
||||||
domain_contacts, _ = Domain.objects.get_or_create(name="freeman.gov")
|
|
||||||
|
|
||||||
technical = PublicContact.get_default_technical()
|
technical = PublicContact.get_default_technical()
|
||||||
technical.email = "tech@mail.gov"
|
technical.email = "tech@mail.gov"
|
||||||
technical.domain = domain_contacts
|
technical.domain = self.domain_contact
|
||||||
technical.save()
|
technical.save()
|
||||||
|
|
||||||
expected_technical_contact = domain_contacts.map_epp_contact_to_public_contact(
|
expected_technical_contact = (
|
||||||
|
self.domain_contact.map_epp_contact_to_public_contact(
|
||||||
self.mockTechnicalContact, "technicalContact", "tech"
|
self.mockTechnicalContact, "technicalContact", "tech"
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
domain_contacts.technical_contact = technical
|
self.domain_contact.technical_contact = technical
|
||||||
|
|
||||||
contact_dict = domain_contacts.technical_contact.__dict__
|
contact_dict = self.domain_contact.technical_contact.__dict__
|
||||||
expected_dict = expected_technical_contact.__dict__
|
expected_dict = expected_technical_contact.__dict__
|
||||||
|
|
||||||
# There has to be a better way to do this.
|
# There has to be a better way to do this.
|
||||||
# Since Cache creates a new object, it causes
|
# Since Cache creates a new object, it causes
|
||||||
# a desync between each instance. Basically,
|
# a desync between each instance. Basically,
|
||||||
# these two objects will never be the same.
|
# these two objects will never be the same.
|
||||||
contact_dict.pop('_state')
|
contact_dict.pop("_state")
|
||||||
expected_dict.pop('_state')
|
expected_dict.pop("_state")
|
||||||
|
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
|
@ -617,10 +658,22 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
call(commands.InfoContact(id='registrantContact', auth_info=None), cleaned=True),
|
call(
|
||||||
call(commands.InfoContact(id='securityContact', auth_info=None), cleaned=True),
|
commands.InfoContact(id="registrantContact", auth_info=None),
|
||||||
call(commands.InfoContact(id='administrativeContact', auth_info=None), cleaned=True),
|
cleaned=True,
|
||||||
call(commands.InfoContact(id='technicalContact', auth_info=None), cleaned=True),
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="securityContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="administrativeContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="technicalContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -629,24 +682,24 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
|
|
||||||
def test_contact_getter_administrative(self):
|
def test_contact_getter_administrative(self):
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
domain_contacts, _ = Domain.objects.get_or_create(name="freeman.gov")
|
|
||||||
|
|
||||||
administrative = PublicContact.get_default_administrative()
|
administrative = PublicContact.get_default_administrative()
|
||||||
administrative.email = "admin@mail.gov"
|
administrative.email = "admin@mail.gov"
|
||||||
administrative.domain = domain_contacts
|
administrative.domain = self.domain_contact
|
||||||
administrative.save()
|
administrative.save()
|
||||||
|
|
||||||
expected_administrative_contact = domain_contacts.map_epp_contact_to_public_contact(
|
expected_administrative_contact = (
|
||||||
|
self.domain_contact.map_epp_contact_to_public_contact(
|
||||||
self.mockAdministrativeContact, "administrativeContact", "admin"
|
self.mockAdministrativeContact, "administrativeContact", "admin"
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
domain_contacts.administrative_contact = administrative
|
self.domain_contact.administrative_contact = administrative
|
||||||
|
|
||||||
contact_dict = domain_contacts.administrative_contact.__dict__
|
contact_dict = self.domain_contact.administrative_contact.__dict__
|
||||||
expected_dict = expected_administrative_contact.__dict__
|
expected_dict = expected_administrative_contact.__dict__
|
||||||
|
|
||||||
contact_dict.pop('_state')
|
contact_dict.pop("_state")
|
||||||
expected_dict.pop('_state')
|
expected_dict.pop("_state")
|
||||||
|
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
|
@ -654,10 +707,22 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
call(commands.InfoContact(id='registrantContact', auth_info=None), cleaned=True),
|
call(
|
||||||
call(commands.InfoContact(id='securityContact', auth_info=None), cleaned=True),
|
commands.InfoContact(id="registrantContact", auth_info=None),
|
||||||
call(commands.InfoContact(id='administrativeContact', auth_info=None), cleaned=True),
|
cleaned=True,
|
||||||
call(commands.InfoContact(id='technicalContact', auth_info=None), cleaned=True),
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="securityContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="administrativeContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="technicalContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -665,27 +730,27 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
self.assertEqual(contact_dict, expected_dict)
|
self.assertEqual(contact_dict, expected_dict)
|
||||||
|
|
||||||
def test_contact_getter_registrant(self):
|
def test_contact_getter_registrant(self):
|
||||||
domain_contacts, _ = Domain.objects.get_or_create(name="freeman.gov")
|
|
||||||
|
|
||||||
registrant = PublicContact.get_default_registrant()
|
registrant = PublicContact.get_default_registrant()
|
||||||
registrant.email = "registrant@mail.gov"
|
registrant.email = "registrant@mail.gov"
|
||||||
registrant.domain = domain_contacts
|
registrant.domain = self.domain_contact
|
||||||
registrant.save()
|
registrant.save()
|
||||||
|
|
||||||
expected_registrant_contact = registrant
|
expected_registrant_contact = registrant
|
||||||
domain_contacts.registrant_contact = registrant
|
self.domain_contact.registrant_contact = registrant
|
||||||
|
|
||||||
expected_registrant_contact = domain_contacts.map_epp_contact_to_public_contact(
|
expected_registrant_contact = (
|
||||||
|
self.domain_contact.map_epp_contact_to_public_contact(
|
||||||
self.mockRegistrantContact, "registrantContact", "registrant"
|
self.mockRegistrantContact, "registrantContact", "registrant"
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
domain_contacts.registrant_contact = registrant
|
self.domain_contact.registrant_contact = registrant
|
||||||
|
|
||||||
contact_dict = domain_contacts.registrant_contact.__dict__
|
contact_dict = self.domain_contact.registrant_contact.__dict__
|
||||||
expected_dict = expected_registrant_contact.__dict__
|
expected_dict = expected_registrant_contact.__dict__
|
||||||
|
|
||||||
contact_dict.pop('_state')
|
contact_dict.pop("_state")
|
||||||
expected_dict.pop('_state')
|
expected_dict.pop("_state")
|
||||||
|
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
|
@ -693,10 +758,22 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
call(commands.InfoContact(id='registrantContact', auth_info=None), cleaned=True),
|
call(
|
||||||
call(commands.InfoContact(id='securityContact', auth_info=None), cleaned=True),
|
commands.InfoContact(id="registrantContact", auth_info=None),
|
||||||
call(commands.InfoContact(id='administrativeContact', auth_info=None), cleaned=True),
|
cleaned=True,
|
||||||
call(commands.InfoContact(id='technicalContact', auth_info=None), cleaned=True),
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="securityContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="administrativeContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="technicalContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue