civics-cdf-validator 1.67.dev4__tar.gz → 1.67.dev6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {civics_cdf_validator-1.67.dev4/civics_cdf_validator.egg-info → civics_cdf_validator-1.67.dev6}/PKG-INFO +1 -1
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6/civics_cdf_validator.egg-info}/PKG-INFO +1 -1
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/SOURCES.txt +2 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/rules.py +4 -102
- civics_cdf_validator-1.67.dev6/rulesets/committee_rules.py +107 -0
- civics_cdf_validator-1.67.dev6/rulesets/election_dates_rules.py +40 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/version.py +1 -1
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/CONTRIBUTING.md +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/LICENSE-2.0.txt +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/MANIFEST.in +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/README.md +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/__init__.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/base.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/dependency_links.txt +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/entry_points.txt +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/requires.txt +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/top_level.txt +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/gpunit_rules.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/loggers.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/office_utils.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/rulesets/__init__.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/rulesets/common_rules.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/rulesets/election_rules.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/rulesets/officeholder_rules.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/rulesets/rule_util.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/setup.cfg +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/setup.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/stats.py +0 -0
- {civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/validator.py +0 -0
|
@@ -16,7 +16,9 @@ setup.py
|
|
|
16
16
|
./validator.py
|
|
17
17
|
./version.py
|
|
18
18
|
./rulesets/__init__.py
|
|
19
|
+
./rulesets/committee_rules.py
|
|
19
20
|
./rulesets/common_rules.py
|
|
21
|
+
./rulesets/election_dates_rules.py
|
|
20
22
|
./rulesets/election_rules.py
|
|
21
23
|
./rulesets/officeholder_rules.py
|
|
22
24
|
./rulesets/rule_util.py
|
|
@@ -17,12 +17,13 @@ from __future__ import print_function
|
|
|
17
17
|
|
|
18
18
|
import datetime
|
|
19
19
|
import enum
|
|
20
|
-
import re
|
|
21
20
|
|
|
22
21
|
from botocore import utils as botocore_utils
|
|
23
22
|
from civics_cdf_validator import base
|
|
24
23
|
from civics_cdf_validator import loggers
|
|
24
|
+
from civics_cdf_validator.rulesets import committee_rules
|
|
25
25
|
from civics_cdf_validator.rulesets import common_rules
|
|
26
|
+
from civics_cdf_validator.rulesets import election_dates_rules
|
|
26
27
|
from civics_cdf_validator.rulesets import election_rules
|
|
27
28
|
from civics_cdf_validator.rulesets import officeholder_rules
|
|
28
29
|
from civics_cdf_validator.rulesets import rule_util
|
|
@@ -39,79 +40,6 @@ _VALID_FEED_LONGEVITY_BY_FEED_TYPE = frozendict({
|
|
|
39
40
|
})
|
|
40
41
|
|
|
41
42
|
|
|
42
|
-
class CommitteeClassificationEndDateOccursAfterStartDate(base.DateRule):
|
|
43
|
-
"""CommitteeClassification elements should have end dates that occur after the start dates."""
|
|
44
|
-
|
|
45
|
-
def elements(self):
|
|
46
|
-
return ["CommitteeClassification"]
|
|
47
|
-
|
|
48
|
-
def check(self, element):
|
|
49
|
-
self.reset_instance_vars()
|
|
50
|
-
self.gather_dates(element)
|
|
51
|
-
|
|
52
|
-
if self.end_date and self.start_date:
|
|
53
|
-
self.check_end_after_start()
|
|
54
|
-
if self.error_log:
|
|
55
|
-
raise loggers.ElectionError(self.error_log)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class AffiliationEndDateOccursAfterStartDate(base.DateRule):
|
|
59
|
-
"""Affiliation elements should have end dates that occur after the start dates."""
|
|
60
|
-
|
|
61
|
-
def elements(self):
|
|
62
|
-
return ["Affiliation"]
|
|
63
|
-
|
|
64
|
-
def check(self, element):
|
|
65
|
-
self.reset_instance_vars()
|
|
66
|
-
self.gather_dates(element)
|
|
67
|
-
|
|
68
|
-
if self.end_date and self.start_date:
|
|
69
|
-
self.check_end_after_start()
|
|
70
|
-
if self.error_log:
|
|
71
|
-
raise loggers.ElectionError(self.error_log)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
class EinMatchesFormat(base.BaseRule):
|
|
75
|
-
"""EIN id should be in the following format: XX-XXXXXXX."""
|
|
76
|
-
|
|
77
|
-
def __init__(self, election_tree, schema_tree, **kwargs):
|
|
78
|
-
super(EinMatchesFormat, self).__init__(election_tree, schema_tree, **kwargs)
|
|
79
|
-
regex = r"\d{2}(-\d{7})?"
|
|
80
|
-
self.ein_id_matcher = re.compile(regex, flags=re.U)
|
|
81
|
-
|
|
82
|
-
def elements(self):
|
|
83
|
-
return ["Committee"]
|
|
84
|
-
|
|
85
|
-
def check(self, element):
|
|
86
|
-
external_identifiers = element.find("ExternalIdentifiers")
|
|
87
|
-
if external_identifiers is not None:
|
|
88
|
-
ein_ids = rule_util.get_external_id_values(external_identifiers, "ein")
|
|
89
|
-
if ein_ids:
|
|
90
|
-
e_id = ein_ids.pop()
|
|
91
|
-
if not self.ein_id_matcher.match(e_id):
|
|
92
|
-
raise loggers.ElectionError.from_message(
|
|
93
|
-
"EIN id '{}' is not in the correct format.".format(e_id),
|
|
94
|
-
[element],
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
class AffiliationHasEitherPartyOrPerson(base.BaseRule):
|
|
99
|
-
"""Affiliation should contain either a Party or a Person objectId."""
|
|
100
|
-
|
|
101
|
-
def elements(self):
|
|
102
|
-
return ["Affiliation"]
|
|
103
|
-
|
|
104
|
-
def check(self, element):
|
|
105
|
-
party_id = element.find("PartyId")
|
|
106
|
-
person_id = element.find("PersonId")
|
|
107
|
-
if not ((party_id is None) ^ (person_id is None)):
|
|
108
|
-
raise loggers.ElectionError.from_message(
|
|
109
|
-
"Affiliation must have one of: PartyId, PersonId. Cannot include"
|
|
110
|
-
" both.",
|
|
111
|
-
[element],
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
|
|
115
43
|
class FeedTypeHasValidFeedLongevity(base.BaseRule):
|
|
116
44
|
"""Feeds types should have valid corresponding FeedLongevity."""
|
|
117
45
|
|
|
@@ -489,22 +417,6 @@ class FeedInactiveDateSetForNonEvergreenFeed(base.BaseRule):
|
|
|
489
417
|
)
|
|
490
418
|
|
|
491
419
|
|
|
492
|
-
class UnreferencedEntitiesElectionDates(common_rules.UnreferencedEntitiesBase):
|
|
493
|
-
"""CDF elections and contests are top-level in election dates feeds.
|
|
494
|
-
|
|
495
|
-
All other entity types must be referenced.
|
|
496
|
-
"""
|
|
497
|
-
|
|
498
|
-
def __init__(self, election_tree, schema_tree, **kwargs):
|
|
499
|
-
super(UnreferencedEntitiesElectionDates, self).__init__(
|
|
500
|
-
election_tree,
|
|
501
|
-
schema_tree,
|
|
502
|
-
frozenset(["Election", "Contest"]),
|
|
503
|
-
frozenset([]),
|
|
504
|
-
**kwargs,
|
|
505
|
-
)
|
|
506
|
-
|
|
507
|
-
|
|
508
420
|
class ElectoralCommissionCollectionExists(base.BaseRule):
|
|
509
421
|
"""ElectoralCommissionCollection should exist."""
|
|
510
422
|
|
|
@@ -673,20 +585,10 @@ class RuleSet(enum.Enum):
|
|
|
673
585
|
COMMON_RULES = common_rules.COMMON_RULES
|
|
674
586
|
OFFICEHOLDER_RULES = officeholder_rules.OFFICEHOLDER_RULES
|
|
675
587
|
ELECTION_RULES = election_rules.ELECTION_RULES
|
|
588
|
+
ELECTION_DATES_RULES = election_dates_rules.ELECTION_DATES_RULES
|
|
589
|
+
COMMITTEE_RULES = committee_rules.COMMITTEE_RULES
|
|
676
590
|
|
|
677
591
|
|
|
678
|
-
COMMITTEE_RULES = COMMON_RULES + (
|
|
679
|
-
# go/keep-sorted start
|
|
680
|
-
AffiliationEndDateOccursAfterStartDate,
|
|
681
|
-
AffiliationHasEitherPartyOrPerson,
|
|
682
|
-
CommitteeClassificationEndDateOccursAfterStartDate,
|
|
683
|
-
EinMatchesFormat,
|
|
684
|
-
common_rules.ProhibitElectionData,
|
|
685
|
-
# go/keep-sorted end
|
|
686
|
-
)
|
|
687
|
-
|
|
688
|
-
ELECTION_DATES_RULES = ELECTION_RULES + (UnreferencedEntitiesElectionDates,)
|
|
689
|
-
|
|
690
592
|
METADATA_RULES = (
|
|
691
593
|
# go/keep-sorted start
|
|
692
594
|
ElectionEventDatesAreSequential,
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Copyright 2020 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
"""Validation rules for committee feeds of the CDF XML validator."""
|
|
15
|
+
|
|
16
|
+
from __future__ import print_function
|
|
17
|
+
|
|
18
|
+
import re
|
|
19
|
+
|
|
20
|
+
from civics_cdf_validator import base
|
|
21
|
+
from civics_cdf_validator import loggers
|
|
22
|
+
from civics_cdf_validator.rulesets import common_rules
|
|
23
|
+
from civics_cdf_validator.rulesets import rule_util
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CommitteeClassificationEndDateOccursAfterStartDate(base.DateRule):
|
|
27
|
+
"""CommitteeClassification elements should have end dates that occur after the start dates."""
|
|
28
|
+
|
|
29
|
+
def elements(self):
|
|
30
|
+
return ["CommitteeClassification"]
|
|
31
|
+
|
|
32
|
+
def check(self, element):
|
|
33
|
+
self.reset_instance_vars()
|
|
34
|
+
self.gather_dates(element)
|
|
35
|
+
|
|
36
|
+
if self.end_date and self.start_date:
|
|
37
|
+
self.check_end_after_start()
|
|
38
|
+
if self.error_log:
|
|
39
|
+
raise loggers.ElectionError(self.error_log)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class AffiliationEndDateOccursAfterStartDate(base.DateRule):
|
|
43
|
+
"""Affiliation elements should have end dates that occur after the start dates."""
|
|
44
|
+
|
|
45
|
+
def elements(self):
|
|
46
|
+
return ["Affiliation"]
|
|
47
|
+
|
|
48
|
+
def check(self, element):
|
|
49
|
+
self.reset_instance_vars()
|
|
50
|
+
self.gather_dates(element)
|
|
51
|
+
|
|
52
|
+
if self.end_date and self.start_date:
|
|
53
|
+
self.check_end_after_start()
|
|
54
|
+
if self.error_log:
|
|
55
|
+
raise loggers.ElectionError(self.error_log)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class EinMatchesFormat(base.BaseRule):
|
|
59
|
+
"""EIN id should be in the following format: XX-XXXXXXX."""
|
|
60
|
+
|
|
61
|
+
def __init__(self, election_tree, schema_tree, **kwargs):
|
|
62
|
+
super(EinMatchesFormat, self).__init__(election_tree, schema_tree, **kwargs)
|
|
63
|
+
regex = r"\d{2}(-\d{7})?"
|
|
64
|
+
self.ein_id_matcher = re.compile(regex, flags=re.U)
|
|
65
|
+
|
|
66
|
+
def elements(self):
|
|
67
|
+
return ["Committee"]
|
|
68
|
+
|
|
69
|
+
def check(self, element):
|
|
70
|
+
external_identifiers = element.find("ExternalIdentifiers")
|
|
71
|
+
if external_identifiers is not None:
|
|
72
|
+
ein_ids = rule_util.get_external_id_values(external_identifiers, "ein")
|
|
73
|
+
if ein_ids:
|
|
74
|
+
e_id = ein_ids.pop()
|
|
75
|
+
if not self.ein_id_matcher.match(e_id):
|
|
76
|
+
raise loggers.ElectionError.from_message(
|
|
77
|
+
"EIN id '{}' is not in the correct format.".format(e_id),
|
|
78
|
+
[element],
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class AffiliationHasEitherPartyOrPerson(base.BaseRule):
|
|
83
|
+
"""Affiliation should contain either a Party or a Person objectId."""
|
|
84
|
+
|
|
85
|
+
def elements(self):
|
|
86
|
+
return ["Affiliation"]
|
|
87
|
+
|
|
88
|
+
def check(self, element):
|
|
89
|
+
party_id = element.find("PartyId")
|
|
90
|
+
person_id = element.find("PersonId")
|
|
91
|
+
if not ((party_id is None) ^ (person_id is None)):
|
|
92
|
+
raise loggers.ElectionError.from_message(
|
|
93
|
+
"Affiliation must have one of: PartyId, PersonId. Cannot include"
|
|
94
|
+
" both.",
|
|
95
|
+
[element],
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
COMMITTEE_RULES = common_rules.COMMON_RULES + (
|
|
100
|
+
# go/keep-sorted start
|
|
101
|
+
AffiliationEndDateOccursAfterStartDate,
|
|
102
|
+
AffiliationHasEitherPartyOrPerson,
|
|
103
|
+
CommitteeClassificationEndDateOccursAfterStartDate,
|
|
104
|
+
EinMatchesFormat,
|
|
105
|
+
common_rules.ProhibitElectionData,
|
|
106
|
+
# go/keep-sorted end
|
|
107
|
+
)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright 2020 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
"""Validation rules for election dates feeds of the CDF XML validator."""
|
|
15
|
+
|
|
16
|
+
from __future__ import print_function
|
|
17
|
+
|
|
18
|
+
from civics_cdf_validator.rulesets import common_rules
|
|
19
|
+
from civics_cdf_validator.rulesets import election_rules
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class UnreferencedEntitiesElectionDates(common_rules.UnreferencedEntitiesBase):
|
|
23
|
+
"""CDF elections and contests are top-level in election dates feeds.
|
|
24
|
+
|
|
25
|
+
All other entity types must be referenced.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, election_tree, schema_tree, **kwargs):
|
|
29
|
+
super(UnreferencedEntitiesElectionDates, self).__init__(
|
|
30
|
+
election_tree,
|
|
31
|
+
schema_tree,
|
|
32
|
+
frozenset(["Election", "Contest"]),
|
|
33
|
+
frozenset([]),
|
|
34
|
+
**kwargs,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
ELECTION_DATES_RULES = election_rules.ELECTION_RULES + (
|
|
39
|
+
UnreferencedEntitiesElectionDates,
|
|
40
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/rulesets/election_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.67.dev4 → civics_cdf_validator-1.67.dev6}/rulesets/officeholder_rules.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|