mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-21 18:25:58 +02:00
Improved test cases / Fixed PublicContact persistence
This commit is contained in:
parent
803137b051
commit
3835293b23
4 changed files with 107 additions and 232 deletions
|
@ -516,6 +516,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
.filter(domain=self, contact_type=contact.contact_type)
|
.filter(domain=self, contact_type=contact.contact_type)
|
||||||
.get()
|
.get()
|
||||||
)
|
)
|
||||||
|
logger.info(f"_set_singleton_contact() -> existing contact is... {existing_contact.__dict__}")
|
||||||
if isRegistrant:
|
if isRegistrant:
|
||||||
# send update domain only for registant contacts
|
# send update domain only for registant contacts
|
||||||
existing_contact.delete()
|
existing_contact.delete()
|
||||||
|
@ -537,9 +538,8 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
self._update_domain_with_contact(contact=contact, rem=False)
|
self._update_domain_with_contact(contact=contact, rem=False)
|
||||||
# if already exists just update
|
# if already exists just update
|
||||||
elif alreadyExistsInRegistry:
|
elif alreadyExistsInRegistry:
|
||||||
old_contact = PublicContact.objects.filter(registry_id=contact.registry_id, contact_type=contact.contact_type).exclude(domain=self)
|
logger.debug(f"aaaa12 {contact.__dict__}")
|
||||||
if(old_contact.count() > 0):
|
|
||||||
old_contact.delete()
|
|
||||||
current_contact = PublicContact.objects.filter(
|
current_contact = PublicContact.objects.filter(
|
||||||
registry_id=contact.registry_id
|
registry_id=contact.registry_id
|
||||||
).get()
|
).get()
|
||||||
|
@ -667,7 +667,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
# I'm sure though that there is an easier alternative...
|
# I'm sure though that there is an easier alternative...
|
||||||
# TLDR: This doesn't look as pretty, but it makes using this function easier
|
# TLDR: This doesn't look as pretty, but it makes using this function easier
|
||||||
def map_epp_contact_to_public_contact(
|
def map_epp_contact_to_public_contact(
|
||||||
self, contact: eppInfo.InfoContactResultData, contact_id, contact_type
|
self, contact: eppInfo.InfoContactResultData, contact_id, contact_type, create_object=True
|
||||||
):
|
):
|
||||||
"""Maps the Epp contact representation to a PublicContact object.
|
"""Maps the Epp contact representation to a PublicContact object.
|
||||||
|
|
||||||
|
@ -676,6 +676,8 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
contact_id -> str: The given registry_id of the object (i.e "cheese@cia.gov")
|
contact_id -> str: The given registry_id of the object (i.e "cheese@cia.gov")
|
||||||
|
|
||||||
contact_type -> str: The given contact type, (i.e. "tech" or "registrant")
|
contact_type -> str: The given contact type, (i.e. "tech" or "registrant")
|
||||||
|
|
||||||
|
create_object -> bool: Flag for if this object is saved or not
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if contact is None:
|
if contact is None:
|
||||||
|
@ -687,6 +689,12 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
if contact_id is None:
|
if contact_id is None:
|
||||||
raise ValueError("contact_id is None")
|
raise ValueError("contact_id is None")
|
||||||
|
|
||||||
|
if len(contact_id) > 16 or len(contact_id) < 1:
|
||||||
|
raise ValueError(
|
||||||
|
"contact_id is of invalid length. "
|
||||||
|
f"Cannot exceed 16 characters, got {contact_id} with a length of {len(contact_id)}"
|
||||||
|
)
|
||||||
|
|
||||||
logger.debug(f"map_epp_contact_to_public_contact contact -> {contact}")
|
logger.debug(f"map_epp_contact_to_public_contact contact -> {contact}")
|
||||||
logger.debug(f"What is the type? {type(contact)}")
|
logger.debug(f"What is the type? {type(contact)}")
|
||||||
if not isinstance(contact, eppInfo.InfoContactResultData):
|
if not isinstance(contact, eppInfo.InfoContactResultData):
|
||||||
|
@ -708,7 +716,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
fillvalue=None,
|
fillvalue=None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
logger.debug(f"WHAT IS CONTACT {contact_id} {len(contact_id)}")
|
||||||
desired_contact = PublicContact(
|
desired_contact = PublicContact(
|
||||||
domain=self,
|
domain=self,
|
||||||
contact_type=contact_type,
|
contact_type=contact_type,
|
||||||
|
@ -725,6 +733,9 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
sp=addr.sp,
|
sp=addr.sp,
|
||||||
**streets,
|
**streets,
|
||||||
)
|
)
|
||||||
|
# Saves to DB
|
||||||
|
if(create_object):
|
||||||
|
desired_contact.save()
|
||||||
return desired_contact
|
return desired_contact
|
||||||
|
|
||||||
def _request_contact_info(self, contact: PublicContact):
|
def _request_contact_info(self, contact: PublicContact):
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
class="usa-button"
|
class="usa-button"
|
||||||
>Add security email</button>
|
>{% if domain.security_email is None %}Add security email{% else %}Save{% endif %}</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %} {# domain_content #}
|
{% endblock %} {# domain_content #}
|
||||||
|
|
|
@ -570,9 +570,9 @@ class MockEppLib(TestCase):
|
||||||
addr=common.ContactAddr(
|
addr=common.ContactAddr(
|
||||||
street=["4200 Wilson Blvd."],
|
street=["4200 Wilson Blvd."],
|
||||||
city="Arlington",
|
city="Arlington",
|
||||||
pc="VA",
|
pc="22201",
|
||||||
cc="US",
|
cc="US",
|
||||||
sp="22201",
|
sp="VA",
|
||||||
),
|
),
|
||||||
org="Cybersecurity and Infrastructure Security Agency",
|
org="Cybersecurity and Infrastructure Security Agency",
|
||||||
type="type",
|
type="type",
|
||||||
|
@ -603,27 +603,27 @@ class MockEppLib(TestCase):
|
||||||
"technicalContact", "tech@mail.gov"
|
"technicalContact", "tech@mail.gov"
|
||||||
)
|
)
|
||||||
mockAdministrativeContact = dummyInfoContactResultData(
|
mockAdministrativeContact = dummyInfoContactResultData(
|
||||||
"administrativeContact", "admin@mail.gov"
|
"adminContact", "admin@mail.gov"
|
||||||
)
|
)
|
||||||
mockRegistrantContact = dummyInfoContactResultData(
|
mockRegistrantContact = dummyInfoContactResultData(
|
||||||
"registrantContact", "registrant@mail.gov"
|
"regContact", "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),
|
||||||
contacts=[common.DomainContact(contact="123", type="security")],
|
contacts=[common.DomainContact(contact="123", type=PublicContact.ContactTypeChoices.SECURITY)],
|
||||||
hosts=["fake.host.com"],
|
hosts=["fake.host.com"],
|
||||||
)
|
)
|
||||||
InfoDomainWithContacts = fakedEppObject(
|
InfoDomainWithContacts = fakedEppObject(
|
||||||
"fakepw",
|
"fakepw",
|
||||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||||
contacts=[
|
contacts=[
|
||||||
common.DomainContact(contact="securityContact", type="security"),
|
common.DomainContact(contact="securityContact", type=PublicContact.ContactTypeChoices.SECURITY),
|
||||||
common.DomainContact(contact="administrativeContact", type="admin"),
|
common.DomainContact(contact="technicalContact", type=PublicContact.ContactTypeChoices.TECHNICAL),
|
||||||
common.DomainContact(contact="technicalContact", type="tech"),
|
common.DomainContact(contact="adminContact", type=PublicContact.ContactTypeChoices.ADMINISTRATIVE),
|
||||||
],
|
],
|
||||||
hosts=["fake.host.com"],
|
hosts=["fake.host.com"],
|
||||||
registrant="registrantContact",
|
registrant="regContact",
|
||||||
)
|
)
|
||||||
infoDomainNoContact = fakedEppObject(
|
infoDomainNoContact = fakedEppObject(
|
||||||
"security",
|
"security",
|
||||||
|
@ -659,9 +659,9 @@ class MockEppLib(TestCase):
|
||||||
mocked_result = self.mockSecurityContact
|
mocked_result = self.mockSecurityContact
|
||||||
case "technicalContact":
|
case "technicalContact":
|
||||||
mocked_result = self.mockTechnicalContact
|
mocked_result = self.mockTechnicalContact
|
||||||
case "administrativeContact":
|
case "adminContact":
|
||||||
mocked_result = self.mockAdministrativeContact
|
mocked_result = self.mockAdministrativeContact
|
||||||
case "registrantContact":
|
case "regContact":
|
||||||
mocked_result = self.mockRegistrantContact
|
mocked_result = self.mockRegistrantContact
|
||||||
case "123":
|
case "123":
|
||||||
mocked_result = self.mockDataInfoContact
|
mocked_result = self.mockDataInfoContact
|
||||||
|
|
|
@ -449,7 +449,9 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
security_contact = self.domain.get_default_security_contact()
|
security_contact = self.domain.get_default_security_contact()
|
||||||
security_contact.email = "originalUserEmail@gmail.com"
|
security_contact.email = "originalUserEmail@gmail.com"
|
||||||
security_contact.registry_id = "fail"
|
security_contact.registry_id = "fail"
|
||||||
security_contact.save()
|
security_contact.domain = self.domain
|
||||||
|
self.domain.security_contact = security_contact
|
||||||
|
|
||||||
expectedCreateCommand = self._convertPublicContactToEpp(
|
expectedCreateCommand = self._convertPublicContactToEpp(
|
||||||
security_contact, disclose_email=True
|
security_contact, disclose_email=True
|
||||||
)
|
)
|
||||||
|
@ -462,23 +464,29 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
security_contact.email = "changedEmail@email.com"
|
self.domain.security_contact.email = "changedEmail@email.com"
|
||||||
security_contact.save()
|
#self.domain.security_contact.email = "changedEmail@email.com"
|
||||||
expectedSecondCreateCommand = self._convertPublicContactToEpp(
|
expectedSecondCreateCommand = self._convertPublicContactToEpp(
|
||||||
security_contact, disclose_email=True
|
security_contact, disclose_email=True
|
||||||
)
|
)
|
||||||
updateContact = self._convertPublicContactToEpp(
|
updateContact = self._convertPublicContactToEpp(
|
||||||
security_contact, disclose_email=True, createContact=False
|
security_contact, disclose_email=True, createContact=False
|
||||||
)
|
)
|
||||||
|
self.domain.security_contact.email = "changedEmailAgain@email.com"
|
||||||
|
|
||||||
expected_calls = [
|
|
||||||
call(expectedCreateCommand, cleaned=True),
|
|
||||||
call(expectedUpdateDomain, cleaned=True),
|
|
||||||
call(expectedSecondCreateCommand, cleaned=True),
|
|
||||||
call(updateContact, cleaned=True),
|
|
||||||
]
|
|
||||||
self.mockedSendFunction.assert_has_calls(expected_calls, any_order=True)
|
|
||||||
self.assertEqual(PublicContact.objects.filter(domain=self.domain).count(), 1)
|
self.assertEqual(PublicContact.objects.filter(domain=self.domain).count(), 1)
|
||||||
|
# Check if security_contact is what we expect...
|
||||||
|
self.assertEqual(self.domain.security_contact.email, "changedEmailAgain@email.com")
|
||||||
|
# If the item in PublicContact is as expected...
|
||||||
|
current_item = PublicContact.objects.filter(domain=self.domain).get()
|
||||||
|
self.assertEqual(current_item.email, "changedEmailAgain@email.com")
|
||||||
|
|
||||||
|
# Check if cache stored it correctly...
|
||||||
|
self.assertEqual("contacts" in self.domain._cache)
|
||||||
|
cached_item = self.domain._cache["contacts"]
|
||||||
|
self.assertTrue(cached_item[0])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@skip("not implemented yet")
|
@skip("not implemented yet")
|
||||||
def test_update_is_unsuccessful(self):
|
def test_update_is_unsuccessful(self):
|
||||||
|
@ -502,122 +510,58 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_contact_getter_security(self):
|
def test_contact_getter_security(self):
|
||||||
|
# Create prexisting object...
|
||||||
security = PublicContact.get_default_security()
|
security = PublicContact.get_default_security()
|
||||||
security.email = "security@mail.gov"
|
security.email = "security@mail.gov"
|
||||||
security.domain = self.domain_contact
|
security.domain = self.domain_contact
|
||||||
security.save()
|
|
||||||
self.domain_contact.security_contact = security
|
self.domain_contact.security_contact = security
|
||||||
|
|
||||||
expected_security_contact = (
|
expected_security_contact = PublicContact.objects.filter(
|
||||||
self.domain_contact.map_epp_contact_to_public_contact(
|
registry_id=self.domain_contact.security_contact.registry_id,
|
||||||
self.mockSecurityContact, "securityContact", "security"
|
contact_type = PublicContact.ContactTypeChoices.SECURITY
|
||||||
)
|
).get()
|
||||||
)
|
|
||||||
|
|
||||||
contact_dict = self.domain_contact.security_contact.__dict__
|
|
||||||
expected_dict = expected_security_contact.__dict__
|
|
||||||
|
|
||||||
contact_dict.pop("_state")
|
|
||||||
expected_dict.pop("_state")
|
|
||||||
|
|
||||||
|
# Checks if we grab the correct PublicContact...
|
||||||
|
self.assertEqual(self.domain_contact.security_contact, expected_security_contact)
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
call(
|
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
|
||||||
cleaned=True,
|
|
||||||
),
|
|
||||||
call(
|
|
||||||
commands.InfoContact(id="registrantContact", auth_info=None),
|
|
||||||
cleaned=True,
|
|
||||||
),
|
|
||||||
call(
|
call(
|
||||||
commands.InfoContact(id="securityContact", auth_info=None),
|
commands.InfoContact(id="securityContact", auth_info=None),
|
||||||
cleaned=True,
|
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),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
# Checks if we are recieving the cache we expect...
|
||||||
self.assertEqual(contact_dict, expected_dict)
|
self.assertEqual(self.domain_contact._cache["contacts"][0], expected_security_contact)
|
||||||
|
|
||||||
def test_setter_getter_security_email(self):
|
def test_setter_getter_security_email(self):
|
||||||
expected_security_contact = (
|
security = PublicContact.get_default_security()
|
||||||
self.domain_contact.map_epp_contact_to_public_contact(
|
security.email = "security@mail.gov"
|
||||||
self.mockSecurityContact, "securityContact", "security"
|
security.domain = self.domain_contact
|
||||||
)
|
self.domain_contact.security_contact = security
|
||||||
)
|
|
||||||
|
|
||||||
contact_dict = self.domain_contact.security_contact.__dict__
|
expected_security_contact = PublicContact.objects.filter(
|
||||||
expected_dict = expected_security_contact.__dict__
|
registry_id=self.domain_contact.security_contact.registry_id,
|
||||||
|
contact_type = PublicContact.ContactTypeChoices.SECURITY
|
||||||
|
).get()
|
||||||
|
|
||||||
contact_dict.pop("_state")
|
# Checks if we grab the correct PublicContact...
|
||||||
expected_dict.pop("_state")
|
self.assertEqual(self.domain_contact.security_contact, expected_security_contact)
|
||||||
|
|
||||||
# Getter functions properly...
|
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
call(
|
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
|
||||||
cleaned=True,
|
|
||||||
),
|
|
||||||
call(
|
|
||||||
commands.InfoContact(id="registrantContact", auth_info=None),
|
|
||||||
cleaned=True,
|
|
||||||
),
|
|
||||||
call(
|
call(
|
||||||
commands.InfoContact(id="securityContact", auth_info=None),
|
commands.InfoContact(id="securityContact", auth_info=None),
|
||||||
cleaned=True,
|
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),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
# Checks if we are recieving the cache we expect...
|
||||||
self.assertEqual(contact_dict, expected_dict)
|
self.assertEqual(self.domain_contact._cache["contacts"][0], expected_security_contact)
|
||||||
|
|
||||||
# Setter functions properly...
|
# Setter functions properly...
|
||||||
self.domain_contact.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(
|
|
||||||
[
|
|
||||||
call(
|
|
||||||
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.InfoHost(name="fake.host.com"), cleaned=True),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.domain_contact.security_contact.email, expected_security_contact.email
|
self.domain_contact.security_contact.email, expected_security_contact.email
|
||||||
)
|
)
|
||||||
|
@ -629,156 +573,76 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def test_contact_getter_technical(self):
|
def test_contact_getter_technical(self):
|
||||||
technical = PublicContact.get_default_technical()
|
contact = PublicContact.get_default_technical()
|
||||||
technical.email = "tech@mail.gov"
|
contact.email = "technical@mail.gov"
|
||||||
technical.domain = self.domain_contact
|
contact.domain = self.domain_contact
|
||||||
technical.save()
|
self.domain_contact.technical_contact = contact
|
||||||
|
|
||||||
expected_technical_contact = (
|
expected_contact = PublicContact.objects.filter(
|
||||||
self.domain_contact.map_epp_contact_to_public_contact(
|
registry_id=self.domain_contact.technical_contact.registry_id,
|
||||||
self.mockTechnicalContact, "technicalContact", "tech"
|
contact_type = PublicContact.ContactTypeChoices.TECHNICAL
|
||||||
)
|
).get()
|
||||||
)
|
|
||||||
|
|
||||||
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
|
|
||||||
# a desync between each instance. Basically,
|
|
||||||
# these two objects will never be the same.
|
|
||||||
contact_dict.pop("_state")
|
|
||||||
expected_dict.pop("_state")
|
|
||||||
|
|
||||||
|
# Checks if we grab the correct PublicContact...
|
||||||
|
self.assertEqual(self.domain_contact.technical_contact, expected_contact)
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
call(
|
|
||||||
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(
|
call(
|
||||||
commands.InfoContact(id="technicalContact", auth_info=None),
|
commands.InfoContact(id="technicalContact", auth_info=None),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
call(commands.InfoHost(name="fake.host.com"), cleaned=True),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
# Checks if we are recieving the cache we expect...
|
||||||
self.assertEqual(contact_dict, expected_dict)
|
self.assertEqual(self.domain_contact._cache["contacts"][1], expected_contact)
|
||||||
|
|
||||||
def test_contact_getter_administrative(self):
|
def test_contact_getter_administrative(self):
|
||||||
self.maxDiff = None
|
contact = PublicContact.get_default_administrative()
|
||||||
administrative = PublicContact.get_default_administrative()
|
contact.email = "admin@mail.gov"
|
||||||
administrative.email = "admin@mail.gov"
|
contact.domain = self.domain_contact
|
||||||
administrative.domain = self.domain_contact
|
self.domain_contact.administrative_contact = contact
|
||||||
administrative.save()
|
|
||||||
|
|
||||||
expected_administrative_contact = (
|
expected_contact = PublicContact.objects.filter(
|
||||||
self.domain_contact.map_epp_contact_to_public_contact(
|
registry_id=self.domain_contact.administrative_contact.registry_id,
|
||||||
self.mockAdministrativeContact, "administrativeContact", "admin"
|
contact_type = PublicContact.ContactTypeChoices.ADMINISTRATIVE
|
||||||
)
|
).get()
|
||||||
)
|
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
|
# Checks if we grab the correct PublicContact...
|
||||||
|
self.assertEqual(self.domain_contact.administrative_contact, expected_contact)
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
call(
|
call(
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
commands.InfoContact(id="adminContact", auth_info=None),
|
||||||
cleaned=True,
|
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),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
# Checks if we are recieving the cache we expect...
|
||||||
self.assertEqual(contact_dict, expected_dict)
|
self.assertEqual(self.domain_contact._cache["contacts"][2], expected_contact)
|
||||||
|
|
||||||
def test_contact_getter_registrant(self):
|
def test_contact_getter_registrant(self):
|
||||||
registrant = PublicContact.get_default_registrant()
|
contact = PublicContact.get_default_registrant()
|
||||||
registrant.email = "registrant@mail.gov"
|
contact.email = "registrant@mail.gov"
|
||||||
registrant.domain = self.domain_contact
|
contact.domain = self.domain_contact
|
||||||
registrant.save()
|
self.domain_contact.registrant_contact = contact
|
||||||
|
|
||||||
expected_registrant_contact = registrant
|
expected_contact = PublicContact.objects.filter(
|
||||||
self.domain_contact.registrant_contact = registrant
|
registry_id=self.domain_contact.registrant_contact.registry_id,
|
||||||
|
contact_type = PublicContact.ContactTypeChoices.REGISTRANT
|
||||||
expected_registrant_contact = (
|
).get()
|
||||||
self.domain_contact.map_epp_contact_to_public_contact(
|
|
||||||
self.mockRegistrantContact, "registrantContact", "registrant"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
|
# Checks if we grab the correct PublicContact...
|
||||||
|
self.assertEqual(self.domain_contact.registrant_contact, expected_contact)
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
call(
|
call(
|
||||||
commands.InfoDomain(name="freeman.gov", auth_info=None),
|
commands.InfoContact(id="regContact", auth_info=None),
|
||||||
cleaned=True,
|
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),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
# Checks if we are recieving the cache we expect...
|
||||||
self.assertEqual(contact_dict, expected_dict)
|
self.assertEqual(self.domain_contact._cache["registrant"], expected_contact)
|
||||||
|
|
||||||
|
|
||||||
class TestRegistrantNameservers(TestCase):
|
class TestRegistrantNameservers(TestCase):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue