diff --git a/rules.py b/rules.py index 0e7abed..b812379 100755 --- a/rules.py +++ b/rules.py @@ -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( @@ -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.""" @@ -5495,7 +5472,6 @@ def check(self, element): EmptyText, Encoding, ExecutiveOfficeShouldNotHaveGovernmentBody, - GovernmentBodyExternalId, GpUnitOcdId, GpUnitsCyclesRefsValidation, GpUnitsHaveInternationalizedName, diff --git a/tests/rules_test.py b/tests/rules_test.py index e50ce3b..c1c07f6 100644 --- a/tests/rules_test.py +++ b/tests/rules_test.py @@ -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 = """ - - - - other - office-role - senate - - - other - government-body - United States Senate - - - - """ - - self.gov_validator.check(etree.fromstring(office_string)) - - def test_post_split_non_exec_office_with_government_body_is_valid_succeeds( - self, - ): - office_string = """ - - - - other - government-body - United States Senate - - - senate - - """ - - self.post_office_split_validator.check(etree.fromstring(office_string)) - - def test_non_exec_office_with_governmental_body_is_valid_succeeds(self): - office_string = """ - - - - other - office-role - senate - - - other - governmental-body - United States Senate - - - - """ - - self.gov_validator.check(etree.fromstring(office_string)) - - def test_post_split_non_exec_office_with_governmental_body_is_valid_succeeds( - self, - ): - office_string = """ - - - - other - governmental-body - United States Senate - - - senate - - """ - - 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 = """ @@ -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""" - - - - other - office-role - {office_role} - - - other - government-body - United States Senate - - - - """ - - 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""" - - - - other - government-body - United States Senate - - - {office_role} - - """ - - 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""" - - - - other - office-role - {office_role} - - - other - governmental-body - United States Senate - - - - """ - - 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""" - - - - other - governmental-body - United States Senate - - - {office_role} - - """ - - 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): @@ -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 = """ - - - - other - government-body - government-body-value - - - - """ - - 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 = """ - - - - other - governmental-body - government-body-value - - - - """ - - 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 = """ - - gb - - """ - - self.validator.check(etree.fromstring(office_string)) - - class ElectoralCommissionCollectionExistsTest(absltest.TestCase): def setUp(self): diff --git a/version.py b/version.py index 1ec1a68..d064bcf 100644 --- a/version.py +++ b/version.py @@ -5,4 +5,4 @@ See https://packaging.python.org/guides/single-sourcing-package-version/ """ -__version__ = '1.61.dev2' +__version__ = '1.61.dev3'