From 57da90d8a0e56ab48049c263756b8ba332c8e827 Mon Sep 17 00:00:00 2001 From: matthewswspence Date: Mon, 5 Aug 2024 15:36:28 -0500 Subject: [PATCH] add more test cases --- src/registrar/tests/test_models.py | 56 +++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/src/registrar/tests/test_models.py b/src/registrar/tests/test_models.py index 9b80e556d..30ce36b1e 100644 --- a/src/registrar/tests/test_models.py +++ b/src/registrar/tests/test_models.py @@ -1495,6 +1495,28 @@ class TestDomainRequestCustomSave(TestCase): self.assertEqual(domain_request.is_election_board, False) self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY) + @less_console_noise_decorator + def test_create_or_update_organization_type_existing_instance_updates_election_board_to_none(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 = None + domain_request.save() + + self.assertEqual(domain_request.is_election_board, None) + self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY) + @less_console_noise_decorator 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.""" @@ -1647,6 +1669,30 @@ class TestDomainInformationCustomSave(TestCase): self.assertEqual(domain_information.is_election_board, False) self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY) + @less_console_noise_decorator + def test_create_or_update_organization_type_existing_instance_updates_election_board_to_none(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 = None + domain_information.save() + domain_information.refresh_from_db() + + self.assertEqual(domain_information.is_election_board, None) + self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY) + @less_console_noise_decorator 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.""" @@ -1853,10 +1899,11 @@ class TestDomainRequestIncomplete(TestCase): self.domain_request.is_election_board = False self.domain_request.save() self.assertTrue(self.domain_request._is_tribal_complete()) - self.domain_request.tribe_name = None self.domain_request.is_election_board = None self.domain_request.save() - # is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election + self.assertFalse(self.domain_request._is_tribal_complete()) + self.domain_request.tribe_name = None + self.domain_request.save() self.assertFalse(self.domain_request._is_tribal_complete()) @less_console_noise_decorator @@ -1886,10 +1933,11 @@ class TestDomainRequestIncomplete(TestCase): self.domain_request.is_election_board = False self.domain_request.save() self.assertTrue(self.domain_request._is_special_district_complete()) - self.domain_request.about_your_organization = None self.domain_request.is_election_board = None self.domain_request.save() - # is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election + self.assertFalse(self.domain_request._is_special_district_complete()) + self.domain_request.about_your_organization = None + self.domain_request.save() self.assertFalse(self.domain_request._is_special_district_complete()) @less_console_noise_decorator