mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-28 16:29:54 +02:00
Move test cases
This commit is contained in:
parent
60e370dfb7
commit
f73fe9f042
2 changed files with 306 additions and 306 deletions
|
@ -1161,3 +1161,309 @@ class TestContact(TestCase):
|
|||
# test for a contact which is assigned as an authorizing official on a domain request
|
||||
self.assertFalse(self.contact_as_ao.has_more_than_one_join("authorizing_official"))
|
||||
self.assertTrue(self.contact_as_ao.has_more_than_one_join("submitted_domain_requests"))
|
||||
|
||||
|
||||
class TestDomainRequestCustomSave(TestCase):
|
||||
"""Tests custom save behaviour on the DomainRequest object"""
|
||||
|
||||
def tearDown(self):
|
||||
DomainRequest.objects.all().delete()
|
||||
super().tearDown()
|
||||
|
||||
def test_create_or_update_organization_type_new_instance(self):
|
||||
"""Test create_or_update_organization_type when creating a new instance"""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
)
|
||||
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
|
||||
|
||||
def test_create_or_update_organization_type_new_instance_federal_does_nothing(self):
|
||||
"""Test if create_or_update_organization_type does nothing when creating a new instance for federal"""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||
is_election_board=True,
|
||||
)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.FEDERAL)
|
||||
self.assertEqual(domain_request.is_election_board, None)
|
||||
|
||||
def test_create_or_update_organization_type_existing_instance_updates_election_board(self):
|
||||
"""Test create_or_update_organization_type for an existing instance."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=False,
|
||||
)
|
||||
domain_request.is_election_board = True
|
||||
domain_request.save()
|
||||
|
||||
self.assertEqual(domain_request.is_election_board, True)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
|
||||
|
||||
# Try reverting the election board value
|
||||
domain_request.is_election_board = False
|
||||
domain_request.save()
|
||||
|
||||
self.assertEqual(domain_request.is_election_board, False)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
|
||||
# Try reverting setting an invalid value for election board (should revert to False)
|
||||
domain_request.is_election_board = None
|
||||
domain_request.save()
|
||||
|
||||
self.assertEqual(domain_request.is_election_board, False)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
|
||||
def test_create_or_update_organization_type_existing_instance_updates_generic_org_type(self):
|
||||
"""Test create_or_update_organization_type when modifying generic_org_type on an existing instance."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
)
|
||||
|
||||
domain_request.generic_org_type = DomainRequest.OrganizationChoices.INTERSTATE
|
||||
domain_request.save()
|
||||
|
||||
# Election board should be None because interstate cannot have an election board.
|
||||
self.assertEqual(domain_request.is_election_board, None)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.INTERSTATE)
|
||||
|
||||
# Try changing the org Type to something that CAN have an election board.
|
||||
domain_request_tribal = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="startedTribal.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.TRIBAL,
|
||||
is_election_board=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
domain_request_tribal.organization_type, DomainRequest.OrgChoicesElectionOffice.TRIBAL_ELECTION
|
||||
)
|
||||
|
||||
# Change the org type
|
||||
domain_request_tribal.generic_org_type = DomainRequest.OrganizationChoices.STATE_OR_TERRITORY
|
||||
domain_request_tribal.save()
|
||||
|
||||
self.assertEqual(domain_request_tribal.is_election_board, True)
|
||||
self.assertEqual(
|
||||
domain_request_tribal.organization_type, DomainRequest.OrgChoicesElectionOffice.STATE_OR_TERRITORY_ELECTION
|
||||
)
|
||||
|
||||
def test_create_or_update_organization_type_no_update(self):
|
||||
"""Test create_or_update_organization_type when there are no values to update."""
|
||||
|
||||
# Test for when both generic_org_type and organization_type is declared,
|
||||
# and are both non-election board
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=False,
|
||||
)
|
||||
domain_request.save()
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
self.assertEqual(domain_request.is_election_board, False)
|
||||
self.assertEqual(domain_request.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Test for when both generic_org_type and organization_type is declared,
|
||||
# and are both election board
|
||||
domain_request_election = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="startedElection.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
organization_type=DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
domain_request_election.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION
|
||||
)
|
||||
self.assertEqual(domain_request_election.is_election_board, True)
|
||||
self.assertEqual(domain_request_election.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Modify an unrelated existing value for both, and ensure that everything is still consistent
|
||||
domain_request.city = "Fudge"
|
||||
domain_request_election.city = "Caramel"
|
||||
domain_request.save()
|
||||
domain_request_election.save()
|
||||
|
||||
self.assertEqual(domain_request.city, "Fudge")
|
||||
self.assertEqual(domain_request_election.city, "Caramel")
|
||||
|
||||
# Test for non-election
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
self.assertEqual(domain_request.is_election_board, False)
|
||||
self.assertEqual(domain_request.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Test for election
|
||||
self.assertEqual(
|
||||
domain_request_election.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION
|
||||
)
|
||||
self.assertEqual(domain_request_election.is_election_board, True)
|
||||
self.assertEqual(domain_request_election.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
|
||||
class TestDomainInformationCustomSave(TestCase):
|
||||
"""Tests custom save behaviour on the DomainInformation object"""
|
||||
|
||||
def tearDown(self):
|
||||
DomainInformation.objects.all().delete()
|
||||
DomainRequest.objects.all().delete()
|
||||
Domain.objects.all().delete()
|
||||
super().tearDown()
|
||||
|
||||
def test_create_or_update_organization_type_new_instance(self):
|
||||
"""Test create_or_update_organization_type when creating a new instance"""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
)
|
||||
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
|
||||
|
||||
def test_create_or_update_organization_type_new_instance_federal_does_nothing(self):
|
||||
"""Test if create_or_update_organization_type does nothing when creating a new instance for federal"""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||
is_election_board=True,
|
||||
)
|
||||
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.FEDERAL)
|
||||
self.assertEqual(domain_information.is_election_board, None)
|
||||
|
||||
def test_create_or_update_organization_type_existing_instance_updates_election_board(self):
|
||||
"""Test create_or_update_organization_type for an existing instance."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=False,
|
||||
)
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
domain_information.is_election_board = True
|
||||
domain_information.save()
|
||||
|
||||
self.assertEqual(domain_information.is_election_board, True)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
|
||||
|
||||
# Try reverting the election board value
|
||||
domain_information.is_election_board = False
|
||||
domain_information.save()
|
||||
domain_information.refresh_from_db()
|
||||
|
||||
self.assertEqual(domain_information.is_election_board, False)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
|
||||
# Try reverting setting an invalid value for election board (should revert to False)
|
||||
domain_information.is_election_board = None
|
||||
domain_information.save()
|
||||
|
||||
self.assertEqual(domain_information.is_election_board, False)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
|
||||
def test_create_or_update_organization_type_existing_instance_updates_generic_org_type(self):
|
||||
"""Test create_or_update_organization_type when modifying generic_org_type on an existing instance."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
)
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
|
||||
domain_information.generic_org_type = DomainRequest.OrganizationChoices.INTERSTATE
|
||||
domain_information.save()
|
||||
|
||||
# Election board should be None because interstate cannot have an election board.
|
||||
self.assertEqual(domain_information.is_election_board, None)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.INTERSTATE)
|
||||
|
||||
# Try changing the org Type to something that CAN have an election board.
|
||||
domain_request_tribal = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="startedTribal.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.TRIBAL,
|
||||
is_election_board=True,
|
||||
)
|
||||
domain_information_tribal = DomainInformation.create_from_da(domain_request_tribal)
|
||||
self.assertEqual(
|
||||
domain_information_tribal.organization_type, DomainRequest.OrgChoicesElectionOffice.TRIBAL_ELECTION
|
||||
)
|
||||
|
||||
# Change the org type
|
||||
domain_information_tribal.generic_org_type = DomainRequest.OrganizationChoices.STATE_OR_TERRITORY
|
||||
domain_information_tribal.save()
|
||||
|
||||
self.assertEqual(domain_information_tribal.is_election_board, True)
|
||||
self.assertEqual(
|
||||
domain_information_tribal.organization_type,
|
||||
DomainRequest.OrgChoicesElectionOffice.STATE_OR_TERRITORY_ELECTION,
|
||||
)
|
||||
|
||||
def test_create_or_update_organization_type_no_update(self):
|
||||
"""Test create_or_update_organization_type when there are no values to update."""
|
||||
|
||||
# Test for when both generic_org_type and organization_type is declared,
|
||||
# and are both non-election board
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=False,
|
||||
)
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
domain_information.save()
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
self.assertEqual(domain_information.is_election_board, False)
|
||||
self.assertEqual(domain_information.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Test for when both generic_org_type and organization_type is declared,
|
||||
# and are both election board
|
||||
domain_request_election = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="startedElection.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
organization_type=DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION,
|
||||
)
|
||||
domain_information_election = DomainInformation.create_from_da(domain_request_election)
|
||||
|
||||
self.assertEqual(
|
||||
domain_information_election.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION
|
||||
)
|
||||
self.assertEqual(domain_information_election.is_election_board, True)
|
||||
self.assertEqual(domain_information_election.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Modify an unrelated existing value for both, and ensure that everything is still consistent
|
||||
domain_information.city = "Fudge"
|
||||
domain_information_election.city = "Caramel"
|
||||
domain_information.save()
|
||||
domain_information_election.save()
|
||||
|
||||
self.assertEqual(domain_information.city, "Fudge")
|
||||
self.assertEqual(domain_information_election.city, "Caramel")
|
||||
|
||||
# Test for non-election
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
self.assertEqual(domain_information.is_election_board, False)
|
||||
self.assertEqual(domain_information.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Test for election
|
||||
self.assertEqual(
|
||||
domain_information_election.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION
|
||||
)
|
||||
self.assertEqual(domain_information_election.is_election_board, True)
|
||||
self.assertEqual(domain_information_election.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
|
|
@ -99,309 +99,3 @@ class TestUserPostSave(TestCase):
|
|||
self.assertEqual(actual.last_name, self.last_name)
|
||||
self.assertEqual(actual.email, self.email)
|
||||
self.assertEqual(actual.phone, self.phone)
|
||||
|
||||
|
||||
class TestDomainRequestSignals(TestCase):
|
||||
"""Tests hooked signals on the DomainRequest object"""
|
||||
|
||||
def tearDown(self):
|
||||
DomainRequest.objects.all().delete()
|
||||
super().tearDown()
|
||||
|
||||
def test_create_or_update_organization_type_new_instance(self):
|
||||
"""Test create_or_update_organization_type when creating a new instance"""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
)
|
||||
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
|
||||
|
||||
def test_create_or_update_organization_type_new_instance_federal_does_nothing(self):
|
||||
"""Test if create_or_update_organization_type does nothing when creating a new instance for federal"""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||
is_election_board=True,
|
||||
)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.FEDERAL)
|
||||
self.assertEqual(domain_request.is_election_board, None)
|
||||
|
||||
def test_create_or_update_organization_type_existing_instance_updates_election_board(self):
|
||||
"""Test create_or_update_organization_type for an existing instance."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=False,
|
||||
)
|
||||
domain_request.is_election_board = True
|
||||
domain_request.save()
|
||||
|
||||
self.assertEqual(domain_request.is_election_board, True)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
|
||||
|
||||
# Try reverting the election board value
|
||||
domain_request.is_election_board = False
|
||||
domain_request.save()
|
||||
|
||||
self.assertEqual(domain_request.is_election_board, False)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
|
||||
# Try reverting setting an invalid value for election board (should revert to False)
|
||||
domain_request.is_election_board = None
|
||||
domain_request.save()
|
||||
|
||||
self.assertEqual(domain_request.is_election_board, False)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
|
||||
def test_create_or_update_organization_type_existing_instance_updates_generic_org_type(self):
|
||||
"""Test create_or_update_organization_type when modifying generic_org_type on an existing instance."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
)
|
||||
|
||||
domain_request.generic_org_type = DomainRequest.OrganizationChoices.INTERSTATE
|
||||
domain_request.save()
|
||||
|
||||
# Election board should be None because interstate cannot have an election board.
|
||||
self.assertEqual(domain_request.is_election_board, None)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.INTERSTATE)
|
||||
|
||||
# Try changing the org Type to something that CAN have an election board.
|
||||
domain_request_tribal = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="startedTribal.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.TRIBAL,
|
||||
is_election_board=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
domain_request_tribal.organization_type, DomainRequest.OrgChoicesElectionOffice.TRIBAL_ELECTION
|
||||
)
|
||||
|
||||
# Change the org type
|
||||
domain_request_tribal.generic_org_type = DomainRequest.OrganizationChoices.STATE_OR_TERRITORY
|
||||
domain_request_tribal.save()
|
||||
|
||||
self.assertEqual(domain_request_tribal.is_election_board, True)
|
||||
self.assertEqual(
|
||||
domain_request_tribal.organization_type, DomainRequest.OrgChoicesElectionOffice.STATE_OR_TERRITORY_ELECTION
|
||||
)
|
||||
|
||||
def test_create_or_update_organization_type_no_update(self):
|
||||
"""Test create_or_update_organization_type when there are no values to update."""
|
||||
|
||||
# Test for when both generic_org_type and organization_type is declared,
|
||||
# and are both non-election board
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=False,
|
||||
)
|
||||
domain_request.save()
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
self.assertEqual(domain_request.is_election_board, False)
|
||||
self.assertEqual(domain_request.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Test for when both generic_org_type and organization_type is declared,
|
||||
# and are both election board
|
||||
domain_request_election = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="startedElection.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
organization_type=DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
domain_request_election.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION
|
||||
)
|
||||
self.assertEqual(domain_request_election.is_election_board, True)
|
||||
self.assertEqual(domain_request_election.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Modify an unrelated existing value for both, and ensure that everything is still consistent
|
||||
domain_request.city = "Fudge"
|
||||
domain_request_election.city = "Caramel"
|
||||
domain_request.save()
|
||||
domain_request_election.save()
|
||||
|
||||
self.assertEqual(domain_request.city, "Fudge")
|
||||
self.assertEqual(domain_request_election.city, "Caramel")
|
||||
|
||||
# Test for non-election
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
self.assertEqual(domain_request.is_election_board, False)
|
||||
self.assertEqual(domain_request.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Test for election
|
||||
self.assertEqual(
|
||||
domain_request_election.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION
|
||||
)
|
||||
self.assertEqual(domain_request_election.is_election_board, True)
|
||||
self.assertEqual(domain_request_election.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
|
||||
class TestDomainInformationSignals(TestCase):
|
||||
"""Tests hooked signals on the DomainRequest object"""
|
||||
|
||||
def tearDown(self):
|
||||
DomainInformation.objects.all().delete()
|
||||
DomainRequest.objects.all().delete()
|
||||
Domain.objects.all().delete()
|
||||
super().tearDown()
|
||||
|
||||
def test_create_or_update_organization_type_new_instance(self):
|
||||
"""Test create_or_update_organization_type when creating a new instance"""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
)
|
||||
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
|
||||
|
||||
def test_create_or_update_organization_type_new_instance_federal_does_nothing(self):
|
||||
"""Test if create_or_update_organization_type does nothing when creating a new instance for federal"""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||
is_election_board=True,
|
||||
)
|
||||
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.FEDERAL)
|
||||
self.assertEqual(domain_information.is_election_board, None)
|
||||
|
||||
def test_create_or_update_organization_type_existing_instance_updates_election_board(self):
|
||||
"""Test create_or_update_organization_type for an existing instance."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=False,
|
||||
)
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
domain_information.is_election_board = True
|
||||
domain_information.save()
|
||||
|
||||
self.assertEqual(domain_information.is_election_board, True)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
|
||||
|
||||
# Try reverting the election board value
|
||||
domain_information.is_election_board = False
|
||||
domain_information.save()
|
||||
domain_information.refresh_from_db()
|
||||
|
||||
self.assertEqual(domain_information.is_election_board, False)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
|
||||
# Try reverting setting an invalid value for election board (should revert to False)
|
||||
domain_information.is_election_board = None
|
||||
domain_information.save()
|
||||
|
||||
self.assertEqual(domain_information.is_election_board, False)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
|
||||
def test_create_or_update_organization_type_existing_instance_updates_generic_org_type(self):
|
||||
"""Test create_or_update_organization_type when modifying generic_org_type on an existing instance."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
)
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
|
||||
domain_information.generic_org_type = DomainRequest.OrganizationChoices.INTERSTATE
|
||||
domain_information.save()
|
||||
|
||||
# Election board should be None because interstate cannot have an election board.
|
||||
self.assertEqual(domain_information.is_election_board, None)
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.INTERSTATE)
|
||||
|
||||
# Try changing the org Type to something that CAN have an election board.
|
||||
domain_request_tribal = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="startedTribal.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.TRIBAL,
|
||||
is_election_board=True,
|
||||
)
|
||||
domain_information_tribal = DomainInformation.create_from_da(domain_request_tribal)
|
||||
self.assertEqual(
|
||||
domain_information_tribal.organization_type, DomainRequest.OrgChoicesElectionOffice.TRIBAL_ELECTION
|
||||
)
|
||||
|
||||
# Change the org type
|
||||
domain_information_tribal.generic_org_type = DomainRequest.OrganizationChoices.STATE_OR_TERRITORY
|
||||
domain_information_tribal.save()
|
||||
|
||||
self.assertEqual(domain_information_tribal.is_election_board, True)
|
||||
self.assertEqual(
|
||||
domain_information_tribal.organization_type,
|
||||
DomainRequest.OrgChoicesElectionOffice.STATE_OR_TERRITORY_ELECTION,
|
||||
)
|
||||
|
||||
def test_create_or_update_organization_type_no_update(self):
|
||||
"""Test create_or_update_organization_type when there are no values to update."""
|
||||
|
||||
# Test for when both generic_org_type and organization_type is declared,
|
||||
# and are both non-election board
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=False,
|
||||
)
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
domain_information.save()
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
self.assertEqual(domain_information.is_election_board, False)
|
||||
self.assertEqual(domain_information.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Test for when both generic_org_type and organization_type is declared,
|
||||
# and are both election board
|
||||
domain_request_election = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="startedElection.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=True,
|
||||
organization_type=DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION,
|
||||
)
|
||||
domain_information_election = DomainInformation.create_from_da(domain_request_election)
|
||||
|
||||
self.assertEqual(
|
||||
domain_information_election.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION
|
||||
)
|
||||
self.assertEqual(domain_information_election.is_election_board, True)
|
||||
self.assertEqual(domain_information_election.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Modify an unrelated existing value for both, and ensure that everything is still consistent
|
||||
domain_information.city = "Fudge"
|
||||
domain_information_election.city = "Caramel"
|
||||
domain_information.save()
|
||||
domain_information_election.save()
|
||||
|
||||
self.assertEqual(domain_information.city, "Fudge")
|
||||
self.assertEqual(domain_information_election.city, "Caramel")
|
||||
|
||||
# Test for non-election
|
||||
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
self.assertEqual(domain_information.is_election_board, False)
|
||||
self.assertEqual(domain_information.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
||||
# Test for election
|
||||
self.assertEqual(
|
||||
domain_information_election.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION
|
||||
)
|
||||
self.assertEqual(domain_information_election.is_election_board, True)
|
||||
self.assertEqual(domain_information_election.generic_org_type, DomainRequest.OrganizationChoices.CITY)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue