mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-28 20:13:46 +02:00
Bug fixes for test cases / Removed duplicate
This commit is contained in:
parent
1c3b43134a
commit
fa8887d7b8
4 changed files with 19 additions and 98 deletions
|
@ -731,16 +731,13 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
db_contact = PublicContact.objects.filter(registry_id=contact_id, contact_type=contact_type, domain=self)
|
||||
# Saves to DB
|
||||
if(create_object and db_contact.count() == 0):
|
||||
desired_contact.save()
|
||||
desired_contact.save(skip_epp_save=True)
|
||||
logger.debug(f"Created a new PublicContact: {desired_contact}")
|
||||
return desired_contact
|
||||
|
||||
if(db_contact.count() == 1):
|
||||
#if(desired_contact != db_contact):
|
||||
#current = desired_contact
|
||||
return db_contact.get()
|
||||
# If it doesn't exist and we don't
|
||||
# want to create it...
|
||||
|
||||
return desired_contact
|
||||
|
||||
def _request_contact_info(self, contact: PublicContact):
|
||||
|
@ -801,46 +798,19 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
if contact_type_choice == PublicContact.ContactTypeChoices.REGISTRANT:
|
||||
desired_property = "registrant"
|
||||
|
||||
# If it exists in our cache, grab that
|
||||
if(self._cache and desired_property in self._cache):
|
||||
return self.grab_contact_in_keys(self._cache[desired_property], contact_type_choice)
|
||||
|
||||
# If not, check in our DB
|
||||
items = PublicContact.objects.filter(domain=self, contact_type=contact_type_choice)
|
||||
if(items.count() > 1):
|
||||
raise ValueError(f"Multiple contacts exist for {contact_type_choice}")
|
||||
|
||||
# Grab the first item in an array of size 1.
|
||||
# We use this instead of .get() as we can expect
|
||||
# values of 'None' occasionally (such as when an object
|
||||
# only exists on the registry)
|
||||
current_contact = items.first()
|
||||
# If we have an item in our DB,
|
||||
# and if contacts hasn't been cleared (meaning data was set)...
|
||||
if(current_contact is not None):
|
||||
# TODO - Should we sync with EppLib in this event?
|
||||
# map_epp_contact_to_public_contact will grab any changes
|
||||
# made in the setter,
|
||||
logger.info(
|
||||
"Contact was not found in cache but was found in DB."
|
||||
"Was this item added recently?"
|
||||
)
|
||||
return current_contact
|
||||
|
||||
try:
|
||||
# Finally, if all else fails, grab from the registry
|
||||
contacts = self._get_property(desired_property)
|
||||
|
||||
except KeyError as error:
|
||||
# Q: Should we be raising an error instead?
|
||||
logger.error(error)
|
||||
return None
|
||||
else:
|
||||
# Grab from cache after its been created
|
||||
cached_contact = self.grab_contact_in_keys(contacts, contact_type_choice)
|
||||
if cached_contact is None:
|
||||
raise ValueError("No contact was found in cache or the registry")
|
||||
|
||||
return cached_contact
|
||||
except RegistryError as error:
|
||||
# Q: Should we be raising an error instead?
|
||||
logger.error(error)
|
||||
return None
|
||||
|
||||
def get_default_security_contact(self):
|
||||
"""Gets the default security contact."""
|
||||
|
|
|
@ -29,7 +29,8 @@ class PublicContact(TimeStampedModel):
|
|||
|
||||
def save(self, *args, **kwargs):
|
||||
"""Save to the registry and also locally in the registrar database."""
|
||||
if hasattr(self, "domain"):
|
||||
skip_epp_save = kwargs.pop('skip_epp_save', False)
|
||||
if hasattr(self, "domain") and not skip_epp_save:
|
||||
match self.contact_type:
|
||||
case PublicContact.ContactTypeChoices.REGISTRANT:
|
||||
self.domain.registrant_contact = self
|
||||
|
|
|
@ -621,6 +621,10 @@ class MockEppLib(TestCase):
|
|||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
contacts=[common.DomainContact(contact="123", type=PublicContact.ContactTypeChoices.SECURITY)],
|
||||
hosts=["fake.host.com"],
|
||||
statuses=[
|
||||
common.Status(state="serverTransferProhibited", description="", lang="en"),
|
||||
common.Status(state="inactive", description="", lang="en"),
|
||||
],
|
||||
)
|
||||
InfoDomainWithContacts = fakedEppObject(
|
||||
"fakepw",
|
||||
|
|
|
@ -22,14 +22,13 @@ from epplibwrapper import (
|
|||
common,
|
||||
)
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestDomainCache(MockEppLib):
|
||||
def tearDown(self):
|
||||
Domain.objects.all().delete()
|
||||
PublicContact.objects.all().delete()
|
||||
Domain.objects.all().delete()
|
||||
super().tearDown()
|
||||
def test_cache_sets_resets(self):
|
||||
"""Cache should be set on getter and reset on setter calls"""
|
||||
|
@ -48,21 +47,16 @@ class TestDomainCache(MockEppLib):
|
|||
|
||||
# using a setter should clear the cache
|
||||
domain.expiration_date = datetime.date.today()
|
||||
self.assertEquals(domain._cache, {})
|
||||
expectedCreateContact = self._convertPublicContactToEpp(domain.security_contact, True, createContact=True)
|
||||
|
||||
# send should have been called only once
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
call(commands.InfoDomain(name='igorville.gov', auth_info=None), cleaned=True),
|
||||
call(commands.InfoContact(id='123', auth_info=None), cleaned=True),
|
||||
call(expectedCreateContact, cleaned=True),
|
||||
call(commands.UpdateDomain(name='igorville.gov', add=[common.DomainContact(contact='123', type=PublicContact.ContactTypeChoices.SECURITY)], rem=[], nsset=None, keyset=None, registrant=None, auth_info=None), cleaned=True),
|
||||
call(commands.InfoHost(name='fake.host.com'), cleaned=True)
|
||||
],
|
||||
any_order=False, # Ensure calls are in the specified order
|
||||
)
|
||||
# Clear the cache
|
||||
domain._invalidate_cache()
|
||||
|
||||
def test_cache_used_when_avail(self):
|
||||
"""Cache is pulled from if the object has already been accessed"""
|
||||
|
@ -75,8 +69,7 @@ class TestDomainCache(MockEppLib):
|
|||
# value should still be set correctly
|
||||
self.assertEqual(cr_date, self.mockDataInfoDomain.cr_date)
|
||||
self.assertEqual(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date)
|
||||
d = domain._cache["contacts"]
|
||||
logger.debug(f"????? questions {d}")
|
||||
|
||||
# send was only called once & not on the second getter call
|
||||
expectedCalls = [
|
||||
call(
|
||||
|
@ -87,8 +80,6 @@ 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"""
|
||||
|
@ -128,11 +119,8 @@ class TestDomainCache(MockEppLib):
|
|||
# get and check hosts is set correctly
|
||||
domain._get_property("hosts")
|
||||
self.assertEqual(domain._cache["hosts"], [expectedHostsDict])
|
||||
# Clear the cache
|
||||
domain._invalidate_cache()
|
||||
|
||||
def test_map_epp_contact_to_public_contact(self):
|
||||
self.maxDiff = None
|
||||
# Tests that the mapper is working how we expect
|
||||
domain, _ = Domain.objects.get_or_create(name="registry.gov")
|
||||
mapped = domain.map_epp_contact_to_public_contact(
|
||||
|
@ -210,7 +198,6 @@ class TestDomainCreation(MockEppLib):
|
|||
domain = Domain.objects.get(name="igorville.gov")
|
||||
self.assertTrue(domain)
|
||||
self.mockedSendFunction.assert_not_called()
|
||||
patcher.stop()
|
||||
|
||||
def test_accessing_domain_properties_creates_domain_in_registry(self):
|
||||
"""
|
||||
|
@ -271,6 +258,7 @@ class TestDomainCreation(MockEppLib):
|
|||
def tearDown(self) -> None:
|
||||
DomainInformation.objects.all().delete()
|
||||
DomainApplication.objects.all().delete()
|
||||
PublicContact.objects.all().delete()
|
||||
Domain.objects.all().delete()
|
||||
User.objects.all().delete()
|
||||
DraftDomain.objects.all().delete()
|
||||
|
@ -287,7 +275,7 @@ class TestDomainStatuses(MockEppLib):
|
|||
_ = domain.statuses
|
||||
status_list = [status.state for status in self.mockDataInfoDomain.statuses]
|
||||
self.assertEquals(domain._cache["statuses"], status_list)
|
||||
|
||||
expectedCreateContact = self._convertPublicContactToEpp(domain.security_contact, True, createContact=True)
|
||||
# Called in _fetch_cache
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -333,6 +321,7 @@ class TestDomainStatuses(MockEppLib):
|
|||
raise
|
||||
|
||||
def tearDown(self) -> None:
|
||||
PublicContact.objects.all().delete()
|
||||
Domain.objects.all().delete()
|
||||
super().tearDown()
|
||||
|
||||
|
@ -579,7 +568,6 @@ class TestRegistrantContacts(MockEppLib):
|
|||
],
|
||||
)
|
||||
security_contact.email = "changedEmail@email.com"
|
||||
security_contact.save()
|
||||
self.domain.security_contact = security_contact
|
||||
expectedSecondCreateCommand = self._convertPublicContactToEpp(
|
||||
security_contact, disclose_email=True
|
||||
|
@ -644,48 +632,6 @@ class TestRegistrantContacts(MockEppLib):
|
|||
# Checks if we are recieving the cache we expect...
|
||||
self.assertEqual(self.domain_contact._cache["contacts"][0], expected_security_contact)
|
||||
|
||||
def test_setter_getter_security_email(self):
|
||||
security = PublicContact.get_default_security()
|
||||
security.email = "security@mail.gov"
|
||||
security.domain = self.domain_contact
|
||||
self.domain_contact.security_contact = security
|
||||
|
||||
expected_security_contact = PublicContact.objects.filter(
|
||||
registry_id=self.domain_contact.security_contact.registry_id,
|
||||
contact_type = PublicContact.ContactTypeChoices.SECURITY
|
||||
).get()
|
||||
|
||||
# Checks if we grab the correct PublicContact...
|
||||
self.assertEqual(self.domain_contact.security_contact, expected_security_contact)
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
call(
|
||||
commands.InfoContact(id="securityContact", auth_info=None),
|
||||
cleaned=True,
|
||||
),
|
||||
]
|
||||
)
|
||||
# Call getter...
|
||||
_ = self.domain_contact.security_contact
|
||||
# Checks if we are recieving the cache we expect...
|
||||
self.assertEqual(self.domain_contact._cache["contacts"][0], expected_security_contact)
|
||||
|
||||
# Setter functions properly...
|
||||
security.email = "123@mail.com"
|
||||
security.save()
|
||||
self.domain_contact.security_contact = security
|
||||
expected_security_contact.email = "123@mail.com"
|
||||
|
||||
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):
|
||||
# TODO - grab the HTML content of the page,
|
||||
# and verify that things have changed as expected
|
||||
raise
|
||||
|
||||
def test_contact_getter_technical(self):
|
||||
expected_contact = PublicContact.objects.filter(
|
||||
registry_id=self.domain_contact.technical_contact.registry_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue