mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 19:09:22 +02:00
Add DomainInformatoin tests
This commit is contained in:
parent
843158b3ef
commit
83e0197902
6 changed files with 179 additions and 11 deletions
|
@ -883,6 +883,7 @@ class DomainInformationAdmin(ListHeaderAdmin):
|
|||
"Type of organization",
|
||||
{
|
||||
"fields": [
|
||||
"is_election_board",
|
||||
"organization_type",
|
||||
"federal_type",
|
||||
"federal_agency",
|
||||
|
|
|
@ -62,7 +62,15 @@ def create_or_update_organization_type(sender, instance, **kwargs):
|
|||
|
||||
# == Init variables == #
|
||||
# Instance is already in the database, fetch its current state
|
||||
if isinstance(instance, DomainRequest):
|
||||
current_instance = DomainRequest.objects.get(id=instance.id)
|
||||
elif isinstance(instance, DomainInformation):
|
||||
current_instance = DomainInformation.objects.get(id=instance.id)
|
||||
else:
|
||||
# This should never occur. But it never hurts to have this check anyway.
|
||||
raise ValueError(
|
||||
"create_or_update_organization_type() -> instance was not DomainRequest or DomainInformation"
|
||||
)
|
||||
|
||||
# Check the new and old values
|
||||
generic_org_type_changed = instance.generic_org_type != current_instance.generic_org_type
|
||||
|
|
|
@ -585,7 +585,7 @@ class MockDb(TestCase):
|
|||
generic_org_type="federal",
|
||||
federal_agency="World War I Centennial Commission",
|
||||
federal_type="executive",
|
||||
is_election_board=True,
|
||||
is_election_board=False,
|
||||
)
|
||||
self.domain_information_2, _ = DomainInformation.objects.get_or_create(
|
||||
creator=self.user, domain=self.domain_2, generic_org_type="interstate", is_election_board=True
|
||||
|
@ -595,14 +595,14 @@ class MockDb(TestCase):
|
|||
domain=self.domain_3,
|
||||
generic_org_type="federal",
|
||||
federal_agency="Armed Forces Retirement Home",
|
||||
is_election_board=True,
|
||||
is_election_board=False,
|
||||
)
|
||||
self.domain_information_4, _ = DomainInformation.objects.get_or_create(
|
||||
creator=self.user,
|
||||
domain=self.domain_4,
|
||||
generic_org_type="federal",
|
||||
federal_agency="Armed Forces Retirement Home",
|
||||
is_election_board=True,
|
||||
is_election_board=False,
|
||||
)
|
||||
self.domain_information_5, _ = DomainInformation.objects.get_or_create(
|
||||
creator=self.user,
|
||||
|
@ -652,7 +652,7 @@ class MockDb(TestCase):
|
|||
generic_org_type="federal",
|
||||
federal_agency="World War I Centennial Commission",
|
||||
federal_type="executive",
|
||||
is_election_board=True,
|
||||
is_election_board=False,
|
||||
)
|
||||
self.domain_information_12, _ = DomainInformation.objects.get_or_create(
|
||||
creator=self.user,
|
||||
|
|
|
@ -1453,12 +1453,13 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
"creator",
|
||||
"investigator",
|
||||
"generic_org_type",
|
||||
"is_election_board",
|
||||
"organization_type",
|
||||
"federally_recognized_tribe",
|
||||
"state_recognized_tribe",
|
||||
"tribe_name",
|
||||
"federal_agency",
|
||||
"federal_type",
|
||||
"is_election_board",
|
||||
"organization_name",
|
||||
"address_line1",
|
||||
"address_line2",
|
||||
|
|
|
@ -687,12 +687,12 @@ class HelperFunctions(MockDb):
|
|||
}
|
||||
# Test with distinct
|
||||
managed_domains_sliced_at_end_date = get_sliced_domains(filter_condition, True)
|
||||
expected_content = [3, 2, 1, 0, 0, 0, 0, 0, 0, 2]
|
||||
expected_content = [3, 2, 1, 0, 0, 0, 0, 0, 0, 0]
|
||||
self.assertEqual(managed_domains_sliced_at_end_date, expected_content)
|
||||
|
||||
# Test without distinct
|
||||
managed_domains_sliced_at_end_date = get_sliced_domains(filter_condition)
|
||||
expected_content = [3, 4, 1, 0, 0, 0, 0, 0, 0, 2]
|
||||
expected_content = [3, 4, 1, 0, 0, 0, 0, 0, 0, 0]
|
||||
self.assertEqual(managed_domains_sliced_at_end_date, expected_content)
|
||||
|
||||
def test_get_sliced_requests(self):
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
from django.test import TestCase
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from registrar.models import Contact
|
||||
from registrar.models.domain_request import DomainRequest
|
||||
from registrar.models import Contact, DomainRequest, Domain, DomainInformation
|
||||
from registrar.tests.common import completed_domain_request
|
||||
|
||||
|
||||
|
@ -130,6 +128,7 @@ class TestDomainRequestSignals(TestCase):
|
|||
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."""
|
||||
|
@ -247,3 +246,162 @@ class TestDomainRequestSignals(TestCase):
|
|||
)
|
||||
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