Code cleanup

This commit is contained in:
zandercymatics 2023-09-26 13:23:34 -06:00
parent 75913adf29
commit 152cd437fc
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 7 additions and 23 deletions

View file

@ -21,7 +21,6 @@ from .utility.time_stamped_model import TimeStampedModel
from .public_contact import PublicContact from .public_contact import PublicContact
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -539,7 +538,6 @@ class Domain(TimeStampedModel, DomainHelper):
current_contact = PublicContact.objects.filter( current_contact = PublicContact.objects.filter(
registry_id=contact.registry_id registry_id=contact.registry_id
).get() ).get()
logger.debug(f"current contact was accessed {current_contact}")
if current_contact.email != contact.email: if current_contact.email != contact.email:
self._update_epp_contact(contact=contact) self._update_epp_contact(contact=contact)
@ -751,7 +749,7 @@ class Domain(TimeStampedModel, DomainHelper):
def generic_contact_getter( def generic_contact_getter(
self, contact_type_choice: PublicContact.ContactTypeChoices self, contact_type_choice: PublicContact.ContactTypeChoices
) -> PublicContact: ) -> PublicContact | None:
"""Abstracts the cache logic on EppLib contact items """Abstracts the cache logic on EppLib contact items
contact_type_choice is a literal in PublicContact.ContactTypeChoices, contact_type_choice is a literal in PublicContact.ContactTypeChoices,
@ -773,8 +771,9 @@ class Domain(TimeStampedModel, DomainHelper):
try: try:
contacts = self._get_property(desired_property) contacts = self._get_property(desired_property)
except KeyError as error: except KeyError as error:
# Q: Should we be raising an error instead?
logger.error(f"Could not find {contact_type_choice}: {error}") logger.error(f"Could not find {contact_type_choice}: {error}")
raise error return None
else: else:
# Grab from cache # Grab from cache
cached_contact = self.grab_contact_in_keys(contacts, contact_type_choice) cached_contact = self.grab_contact_in_keys(contacts, contact_type_choice)
@ -841,7 +840,7 @@ class Domain(TimeStampedModel, DomainHelper):
# If the for loop didn't do a return, # If the for loop didn't do a return,
# then we know that it doesn't exist within cache # then we know that it doesn't exist within cache
logger.info( logger.info(
f"Requested contact {contact.registry_id} " "Does not exist in cache." f"Requested contact {contact.registry_id} does not exist in cache."
) )
return None return None
@ -890,7 +889,6 @@ class Domain(TimeStampedModel, DomainHelper):
while not exitEarly and count < 3: while not exitEarly and count < 3:
try: try:
logger.info("Getting domain info from epp") logger.info("Getting domain info from epp")
logger.debug(f"domain info name is... {self.__dict__}")
req = commands.InfoDomain(name=self.name) req = commands.InfoDomain(name=self.name)
domainInfo = registry.send(req, cleaned=True).res_data[0] domainInfo = registry.send(req, cleaned=True).res_data[0]
exitEarly = True exitEarly = True
@ -1242,7 +1240,7 @@ class Domain(TimeStampedModel, DomainHelper):
# Saves to DB if it doesn't exist already. # Saves to DB if it doesn't exist already.
# Doesn't run custom save logic, just saves to DB # Doesn't run custom save logic, just saves to DB
public_contact.save(skip_epp_save=True) public_contact.save(skip_epp_save=True)
logger.debug(f"Created a new PublicContact: {public_contact}") logger.info(f"Created a new PublicContact: {public_contact}")
# Append the item we just created # Append the item we just created
return public_contact return public_contact
@ -1265,7 +1263,6 @@ class Domain(TimeStampedModel, DomainHelper):
def _invalidate_cache(self): def _invalidate_cache(self):
"""Remove cache data when updates are made.""" """Remove cache data when updates are made."""
logger.debug(f"cache was cleared! {self.__dict__}")
self._cache = {} self._cache = {}
def _get_property(self, property): def _get_property(self, property):
@ -1277,7 +1274,6 @@ class Domain(TimeStampedModel, DomainHelper):
) )
if property in self._cache: if property in self._cache:
logger.debug(self._cache[property])
return self._cache[property] return self._cache[property]
else: else:
raise KeyError( raise KeyError(

View file

@ -48,6 +48,7 @@ class TestDomainCache(MockEppLib):
# using a setter should clear the cache # using a setter should clear the cache
domain.expiration_date = datetime.date.today() domain.expiration_date = datetime.date.today()
self.assertEquals(domain._cache, {})
# send should have been called only once # send should have been called only once
self.mockedSendFunction.assert_has_calls( self.mockedSendFunction.assert_has_calls(
@ -97,7 +98,7 @@ class TestDomainCache(MockEppLib):
expectedContactsList = [domain.security_contact] expectedContactsList = [domain.security_contact]
expectedHostsDict = { expectedHostsDict = {
"name": self.mockDataInfoDomain.hosts[0], "name": self.mockDataInfoDomain.hosts[0],
"cr_date": self.mockDataInfoDomain.cr_date, "cr_date": self.mockDataInfoHosts.cr_date,
} }
# this can be changed when the getter for contacts is implemented # this can be changed when the getter for contacts is implemented
@ -112,7 +113,6 @@ 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)
self.assertEqual(domain._cache["contacts"], expectedContactsList) self.assertEqual(domain._cache["contacts"], expectedContactsList)
# get and check hosts is set correctly # get and check hosts is set correctly
@ -575,18 +575,6 @@ class TestRegistrantContacts(MockEppLib):
""" """
raise raise
@skip("not implemented yet")
def test_contact_getters_cache(self):
"""
Scenario: A user is grabbing a domain that has multiple contact objects
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): def test_contact_getter_security(self):
self.maxDiff = None self.maxDiff = None
# Create prexisting object... # Create prexisting object...