mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 00:42:16 +02:00
Merge pull request #2538 from cisagov/ms/2322-tribal-gov-skip-fix
#2322 Stop Election Office from unlocking early
This commit is contained in:
commit
161b8d976d
2 changed files with 64 additions and 24 deletions
|
@ -4,7 +4,6 @@ import time
|
|||
import logging
|
||||
from urllib.parse import urlparse, urlunparse, urlencode
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -173,10 +172,6 @@ class CreateOrUpdateOrganizationTypeHelper:
|
|||
self.instance.is_election_board = None
|
||||
self.instance.organization_type = generic_org_type
|
||||
else:
|
||||
# This can only happen with manual data tinkering, which causes these to be out of sync.
|
||||
if self.instance.is_election_board is None:
|
||||
self.instance.is_election_board = False
|
||||
|
||||
if self.instance.is_election_board:
|
||||
self.instance.organization_type = self.generic_org_to_org_map[generic_org_type]
|
||||
else:
|
||||
|
@ -219,12 +214,15 @@ class CreateOrUpdateOrganizationTypeHelper:
|
|||
self.instance.is_election_board = None
|
||||
self.instance.generic_org_type = None
|
||||
|
||||
def _validate_new_instance(self):
|
||||
def _validate_new_instance(self) -> bool:
|
||||
"""
|
||||
Validates whether a new instance of DomainRequest or DomainInformation can proceed with the update
|
||||
based on the consistency between organization_type, generic_org_type, and is_election_board.
|
||||
|
||||
Returns a boolean determining if execution should proceed or not.
|
||||
|
||||
Raises:
|
||||
ValueError if there is a mismatch between organization_type, generic_org_type, and is_election_board
|
||||
"""
|
||||
|
||||
# We conditionally accept both of these values to exist simultaneously, as long as
|
||||
|
@ -242,13 +240,20 @@ class CreateOrUpdateOrganizationTypeHelper:
|
|||
is_election_type = "_election" in organization_type
|
||||
can_have_election_board = organization_type in self.generic_org_to_org_map
|
||||
|
||||
election_board_mismatch = (is_election_type != self.instance.is_election_board) and can_have_election_board
|
||||
election_board_mismatch = (
|
||||
is_election_type and not self.instance.is_election_board and can_have_election_board
|
||||
)
|
||||
org_type_mismatch = mapped_org_type is not None and (generic_org_type != mapped_org_type)
|
||||
if election_board_mismatch or org_type_mismatch:
|
||||
message = (
|
||||
"Cannot add organization_type and generic_org_type simultaneously "
|
||||
"when generic_org_type, is_election_board, and organization_type values do not match."
|
||||
"Cannot add organization_type and generic_org_type simultaneously when"
|
||||
"generic_org_type ({}), is_election_board ({}), and organization_type ({}) don't match.".format(
|
||||
generic_org_type, self.instance.is_election_board, organization_type
|
||||
)
|
||||
)
|
||||
message = "Mismatch on election board, {}".format(message) if election_board_mismatch else message
|
||||
message = "Mistmatch on org type, {}".format(message) if org_type_mismatch else message
|
||||
logger.error("_validate_new_instance: %s", message)
|
||||
raise ValueError(message)
|
||||
|
||||
return True
|
||||
|
|
|
@ -1495,11 +1495,28 @@ class TestDomainRequestCustomSave(TestCase):
|
|||
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)
|
||||
@less_console_noise_decorator
|
||||
def test_existing_instance_updates_election_board_to_none(self):
|
||||
"""Test create_or_update_organization_type for an existing instance, first to True and then to None.
|
||||
Start our with is_election_board as none to simulate a situation where the request was started, but
|
||||
only completed to the point of filling out the generic_org_type."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=None,
|
||||
)
|
||||
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, False)
|
||||
self.assertEqual(domain_request.is_election_board, None)
|
||||
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
|
||||
|
||||
@less_console_noise_decorator
|
||||
|
@ -1654,11 +1671,30 @@ class TestDomainInformationCustomSave(TestCase):
|
|||
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
|
||||
@less_console_noise_decorator
|
||||
def test_existing_instance_update_election_board_to_none(self):
|
||||
"""Test create_or_update_organization_type for an existing instance, first to True and then to None.
|
||||
Start our with is_election_board as none to simulate a situation where the request was started, but
|
||||
only completed to the point of filling out the generic_org_type."""
|
||||
domain_request = completed_domain_request(
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
name="started.gov",
|
||||
generic_org_type=DomainRequest.OrganizationChoices.CITY,
|
||||
is_election_board=None,
|
||||
)
|
||||
domain_information = DomainInformation.create_from_da(domain_request)
|
||||
domain_information.is_election_board = True
|
||||
domain_information.save()
|
||||
|
||||
self.assertEqual(domain_information.is_election_board, False)
|
||||
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
|
||||
|
@ -1858,8 +1894,7 @@ class TestDomainRequestIncomplete(TestCase):
|
|||
self.assertTrue(self.domain_request._is_state_or_territory_complete())
|
||||
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.assertTrue(self.domain_request._is_state_or_territory_complete())
|
||||
self.assertFalse(self.domain_request._is_state_or_territory_complete())
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_is_tribal_complete(self):
|
||||
|
@ -1868,10 +1903,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
|
||||
|
@ -1882,8 +1918,7 @@ class TestDomainRequestIncomplete(TestCase):
|
|||
self.assertTrue(self.domain_request._is_county_complete())
|
||||
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.assertTrue(self.domain_request._is_county_complete())
|
||||
self.assertFalse(self.domain_request._is_county_complete())
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_is_city_complete(self):
|
||||
|
@ -1893,8 +1928,7 @@ class TestDomainRequestIncomplete(TestCase):
|
|||
self.assertTrue(self.domain_request._is_city_complete())
|
||||
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.assertTrue(self.domain_request._is_city_complete())
|
||||
self.assertFalse(self.domain_request._is_city_complete())
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_is_special_district_complete(self):
|
||||
|
@ -1903,10 +1937,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue