Fix all but 1 unit test

This commit is contained in:
Rebecca Hsieh 2024-04-12 16:52:53 -07:00
parent 757eba1d6e
commit 9f0ea37733
No known key found for this signature in database
2 changed files with 29 additions and 12 deletions

View file

@ -1059,8 +1059,12 @@ class MockEppLib(TestCase):
ex_date=date(2023, 11, 15), ex_date=date(2023, 11, 15),
) )
mockDataInfoContact = mockDataInfoDomain.dummyInfoContactResultData( mockDataInfoContact = mockDataInfoDomain.dummyInfoContactResultData(
"123", "123@mail.gov", datetime(2023, 5, 25, 19, 45, 35), "lastPw" id="SECURITY", email="security@mail.gov", cr_date=datetime(2023, 5, 25, 19, 45, 35), pw="lastPw"
) )
mockDataSecurityContact = mockDataInfoDomain.dummyInfoContactResultData(
id="SECURITY", email="security@mail.gov", cr_date=datetime(2023, 5, 25, 19, 45, 35), pw="lastPw"
)
print("!! mockDataInfoContact is", mockDataInfoContact)
InfoDomainWithContacts = fakedEppObject( InfoDomainWithContacts = fakedEppObject(
"fakepw", "fakepw",
cr_date=make_aware(datetime(2023, 5, 25, 19, 45, 35)), cr_date=make_aware(datetime(2023, 5, 25, 19, 45, 35)),
@ -1497,6 +1501,7 @@ class MockEppLib(TestCase):
"fakemeow.gov": (self.mockDataInfoDomainNotSubdomainNoIP, None), "fakemeow.gov": (self.mockDataInfoDomainNotSubdomainNoIP, None),
"subdomainwoip.gov": (self.mockDataInfoDomainSubdomainNoIP, None), "subdomainwoip.gov": (self.mockDataInfoDomainSubdomainNoIP, None),
"ddomain3.gov": (self.InfoDomainWithContacts, None), "ddomain3.gov": (self.InfoDomainWithContacts, None),
"igorville.gov": (self.InfoDomainWithContacts, None),
} }
# Retrieve the corresponding values from the dictionary # Retrieve the corresponding values from the dictionary
@ -1510,8 +1515,6 @@ class MockEppLib(TestCase):
def mockInfoContactCommands(self, _request, cleaned): def mockInfoContactCommands(self, _request, cleaned):
mocked_result: info.InfoContactResultData mocked_result: info.InfoContactResultData
print("!!! _request is ", _request)
# For testing contact types # For testing contact types
match getattr(_request, "id", None): match getattr(_request, "id", None):
case "securityContact": case "securityContact":

View file

@ -99,7 +99,7 @@ class TestDomainCache(MockEppLib):
def test_cache_nested_elements_not_subdomain(self): def test_cache_nested_elements_not_subdomain(self):
"""Cache works correctly with the nested objects cache and hosts""" """Cache works correctly with the nested objects cache and hosts"""
with less_console_noise(): with less_console_noise():
domain, _ = Domain.objects.get_or_create(name="igorville.gov", state=Domain.State.DNS_NEEDED) domain, _ = Domain.objects.get_or_create(name="igorville.gov")
# The contact list will initially contain objects of type 'DomainContact' # The contact list will initially 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
@ -107,9 +107,9 @@ class TestDomainCache(MockEppLib):
common.DomainContact(contact="123", type="security"), common.DomainContact(contact="123", type="security"),
] ]
expectedContactsDict = { expectedContactsDict = {
PublicContact.ContactTypeChoices.ADMINISTRATIVE: None, PublicContact.ContactTypeChoices.ADMINISTRATIVE: "adminContact",
PublicContact.ContactTypeChoices.SECURITY: "123", PublicContact.ContactTypeChoices.SECURITY: "securityContact",
PublicContact.ContactTypeChoices.TECHNICAL: None, PublicContact.ContactTypeChoices.TECHNICAL: "technicalContact",
} }
expectedHostsDict = { expectedHostsDict = {
"name": self.mockDataInfoDomain.hosts[0], "name": self.mockDataInfoDomain.hosts[0],
@ -129,6 +129,9 @@ class TestDomainCache(MockEppLib):
# 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)
# print("!!! domain._cache[contacts] is", domain._cache["contacts"])
# print("!!! expectedContactsDict is", expectedContactsDict)
self.assertEqual(domain._cache["contacts"], expectedContactsDict) self.assertEqual(domain._cache["contacts"], expectedContactsDict)
# get and check hosts is set correctly # get and check hosts is set correctly
@ -206,15 +209,18 @@ class TestDomainCache(MockEppLib):
domain, _ = Domain.objects.get_or_create(name="registry.gov", state=Domain.State.DNS_NEEDED) domain, _ = Domain.objects.get_or_create(name="registry.gov", state=Domain.State.DNS_NEEDED)
security = PublicContact.ContactTypeChoices.SECURITY security = PublicContact.ContactTypeChoices.SECURITY
mapped = domain.map_epp_contact_to_public_contact( mapped = domain.map_epp_contact_to_public_contact(
self.mockDataInfoContact, self.mockDataSecurityContact,
self.mockDataInfoContact.id, self.mockDataSecurityContact.id,
security, security,
) )
print("self.mockDataInfoContact.id is", self.mockDataInfoContact.id)
print("self.mockDataSecurityContact.id is", self.mockDataSecurityContact.id)
# id and registry_id are the same thing
expected_contact = PublicContact( expected_contact = PublicContact(
domain=domain, domain=domain,
contact_type=security, contact_type=security,
registry_id="123", registry_id="SECURITY", # self.mockDataInfoContact.id
email="security@mail.gov", email="security@mail.gov",
voice="+1.8882820870", voice="+1.8882820870",
fax="+1-212-9876543", fax="+1-212-9876543",
@ -232,7 +238,8 @@ class TestDomainCache(MockEppLib):
# two duplicate objects. We would expect # two duplicate objects. We would expect
# these not to have the same state. # these not to have the same state.
expected_contact._state = mapped._state expected_contact._state = mapped._state
print("!!! expected_contact._state is", expected_contact.__dict__)
print("!!! mapped.__dict__ is", mapped.__dict__)
# Mapped object is what we expect # Mapped object is what we expect
self.assertEqual(mapped.__dict__, expected_contact.__dict__) self.assertEqual(mapped.__dict__, expected_contact.__dict__)
@ -243,9 +250,16 @@ class TestDomainCache(MockEppLib):
registry_id=domain.security_contact.registry_id, registry_id=domain.security_contact.registry_id,
contact_type=security, contact_type=security,
).get() ).get()
"""
!!! db_object is Registry Customer Service <123@mail.gov>id: 123 type: security
!!! in_db is Registry Customer Service <security@mail.gov>id: securityContact type: security
"""
print("!!! domain.security_contact.registry_id ", domain.security_contact.registry_id)
print("!!! db_object is", db_object)
print("!!! in_db is", in_db)
# DB Object is the same as the mapped object # DB Object is the same as the mapped object
self.assertEqual(db_object, in_db) self.assertEqual(db_object, in_db)
domain.security_contact = in_db domain.security_contact = in_db
# Trigger the getter # Trigger the getter
_ = domain.security_contact _ = domain.security_contact