linter fixes

This commit is contained in:
matthewswspence 2024-12-04 13:37:23 -06:00
parent 74eeae19e8
commit 89253a1626
No known key found for this signature in database
GPG key ID: FB458202A7852BA4
3 changed files with 22 additions and 26 deletions

View file

@ -747,11 +747,7 @@ class Domain(TimeStampedModel, DomainHelper):
successTotalNameservers = len(oldNameservers) - deleteCount + addToDomainCount successTotalNameservers = len(oldNameservers) - deleteCount + addToDomainCount
try: self._delete_hosts_if_not_used(hostsToDelete=deleted_values)
self._delete_hosts_if_not_used(hostsToDelete=deleted_values)
except:
# in this case we don't care if there's an error, and it will be logged in the function.
pass
if successTotalNameservers < 2: if successTotalNameservers < 2:
try: try:
@ -1034,10 +1030,10 @@ class Domain(TimeStampedModel, DomainHelper):
# if registry error occurs, log the error, and raise it as well # if registry error occurs, log the error, and raise it as well
logger.error(f"registry error removing client hold: {err}") logger.error(f"registry error removing client hold: {err}")
raise (err) raise (err)
def _delete_nonregistrant_contacts(self): def _delete_nonregistrant_contacts(self):
"""Non-registrant contacts associated with this domain will be deleted. """Non-registrant contacts associated with this domain will be deleted.
RegistryErrors will be logged and raised. Error RegistryErrors will be logged and raised. Error
handling should be provided by the caller. handling should be provided by the caller.
""" """
logger.info("Deleting contacts for %s", self.name) logger.info("Deleting contacts for %s", self.name)
@ -1048,8 +1044,7 @@ class Domain(TimeStampedModel, DomainHelper):
# registrants have to be deleted after the domain # registrants have to be deleted after the domain
if contact != PublicContact.ContactTypeChoices.REGISTRANT: if contact != PublicContact.ContactTypeChoices.REGISTRANT:
self._delete_contact(contact, id) self._delete_contact(contact, id)
def _delete_subdomains(self): def _delete_subdomains(self):
"""Subdomains of this domain should be deleted from the registry. """Subdomains of this domain should be deleted from the registry.
Subdomains which are used by other domains (eg as a hostname) will Subdomains which are used by other domains (eg as a hostname) will
@ -1690,10 +1685,10 @@ class Domain(TimeStampedModel, DomainHelper):
) )
raise e raise e
def _delete_contact(self, contact_name: str, registry_id: str): def _delete_contact(self, contact_name: str, registry_id: str):
"""Try to delete a contact from the registry. """Try to delete a contact from the registry.
raises: raises:
RegistryError: if the registry is unable to delete the contact RegistryError: if the registry is unable to delete the contact
""" """
@ -1703,10 +1698,8 @@ class Domain(TimeStampedModel, DomainHelper):
return registry.send(req, cleaned=True).res_data[0] return registry.send(req, cleaned=True).res_data[0]
except RegistryError as error: except RegistryError as error:
logger.error( logger.error(
"Registry threw error when trying to delete contact id %s contact type is %s, error code is\n %s full error is %s", # noqa "Registry threw error when trying to delete contact %s, error: %s", # noqa
contact.registry_id, contact_name,
contact.contact_type,
error.code,
error, error,
) )
raise error raise error
@ -1834,7 +1827,7 @@ class Domain(TimeStampedModel, DomainHelper):
logger.info("Did not remove host %s because it is in use on another domain." % nameserver) logger.info("Did not remove host %s because it is in use on another domain." % nameserver)
else: else:
logger.error("Error _delete_hosts_if_not_used, code was %s error was %s" % (e.code, e)) logger.error("Error _delete_hosts_if_not_used, code was %s error was %s" % (e.code, e))
raise e raise e
def _fix_unknown_state(self, cleaned): def _fix_unknown_state(self, cleaned):

View file

@ -1672,7 +1672,7 @@ class MockEppLib(TestCase):
res_data=[self.mockDataHostChange], res_data=[self.mockDataHostChange],
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY, code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
) )
def mockDeleteHostCommands(self, _request, cleaned): def mockDeleteHostCommands(self, _request, cleaned):
host = getattr(_request, "name", None) host = getattr(_request, "name", None)
if "sharedhost.com" in host: if "sharedhost.com" in host:
@ -1814,15 +1814,15 @@ class MockEppLib(TestCase):
# mocks a contact error on creation # mocks a contact error on creation
raise ContactError(code=ContactErrorCodes.CONTACT_TYPE_NONE) raise ContactError(code=ContactErrorCodes.CONTACT_TYPE_NONE)
return MagicMock(res_data=[self.mockDataInfoHosts]) return MagicMock(res_data=[self.mockDataInfoHosts])
def mockDeleteContactCommands(self, _request, cleaned): def mockDeleteContactCommands(self, _request, cleaned):
if getattr(_request, "id", None) == "fail": if getattr(_request, "id", None) == "fail":
raise RegistryError(code=ErrorCode.OBJECT_EXISTS) raise RegistryError(code=ErrorCode.OBJECT_EXISTS)
else: else:
return MagicMock( return MagicMock(
res_data=[self.mockDataInfoContact], res_data=[self.mockDataInfoContact],
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY, code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
) )
def setUp(self): def setUp(self):
"""mock epp send function as this will fail locally""" """mock epp send function as this will fail locally"""

View file

@ -2643,7 +2643,7 @@ class TestAnalystDelete(MockEppLib):
self.mockedSendFunction.assert_has_calls( self.mockedSendFunction.assert_has_calls(
[ [
call( call(
commands.DeleteHost(name='ns1.sharedhost.com'), commands.DeleteHost(name="ns1.sharedhost.com"),
cleaned=True, cleaned=True,
), ),
] ]
@ -2664,7 +2664,7 @@ class TestAnalystDelete(MockEppLib):
And `state` is set to `DELETED` And `state` is set to `DELETED`
""" """
# with less_console_noise(): # with less_console_noise():
# Desired domain # Desired domain
domain, _ = Domain.objects.get_or_create(name="freeman.gov", state=Domain.State.ON_HOLD) domain, _ = Domain.objects.get_or_create(name="freeman.gov", state=Domain.State.ON_HOLD)
# Put the domain in client hold # Put the domain in client hold
domain.place_client_hold() domain.place_client_hold()
@ -2675,12 +2675,15 @@ class TestAnalystDelete(MockEppLib):
# Check that the host and contacts are deleted, order doesn't matter # Check that the host and contacts are deleted, order doesn't matter
self.mockedSendFunction.assert_has_calls( self.mockedSendFunction.assert_has_calls(
[ [
call(commands.DeleteHost(name='fake.host.com'), cleaned=True), call(commands.DeleteHost(name="fake.host.com"), cleaned=True),
call(commands.DeleteContact(id="securityContact"), cleaned=True), call(commands.DeleteContact(id="securityContact"), cleaned=True),
call(commands.DeleteContact(id="technicalContact"), cleaned=True), call(commands.DeleteContact(id="technicalContact"), cleaned=True),
call(commands.DeleteContact(id="adminContact"),cleaned=True,) call(
commands.DeleteContact(id="adminContact"),
cleaned=True,
),
], ],
any_order=True any_order=True,
) )
# These calls need to be in order # These calls need to be in order