mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 04:59:59 +02:00
fix tests
This commit is contained in:
parent
533e57722f
commit
51da456f02
4 changed files with 97 additions and 38 deletions
|
@ -1071,6 +1071,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
|
|
||||||
logger.debug("Deleting non-registrant contacts for %s", self.name)
|
logger.debug("Deleting non-registrant contacts for %s", self.name)
|
||||||
contacts = PublicContact.objects.filter(domain=self)
|
contacts = PublicContact.objects.filter(domain=self)
|
||||||
|
logger.debug("contacts %s", contacts)
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
if contact.contact_type != PublicContact.ContactTypeChoices.REGISTRANT:
|
if contact.contact_type != PublicContact.ContactTypeChoices.REGISTRANT:
|
||||||
logger.debug("removing contact %s from domain %s", contact.registry_id, self.name)
|
logger.debug("removing contact %s from domain %s", contact.registry_id, self.name)
|
||||||
|
@ -1085,6 +1086,9 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
|
|
||||||
logger.debug("Deleting registrant contact for %s", self.name)
|
logger.debug("Deleting registrant contact for %s", self.name)
|
||||||
registrant_id = self.registrant_contact.registry_id
|
registrant_id = self.registrant_contact.registry_id
|
||||||
|
logger.debug("setting default registrant contact")
|
||||||
|
self._add_registrant_to_existing_domain(self.get_default_registrant_contact())
|
||||||
|
logger.debug("deleting registrant contact %s from registry", registrant_id)
|
||||||
deleteRegistrant = commands.DeleteContact(id=registrant_id)
|
deleteRegistrant = commands.DeleteContact(id=registrant_id)
|
||||||
registry.send(deleteRegistrant, cleaned=True)
|
registry.send(deleteRegistrant, cleaned=True)
|
||||||
|
|
||||||
|
|
|
@ -1677,7 +1677,7 @@ class MockEppLib(TestCase):
|
||||||
host = getattr(_request, "name", None)
|
host = getattr(_request, "name", None)
|
||||||
if "sharedhost.com" in host:
|
if "sharedhost.com" in host:
|
||||||
print("raising registry error")
|
print("raising registry error")
|
||||||
raise RegistryError(code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION, note="otherdomain.gov")
|
raise RegistryError(code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION, note="ns1.sharedhost.com")
|
||||||
return MagicMock(
|
return MagicMock(
|
||||||
res_data=[self.mockDataHostChange],
|
res_data=[self.mockDataHostChange],
|
||||||
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
||||||
|
|
|
@ -265,7 +265,7 @@ class TestDomainAdminAsStaff(MockEppLib):
|
||||||
mock_add_message.assert_called_once_with(
|
mock_add_message.assert_called_once_with(
|
||||||
request,
|
request,
|
||||||
messages.ERROR,
|
messages.ERROR,
|
||||||
"Error deleting this Domain: This subdomain is being used as a hostname on another domain: otherdomain.gov",
|
"Error deleting this Domain: This subdomain is being used as a hostname on another domain: ns1.sharedhost.com",
|
||||||
extra_tags="",
|
extra_tags="",
|
||||||
fail_silently=False,
|
fail_silently=False,
|
||||||
)
|
)
|
||||||
|
|
|
@ -2584,8 +2584,24 @@ class TestAnalystDelete(MockEppLib):
|
||||||
"""
|
"""
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.domain, _ = Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY)
|
self.domain, _ = Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY)
|
||||||
|
self.domain_with_contacts, _ = Domain.objects.get_or_create(name="freeman.gov", state=Domain.State.READY)
|
||||||
self.domain_on_hold, _ = Domain.objects.get_or_create(name="fake-on-hold.gov", state=Domain.State.ON_HOLD)
|
self.domain_on_hold, _ = Domain.objects.get_or_create(name="fake-on-hold.gov", state=Domain.State.ON_HOLD)
|
||||||
Host.objects.create(name="ns1.sharingiscaring.gov", domain=self.domain_on_hold)
|
Host.objects.create(name="ns1.sharingiscaring.gov", domain=self.domain_on_hold)
|
||||||
|
PublicContact.objects.create(
|
||||||
|
registry_id="regContact",
|
||||||
|
contact_type=PublicContact.ContactTypeChoices.REGISTRANT,
|
||||||
|
domain=self.domain_with_contacts,
|
||||||
|
)
|
||||||
|
PublicContact.objects.create(
|
||||||
|
registry_id="adminContact",
|
||||||
|
contact_type=PublicContact.ContactTypeChoices.ADMINISTRATIVE,
|
||||||
|
domain=self.domain_with_contacts,
|
||||||
|
)
|
||||||
|
PublicContact.objects.create(
|
||||||
|
registry_id="techContact",
|
||||||
|
contact_type=PublicContact.ContactTypeChoices.TECHNICAL,
|
||||||
|
domain=self.domain_with_contacts,
|
||||||
|
)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
Host.objects.all().delete()
|
Host.objects.all().delete()
|
||||||
|
@ -2642,8 +2658,8 @@ class TestAnalystDelete(MockEppLib):
|
||||||
domain.deletedInEpp()
|
domain.deletedInEpp()
|
||||||
domain.save()
|
domain.save()
|
||||||
|
|
||||||
self.assertTrue(err.is_client_error() and err.code == ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION)
|
self.assertTrue(err.code == ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION)
|
||||||
self.assertEqual(err.msg, "Host in use by another domain: fake-on-hold.gov")
|
self.assertEqual(err.msg, "Host ns1.sharingiscaring.gov is in use by: fake-on-hold.gov")
|
||||||
# Domain itself should not be deleted
|
# Domain itself should not be deleted
|
||||||
self.assertNotEqual(domain, None)
|
self.assertNotEqual(domain, None)
|
||||||
# State should not have changed
|
# State should not have changed
|
||||||
|
@ -2654,33 +2670,22 @@ class TestAnalystDelete(MockEppLib):
|
||||||
"""
|
"""
|
||||||
Scenario: Domain with related Host and Contacts is Deleted
|
Scenario: Domain with related Host and Contacts is Deleted
|
||||||
When a contact and host exists that is tied to this domain
|
When a contact and host exists that is tied to this domain
|
||||||
Then `commands.DeleteHost` is sent to the registry
|
Then all the needed commands are sent to the registry
|
||||||
Then `commands.DeleteContact` is sent to the registry
|
|
||||||
Then `commands.DeleteDomain` is sent to the registry
|
|
||||||
Then `commands.DeleteContact` is sent to the registry for the registrant contact
|
|
||||||
And `state` is set to `DELETED`
|
And `state` is set to `DELETED`
|
||||||
"""
|
"""
|
||||||
# Desired domain
|
|
||||||
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()
|
self.domain_with_contacts.place_client_hold()
|
||||||
# Delete it
|
# Delete it
|
||||||
domain.deletedInEpp()
|
self.domain_with_contacts.deletedInEpp()
|
||||||
domain.save()
|
self.domain_with_contacts.save()
|
||||||
|
|
||||||
# Check that the host and contacts are deleted, order doesn't matter
|
# Check that the host and contacts are deleted
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
call(
|
call(
|
||||||
commands.UpdateDomain(
|
commands.UpdateDomain(
|
||||||
name="freeman.gov",
|
name='freeman.gov',
|
||||||
add=[
|
add=[common.Status(state=Domain.Status.CLIENT_HOLD, description='', lang='en')],
|
||||||
common.Status(
|
|
||||||
state=Domain.Status.CLIENT_HOLD,
|
|
||||||
description="",
|
|
||||||
lang="en",
|
|
||||||
)
|
|
||||||
],
|
|
||||||
rem=[],
|
rem=[],
|
||||||
nsset=None,
|
nsset=None,
|
||||||
keyset=None,
|
keyset=None,
|
||||||
|
@ -2689,28 +2694,78 @@ class TestAnalystDelete(MockEppLib):
|
||||||
),
|
),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
call(commands.DeleteHost(name="fake.host.com"), cleaned=True),
|
call(
|
||||||
call(commands.DeleteContact(id="securityContact"), cleaned=True),
|
commands.InfoDomain(name='freeman.gov', auth_info=None),
|
||||||
call(commands.DeleteContact(id="technicalContact"), cleaned=True),
|
cleaned=True,
|
||||||
call(commands.DeleteContact(id="adminContact"), cleaned=True),
|
),
|
||||||
|
call(
|
||||||
|
commands.InfoHost(name='fake.host.com'),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.UpdateDomain(
|
||||||
|
name='freeman.gov',
|
||||||
|
add=[],
|
||||||
|
rem=[common.HostObjSet(hosts=['fake.host.com'])],
|
||||||
|
nsset=None,
|
||||||
|
keyset=None,
|
||||||
|
registrant=None,
|
||||||
|
auth_info=None,
|
||||||
|
),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.DeleteHost(name='fake.host.com'),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.UpdateDomain(
|
||||||
|
name='freeman.gov',
|
||||||
|
add=[],
|
||||||
|
rem=[common.DomainContact(contact='adminContact', type='admin')],
|
||||||
|
nsset=None,
|
||||||
|
keyset=None,
|
||||||
|
registrant=None,
|
||||||
|
auth_info=None,
|
||||||
|
),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.DeleteContact(id='adminContact'),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.UpdateDomain(
|
||||||
|
name='freeman.gov',
|
||||||
|
add=[],
|
||||||
|
rem=[common.DomainContact(contact='techContact', type='tech')],
|
||||||
|
nsset=None,
|
||||||
|
keyset=None,
|
||||||
|
registrant=None,
|
||||||
|
auth_info=None,
|
||||||
|
),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.DeleteContact(id='techContact'),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.DeleteDomain(name='freeman.gov'),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
call(
|
||||||
|
commands.DeleteContact(id='regContact'),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
actual_calls = self.mockedSendFunction.call_args_list
|
|
||||||
print("actual_calls", actual_calls)
|
|
||||||
|
|
||||||
# These calls need to be in order
|
|
||||||
self.mockedSendFunction.assert_has_calls(
|
|
||||||
[
|
|
||||||
call(commands.DeleteDomain(name="freeman.gov"), cleaned=True),
|
|
||||||
call(commands.InfoContact(id="regContact"), cleaned=True),
|
|
||||||
call(commands.DeleteContact(id="regContact"), cleaned=True),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
# Domain itself should not be deleted
|
# Domain itself should not be deleted
|
||||||
self.assertNotEqual(domain, None)
|
self.assertNotEqual(self.domain_with_contacts, None)
|
||||||
# State should have changed
|
# State should have changed
|
||||||
self.assertEqual(domain.state, Domain.State.DELETED)
|
self.assertEqual(self.domain_with_contacts.state, Domain.State.DELETED)
|
||||||
|
|
||||||
# @less_console_noise_decorator
|
# @less_console_noise_decorator
|
||||||
def test_deletion_ready_fsm_failure(self):
|
def test_deletion_ready_fsm_failure(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue