mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 00:42:16 +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 = {}
|
||||
if addr is not None and addr.street is not None:
|
||||
# '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
|
||||
streets = dict(
|
||||
zip_longest(
|
||||
|
@ -734,7 +735,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
contact.contact_type,
|
||||
error.code,
|
||||
error,
|
||||
)
|
||||
) # noqa
|
||||
raise error
|
||||
|
||||
def get_contact_default(
|
||||
|
@ -776,17 +777,18 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
or cache_contact_helper("security")
|
||||
"""
|
||||
try:
|
||||
# TODO - refactor
|
||||
desired_property = "contacts"
|
||||
# The contact type 'registrant' is stored under a different property
|
||||
if contact_type_choice == PublicContact.ContactTypeChoices.REGISTRANT:
|
||||
desired_property = "registrant"
|
||||
logger.debug(f"generic domain getter was called. Wanting contacts on {contact_type_choice}")
|
||||
contacts = self._get_property(desired_property)
|
||||
if contact_type_choice == PublicContact.ContactTypeChoices.REGISTRANT:
|
||||
contacts = [contacts]
|
||||
except KeyError as error:
|
||||
logger.warning("generic_contact_getter -> Contact does not exist")
|
||||
logger.warning(error)
|
||||
# Should we just raise an error instead?
|
||||
return self.get_contact_default(contact_type_choice)
|
||||
else:
|
||||
print(f"generic_contact_getter -> contacts?? {contacts}")
|
||||
|
@ -1123,38 +1125,27 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
"tr_date": getattr(data, "tr_date", ...),
|
||||
"up_date": getattr(data, "up_date", ...),
|
||||
}
|
||||
print(f"precleaned stuff {cache}")
|
||||
# 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 ...}
|
||||
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
|
||||
if "statuses" in cleaned.keys():
|
||||
cleaned["statuses"] = [status.state for status in cleaned["statuses"]]
|
||||
|
||||
# Registrant should be of type PublicContact
|
||||
if "registrant" in cleaned.keys():
|
||||
try:
|
||||
contact = PublicContact(
|
||||
registry_id=cleaned["registrant"],
|
||||
contact_type=PublicContact.ContactTypeChoices.REGISTRANT,
|
||||
)
|
||||
# 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
|
||||
# For linter...
|
||||
_ = cleaned["registrant"]
|
||||
# Registrant, if it exists, should always exist in EppLib.
|
||||
# If it doesn't, that is bad. We expect this to exist, always.
|
||||
cleaned["registrant"] = self._registrant_to_public_contact(_)
|
||||
|
||||
if (
|
||||
# fetch_contacts and
|
||||
"_contacts" in cleaned
|
||||
"_contacts" in cleaned.keys()
|
||||
and isinstance(cleaned["_contacts"], list)
|
||||
and len(cleaned["_contacts"])
|
||||
and len(cleaned["_contacts"]) > 0
|
||||
):
|
||||
logger.debug("hit!")
|
||||
cleaned["contacts"] = []
|
||||
for domainContact in cleaned["_contacts"]:
|
||||
# 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
|
||||
|
||||
# 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)
|
||||
data = registry.send(req, cleaned=True).res_data[0]
|
||||
|
||||
|
@ -1183,31 +1174,63 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
# no point in removing
|
||||
cleaned["hosts"] = []
|
||||
for name in cleaned["_hosts"]:
|
||||
# we do not use _get_or_create_* because we expect the object we
|
||||
# just asked the registry for still exists --
|
||||
# if not, that's a problem
|
||||
req = commands.InfoHost(name=name)
|
||||
data = registry.send(req, cleaned=True).res_data[0]
|
||||
# extract properties from response
|
||||
# (Ellipsis is used to mean "null")
|
||||
host = {
|
||||
"name": name,
|
||||
"addrs": getattr(data, "addrs", ...),
|
||||
"cr_date": getattr(data, "cr_date", ...),
|
||||
"statuses": getattr(data, "statuses", ...),
|
||||
"tr_date": getattr(data, "tr_date", ...),
|
||||
"up_date": getattr(data, "up_date", ...),
|
||||
}
|
||||
cleaned["hosts"].append(
|
||||
{k: v for k, v in host.items() if v is not ...}
|
||||
)
|
||||
|
||||
# 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
|
||||
# just asked the registry for still exists --
|
||||
# if not, that's a problem
|
||||
req = commands.InfoHost(name=host_name)
|
||||
data = registry.send(req, cleaned=True).res_data[0]
|
||||
# extract properties from response
|
||||
# (Ellipsis is used to mean "null")
|
||||
host = {
|
||||
"name": host_name,
|
||||
"addrs": getattr(data, "addrs", ...),
|
||||
"cr_date": getattr(data, "cr_date", ...),
|
||||
"statuses": getattr(data, "statuses", ...),
|
||||
"tr_date": getattr(data, "tr_date", ...),
|
||||
"up_date": getattr(data, "up_date", ...),
|
||||
}
|
||||
return {k: v for k, v in host.items() if v is not ...}
|
||||
|
||||
def _invalidate_cache(self):
|
||||
"""Remove cache data when updates are made."""
|
||||
logger.debug(f"cache was cleared! {self.__dict__}")
|
||||
|
|
|
@ -557,7 +557,12 @@ class MockEppLib(TestCase):
|
|||
self.hosts = hosts
|
||||
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(
|
||||
id=id,
|
||||
postal_info=common.PostalInfo(
|
||||
|
@ -591,10 +596,18 @@ class MockEppLib(TestCase):
|
|||
)
|
||||
return fake
|
||||
|
||||
mockSecurityContact = dummyInfoContactResultData("securityContact", "security@mail.gov")
|
||||
mockTechnicalContact = dummyInfoContactResultData("technicalContact", "tech@mail.gov")
|
||||
mockAdministrativeContact = dummyInfoContactResultData("administrativeContact", "admin@mail.gov")
|
||||
mockRegistrantContact = dummyInfoContactResultData("registrantContact", "registrant@mail.gov")
|
||||
mockSecurityContact = dummyInfoContactResultData(
|
||||
"securityContact", "security@mail.gov"
|
||||
)
|
||||
mockTechnicalContact = dummyInfoContactResultData(
|
||||
"technicalContact", "tech@mail.gov"
|
||||
)
|
||||
mockAdministrativeContact = dummyInfoContactResultData(
|
||||
"administrativeContact", "admin@mail.gov"
|
||||
)
|
||||
mockRegistrantContact = dummyInfoContactResultData(
|
||||
"registrantContact", "registrant@mail.gov"
|
||||
)
|
||||
mockDataInfoDomain = fakedEppObject(
|
||||
"lastPw",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
|
@ -618,7 +631,9 @@ class MockEppLib(TestCase):
|
|||
contacts=[],
|
||||
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(
|
||||
"lastPw", cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35)
|
||||
)
|
||||
|
@ -633,6 +648,8 @@ class MockEppLib(TestCase):
|
|||
return MagicMock(res_data=[self.infoDomainNoContact])
|
||||
elif getattr(_request, "name", None) == "freeman.gov":
|
||||
return MagicMock(res_data=[self.InfoDomainWithContacts])
|
||||
else:
|
||||
return MagicMock(res_data=[self.mockDataInfoDomain])
|
||||
elif isinstance(_request, commands.InfoContact):
|
||||
# Default contact return
|
||||
mocked_result = self.mockDataInfoContact
|
||||
|
@ -646,6 +663,8 @@ class MockEppLib(TestCase):
|
|||
mocked_result = self.mockAdministrativeContact
|
||||
case "registrantContact":
|
||||
mocked_result = self.mockRegistrantContact
|
||||
case "123":
|
||||
mocked_result = self.mockDataInfoContact
|
||||
|
||||
return MagicMock(res_data=[mocked_result])
|
||||
elif (
|
||||
|
|
|
@ -29,14 +29,15 @@ logger = logging.getLogger(__name__)
|
|||
class TestDomainCache(MockEppLib):
|
||||
def test_cache_sets_resets(self):
|
||||
"""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
|
||||
_ = domain.creation_date
|
||||
logger.debug(f"what is the cache here? {domain._cache}")
|
||||
domain._get_property("contacts")
|
||||
# getter should set the domain cache with a InfoDomain object
|
||||
# (see InfoDomainResult)
|
||||
self.assertEquals(domain._cache["auth_info"], self.InfoDomainWithContacts.auth_info)
|
||||
self.assertEquals(domain._cache["cr_date"], self.InfoDomainWithContacts.cr_date)
|
||||
self.assertEquals(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
||||
self.assertEquals(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date)
|
||||
self.assertFalse("avail" in domain._cache.keys())
|
||||
|
||||
# using a setter should clear the cache
|
||||
|
@ -47,16 +48,15 @@ class TestDomainCache(MockEppLib):
|
|||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
call(
|
||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||
commands.InfoDomain(name="igorville.gov", auth_info=None),
|
||||
cleaned=True,
|
||||
),
|
||||
call(commands.InfoContact(id='registrantContact', 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.InfoContact(id="123", auth_info=None), cleaned=True),
|
||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
||||
]
|
||||
)
|
||||
# Clear the cache
|
||||
domain._invalidate_cache()
|
||||
|
||||
def test_cache_used_when_avail(self):
|
||||
"""Cache is pulled from if the object has already been accessed"""
|
||||
|
@ -80,64 +80,67 @@ class TestDomainCache(MockEppLib):
|
|||
]
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(expectedCalls)
|
||||
# Clear the cache
|
||||
domain._invalidate_cache()
|
||||
|
||||
def test_cache_nested_elements(self):
|
||||
"""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
|
||||
# The contact list will initally contain objects of type 'DomainContact'
|
||||
# this is then transformed into PublicContact, and cache should NOT
|
||||
# hold onto the DomainContact object
|
||||
expectedUnfurledContactsList = [
|
||||
common.DomainContact(contact="securityContact", type="security"),
|
||||
common.DomainContact(contact="administrativeContact", type="admin"),
|
||||
common.DomainContact(contact="technicalContact", type="tech"),
|
||||
common.DomainContact(contact="123", type="security"),
|
||||
]
|
||||
expectedContactsList = [
|
||||
domain.map_epp_contact_to_public_contact(
|
||||
self.mockSecurityContact, "securityContact", "security"
|
||||
),
|
||||
domain.map_epp_contact_to_public_contact(
|
||||
self.mockAdministrativeContact, "administrativeContact", "admin"
|
||||
),
|
||||
domain.map_epp_contact_to_public_contact(
|
||||
self.mockTechnicalContact, "technicalContact", "tech"
|
||||
),
|
||||
self.mockDataInfoContact, "123", "security"
|
||||
)
|
||||
]
|
||||
expectedHostsDict = {
|
||||
"name": self.InfoDomainWithContacts.hosts[0],
|
||||
"cr_date": self.InfoDomainWithContacts.cr_date,
|
||||
"name": self.mockDataInfoDomain.hosts[0],
|
||||
"cr_date": self.mockDataInfoDomain.cr_date,
|
||||
}
|
||||
|
||||
# this can be changed when the getter for contacts is implemented
|
||||
domain._get_property("contacts")
|
||||
|
||||
|
||||
# check domain info is still correct and not overridden
|
||||
self.assertEqual(domain._cache["auth_info"], self.InfoDomainWithContacts.auth_info)
|
||||
self.assertEqual(domain._cache["cr_date"], self.InfoDomainWithContacts.cr_date)
|
||||
self.assertEqual(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
||||
self.assertEqual(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date)
|
||||
|
||||
# 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,
|
||||
# as _fetch_cache will transform the type to PublicContact
|
||||
# as _fetch_cache will transform the type to PublicContact
|
||||
self.assertNotEqual(domain._cache["contacts"], expectedUnfurledContactsList)
|
||||
# Assert that what we get from cache is inline with our mock
|
||||
# Since our cache creates new items inside of our contact list,
|
||||
# as we need to map DomainContact -> PublicContact, our mocked items
|
||||
# will point towards a different location in memory (as they are different objects).
|
||||
# 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
|
||||
# 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(
|
||||
{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(cached_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
|
||||
domain._get_property("hosts")
|
||||
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):
|
||||
|
@ -171,6 +174,7 @@ class TestDomainCreation(TestCase):
|
|||
domain = Domain.objects.get(name="igorville.gov")
|
||||
self.assertTrue(domain)
|
||||
mocked_domain_creation.assert_not_called()
|
||||
patcher.stop()
|
||||
|
||||
@skip("not implemented yet")
|
||||
def test_accessing_domain_properties_creates_domain_in_registry(self):
|
||||
|
@ -221,7 +225,7 @@ class TestDomainCreation(TestCase):
|
|||
|
||||
class TestRegistrantContacts(MockEppLib):
|
||||
"""Rule: Registrants may modify their WHOIS data"""
|
||||
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Background:
|
||||
|
@ -229,15 +233,15 @@ class TestRegistrantContacts(MockEppLib):
|
|||
And the registrant is the admin on a domain
|
||||
"""
|
||||
super().setUp()
|
||||
# Creates a domain with no contact associated to it
|
||||
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):
|
||||
super().tearDown()
|
||||
PublicContact.objects.all().delete()
|
||||
DomainInformation.objects.all().delete()
|
||||
DomainApplication.objects.all().delete()
|
||||
Domain.objects.all().delete()
|
||||
self.domain._cache = {}
|
||||
self.domain._invalidate_cache()
|
||||
self.domain_contact._invalidate_cache()
|
||||
# self.contactMailingAddressPatch.stop()
|
||||
# self.createContactPatch.stop()
|
||||
|
||||
|
@ -484,7 +488,7 @@ class TestRegistrantContacts(MockEppLib):
|
|||
Then a user-friendly error message is returned for displaying on the web
|
||||
"""
|
||||
raise
|
||||
|
||||
|
||||
@skip("not implemented yet")
|
||||
def test_contact_getters_cache(self):
|
||||
"""
|
||||
|
@ -492,29 +496,29 @@ class TestRegistrantContacts(MockEppLib):
|
|||
When each contact is retrieved from cache
|
||||
Then the user retrieves the correct contact objects
|
||||
"""
|
||||
|
||||
@skip("not implemented yet")
|
||||
def test_epp_public_contact_mapper(self):
|
||||
pass
|
||||
|
||||
def test_contact_getter_security(self):
|
||||
domain_contacts, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||
|
||||
security = PublicContact.get_default_security()
|
||||
security.email = "security@mail.gov"
|
||||
security.domain = domain_contacts
|
||||
security.domain = self.domain_contact
|
||||
security.save()
|
||||
domain_contacts.security_contact = security
|
||||
self.domain_contact.security_contact = security
|
||||
|
||||
expected_security_contact = domain_contacts.map_epp_contact_to_public_contact(
|
||||
self.mockSecurityContact, "securityContact", "security"
|
||||
)
|
||||
|
||||
expected_security_contact = (
|
||||
self.domain_contact.map_epp_contact_to_public_contact(
|
||||
self.mockSecurityContact, "securityContact", "security"
|
||||
)
|
||||
)
|
||||
|
||||
contact_dict = domain_contacts.security_contact.__dict__
|
||||
contact_dict = self.domain_contact.security_contact.__dict__
|
||||
expected_dict = expected_security_contact.__dict__
|
||||
|
||||
contact_dict.pop('_state')
|
||||
expected_dict.pop('_state')
|
||||
contact_dict.pop("_state")
|
||||
expected_dict.pop("_state")
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -522,10 +526,22 @@ class TestRegistrantContacts(MockEppLib):
|
|||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||
cleaned=True,
|
||||
),
|
||||
call(commands.InfoContact(id='registrantContact', 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.InfoContact(id="registrantContact", 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),
|
||||
]
|
||||
)
|
||||
|
@ -533,18 +549,17 @@ class TestRegistrantContacts(MockEppLib):
|
|||
self.assertEqual(contact_dict, expected_dict)
|
||||
|
||||
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(
|
||||
self.mockSecurityContact, "securityContact", "security"
|
||||
)
|
||||
)
|
||||
|
||||
expected_security_contact = domain_contacts.map_epp_contact_to_public_contact(
|
||||
self.mockSecurityContact, "securityContact", "security"
|
||||
)
|
||||
|
||||
|
||||
contact_dict = domain_contacts.security_contact.__dict__
|
||||
contact_dict = self.domain_contact.security_contact.__dict__
|
||||
expected_dict = expected_security_contact.__dict__
|
||||
|
||||
contact_dict.pop('_state')
|
||||
expected_dict.pop('_state')
|
||||
contact_dict.pop("_state")
|
||||
expected_dict.pop("_state")
|
||||
|
||||
# Getter functions properly...
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
|
@ -553,10 +568,22 @@ class TestRegistrantContacts(MockEppLib):
|
|||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||
cleaned=True,
|
||||
),
|
||||
call(commands.InfoContact(id='registrantContact', 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.InfoContact(id="registrantContact", 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),
|
||||
]
|
||||
)
|
||||
|
@ -564,7 +591,7 @@ class TestRegistrantContacts(MockEppLib):
|
|||
self.assertEqual(contact_dict, expected_dict)
|
||||
|
||||
# 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"
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -572,14 +599,28 @@ class TestRegistrantContacts(MockEppLib):
|
|||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||
cleaned=True,
|
||||
),
|
||||
call(commands.InfoContact(id='registrantContact', 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.InfoContact(id="registrantContact", 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),
|
||||
]
|
||||
)
|
||||
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")
|
||||
def test_setter_getter_security_email_mock_user(self):
|
||||
|
@ -588,28 +629,28 @@ class TestRegistrantContacts(MockEppLib):
|
|||
raise
|
||||
|
||||
def test_contact_getter_technical(self):
|
||||
domain_contacts, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||
|
||||
technical = PublicContact.get_default_technical()
|
||||
technical.email = "tech@mail.gov"
|
||||
technical.domain = domain_contacts
|
||||
technical.domain = self.domain_contact
|
||||
technical.save()
|
||||
|
||||
expected_technical_contact = domain_contacts.map_epp_contact_to_public_contact(
|
||||
self.mockTechnicalContact, "technicalContact", "tech"
|
||||
)
|
||||
|
||||
domain_contacts.technical_contact = technical
|
||||
expected_technical_contact = (
|
||||
self.domain_contact.map_epp_contact_to_public_contact(
|
||||
self.mockTechnicalContact, "technicalContact", "tech"
|
||||
)
|
||||
)
|
||||
|
||||
contact_dict = domain_contacts.technical_contact.__dict__
|
||||
self.domain_contact.technical_contact = technical
|
||||
|
||||
contact_dict = self.domain_contact.technical_contact.__dict__
|
||||
expected_dict = expected_technical_contact.__dict__
|
||||
|
||||
# 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,
|
||||
# these two objects will never be the same.
|
||||
contact_dict.pop('_state')
|
||||
expected_dict.pop('_state')
|
||||
contact_dict.pop("_state")
|
||||
expected_dict.pop("_state")
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -617,10 +658,22 @@ class TestRegistrantContacts(MockEppLib):
|
|||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||
cleaned=True,
|
||||
),
|
||||
call(commands.InfoContact(id='registrantContact', 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.InfoContact(id="registrantContact", 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),
|
||||
]
|
||||
)
|
||||
|
@ -629,24 +682,24 @@ class TestRegistrantContacts(MockEppLib):
|
|||
|
||||
def test_contact_getter_administrative(self):
|
||||
self.maxDiff = None
|
||||
domain_contacts, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||
|
||||
administrative = PublicContact.get_default_administrative()
|
||||
administrative.email = "admin@mail.gov"
|
||||
administrative.domain = domain_contacts
|
||||
administrative.domain = self.domain_contact
|
||||
administrative.save()
|
||||
|
||||
expected_administrative_contact = domain_contacts.map_epp_contact_to_public_contact(
|
||||
self.mockAdministrativeContact, "administrativeContact", "admin"
|
||||
)
|
||||
|
||||
domain_contacts.administrative_contact = administrative
|
||||
expected_administrative_contact = (
|
||||
self.domain_contact.map_epp_contact_to_public_contact(
|
||||
self.mockAdministrativeContact, "administrativeContact", "admin"
|
||||
)
|
||||
)
|
||||
|
||||
contact_dict = domain_contacts.administrative_contact.__dict__
|
||||
self.domain_contact.administrative_contact = administrative
|
||||
|
||||
contact_dict = self.domain_contact.administrative_contact.__dict__
|
||||
expected_dict = expected_administrative_contact.__dict__
|
||||
|
||||
contact_dict.pop('_state')
|
||||
expected_dict.pop('_state')
|
||||
contact_dict.pop("_state")
|
||||
expected_dict.pop("_state")
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -654,38 +707,50 @@ class TestRegistrantContacts(MockEppLib):
|
|||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||
cleaned=True,
|
||||
),
|
||||
call(commands.InfoContact(id='registrantContact', 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.InfoContact(id="registrantContact", 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),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(contact_dict, expected_dict)
|
||||
|
||||
def test_contact_getter_registrant(self):
|
||||
domain_contacts, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||
|
||||
def test_contact_getter_registrant(self):
|
||||
registrant = PublicContact.get_default_registrant()
|
||||
registrant.email = "registrant@mail.gov"
|
||||
registrant.domain = domain_contacts
|
||||
registrant.domain = self.domain_contact
|
||||
registrant.save()
|
||||
|
||||
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(
|
||||
self.mockRegistrantContact, "registrantContact", "registrant"
|
||||
)
|
||||
|
||||
domain_contacts.registrant_contact = registrant
|
||||
expected_registrant_contact = (
|
||||
self.domain_contact.map_epp_contact_to_public_contact(
|
||||
self.mockRegistrantContact, "registrantContact", "registrant"
|
||||
)
|
||||
)
|
||||
|
||||
contact_dict = domain_contacts.registrant_contact.__dict__
|
||||
self.domain_contact.registrant_contact = registrant
|
||||
|
||||
contact_dict = self.domain_contact.registrant_contact.__dict__
|
||||
expected_dict = expected_registrant_contact.__dict__
|
||||
|
||||
contact_dict.pop('_state')
|
||||
expected_dict.pop('_state')
|
||||
contact_dict.pop("_state")
|
||||
expected_dict.pop("_state")
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -693,10 +758,22 @@ class TestRegistrantContacts(MockEppLib):
|
|||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
||||
cleaned=True,
|
||||
),
|
||||
call(commands.InfoContact(id='registrantContact', 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.InfoContact(id="registrantContact", 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),
|
||||
]
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue