Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,7 @@ def _is_executive_office(element, is_post_office_split_feed=False):


def _has_government_body(element):
if element_has_text(element.find("GovernmentBodyIds")):
return True
governmental_body = get_entity_info_for_value_type(
element,
"governmental-body",
)
government_body = get_entity_info_for_value_type(element, "government-body")
return bool(governmental_body or government_body)
return element_has_text(element.find("GovernmentBodyIds"))


def get_external_id_values(
Expand Down Expand Up @@ -4935,22 +4928,6 @@ def check(self, element):
)


class GovernmentBodyExternalId(base.BaseRule):
"""Errors if the government body is set using an external identifier instead of the GovernmentBody element."""

def elements(self):
return ["ExternalIdentifiers"]

def check(self, element):
if get_external_id_values(
element, "government-body"
) or get_external_id_values(element, "governmental-body"):
raise loggers.ElectionError.from_message(
"Specifying government body via external identifiers is deprecated."
" Please use the top level GovernmentBody element instead."
)


class ElectoralCommissionCollectionExists(base.BaseRule):
"""ElectoralCommissionCollection should exist."""

Expand Down Expand Up @@ -5495,7 +5472,6 @@ def check(self, element):
EmptyText,
Encoding,
ExecutiveOfficeShouldNotHaveGovernmentBody,
GovernmentBodyExternalId,
GpUnitOcdId,
GpUnitsCyclesRefsValidation,
GpUnitsHaveInternationalizedName,
Expand Down
248 changes: 0 additions & 248 deletions tests/rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10993,82 +10993,6 @@ def test_post_split_non_exec_office_with_empty_government_body_ids_raises_info(
" body.",
)

def test_non_exec_office_with_government_body_is_valid_succeeds(self):
office_string = """
<Office>
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>office-role</OtherType>
<Value>senate</Value>
</ExternalIdentifier>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>government-body</OtherType>
<Value>United States Senate</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
</Office>
"""

self.gov_validator.check(etree.fromstring(office_string))

def test_post_split_non_exec_office_with_government_body_is_valid_succeeds(
self,
):
office_string = """
<Office>
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>government-body</OtherType>
<Value>United States Senate</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
<Role>senate</Role>
</Office>
"""

self.post_office_split_validator.check(etree.fromstring(office_string))

def test_non_exec_office_with_governmental_body_is_valid_succeeds(self):
office_string = """
<Office>
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>office-role</OtherType>
<Value>senate</Value>
</ExternalIdentifier>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>governmental-body</OtherType>
<Value>United States Senate</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
</Office>
"""

self.gov_validator.check(etree.fromstring(office_string))

def test_post_split_non_exec_office_with_governmental_body_is_valid_succeeds(
self,
):
office_string = """
<Office>
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>governmental-body</OtherType>
<Value>United States Senate</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
<Role>senate</Role>
</Office>
"""

self.post_office_split_validator.check(etree.fromstring(office_string))

def test_non_exec_office_with_government_body_ids_is_valid_succeeds(self):
office_string = """
<Office>
Expand Down Expand Up @@ -11125,120 +11049,6 @@ def setUp(self):
)
)

def test_executive_office_with_government_body_fails(self):
for office_role in rules._EXECUTIVE_OFFICE_ROLES:
with self.subTest(office_role=office_role):
office_string = f"""
<Office>
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>office-role</OtherType>
<Value>{office_role}</Value>
</ExternalIdentifier>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>government-body</OtherType>
<Value>United States Senate</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
</Office>
"""

with self.assertRaises(loggers.ElectionError) as context:
self.gov_validator.check(etree.fromstring(office_string))
self.assertEqual(
context.exception.log_entry[0].message,
f"Head of Government/State Office element (roles: {office_role})"
" has a government body. Head of Government/State offices should"
" not have government bodies.",
)

def test_post_split_executive_office_with_government_body_fails(self):
for office_role in rules._EXECUTIVE_OFFICE_ROLES:
with self.subTest(office_role=office_role):
office_string = f"""
<Office>
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>government-body</OtherType>
<Value>United States Senate</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
<Role>{office_role}</Role>
</Office>
"""

with self.assertRaises(loggers.ElectionError) as context:
self.post_office_split_validator.check(
etree.fromstring(office_string)
)
self.assertEqual(
context.exception.log_entry[0].message,
f"Head of Government/State Office element (roles: {office_role})"
" has a government body. Head of Government/State offices should"
" not have government bodies.",
)

def test_executive_office_with_governmental_body_fails(self):
for office_role in rules._EXECUTIVE_OFFICE_ROLES:
with self.subTest(office_role=office_role):
office_string = f"""
<Office>
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>office-role</OtherType>
<Value>{office_role}</Value>
</ExternalIdentifier>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>governmental-body</OtherType>
<Value>United States Senate</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
</Office>
"""

with self.assertRaises(loggers.ElectionError) as context:
self.gov_validator.check(etree.fromstring(office_string))
self.assertEqual(
context.exception.log_entry[0].message,
f"Head of Government/State Office element (roles: {office_role})"
" has a government body. Head of Government/State offices should"
" not have government bodies.",
)

def test_post_split_executive_office_with_governmental_body_fails(
self,
):
for office_role in rules._EXECUTIVE_OFFICE_ROLES:
with self.subTest(office_role=office_role):
office_string = f"""
<Office>
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>governmental-body</OtherType>
<Value>United States Senate</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
<Role>{office_role}</Role>
</Office>
"""

with self.assertRaises(loggers.ElectionError) as context:
self.post_office_split_validator.check(
etree.fromstring(office_string)
)
self.assertEqual(
context.exception.log_entry[0].message,
f"Head of Government/State Office element (roles: {office_role})"
" has a government body. Head of Government/State offices should"
" not have government bodies.",
)

def test_executive_office_with_government_body_ids_fails(self):
for office_role in rules._EXECUTIVE_OFFICE_ROLES:
with self.subTest(office_role=office_role):
Expand Down Expand Up @@ -14006,64 +13816,6 @@ def test_deprecated_party_chair_schema_fails(self):
)


class GovernmentBodyExternalIdTest(absltest.TestCase):

def setUp(self):
super(GovernmentBodyExternalIdTest, self).setUp()
self.validator = rules.GovernmentBodyExternalId(None, None)

def test_government_body_external_id_warns(self):
government_body_string = """
<Office objectId="office">
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>government-body</OtherType>
<Value>government-body-value</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
</Office>
"""

with self.assertRaises(loggers.ElectionError) as context:
self.validator.check(etree.fromstring(government_body_string))
self.assertEqual(
context.exception.log_entry[0].message,
"Specifying government body via external identifiers is deprecated."
" Please use the top level GovernmentBody element instead.",
)

def test_governmental_body_external_id_warns(self):
government_body_string = """
<Office objectId="office">
<ExternalIdentifiers>
<ExternalIdentifier>
<Type>other</Type>
<OtherType>governmental-body</OtherType>
<Value>government-body-value</Value>
</ExternalIdentifier>
</ExternalIdentifiers>
</Office>
"""

with self.assertRaises(loggers.ElectionError) as context:
self.validator.check(etree.fromstring(government_body_string))
self.assertEqual(
context.exception.log_entry[0].message,
"Specifying government body via external identifiers is deprecated."
" Please use the top level GovernmentBody element instead.",
)

def test_new_schema_succeeds(self):
office_string = """
<Office objectId="office-id">
<GovernmentBodyIds>gb</GovernmentBodyIds>
</Office>
"""

self.validator.check(etree.fromstring(office_string))


class ElectoralCommissionCollectionExistsTest(absltest.TestCase):

def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
See https://packaging.python.org/guides/single-sourcing-package-version/
"""

__version__ = '1.61.dev2'
__version__ = '1.61.dev3'
Loading