Skip to content
Merged
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
2 changes: 1 addition & 1 deletion civicpatch/Dockerfile.github-actions
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ RUN poetry install

FROM image-base AS post-install

RUN poetry run playwright install --with-deps chromium
RUN poetry run playwright install --with-deps chrome

RUN poetry run post-install

Expand Down
3 changes: 3 additions & 0 deletions civicpatch/src/utils/people_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def normalize_roles(roles: List[str]) -> List[str]:
for role in roles:
role = str(role).strip().lower()

if not role:
continue

direct_match = role_aliases.get(role)
if direct_match:
seen.add(direct_match)
Expand Down
62 changes: 20 additions & 42 deletions civicpatch/tests/unit/scripts/test_generate_review_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,38 +182,30 @@ def test_direct_name_match():
url="https://city.gov",
identities={"michelle drass": ["michelle d rass"]}
)
research = ResearchMunicipalityStep(
people=[],
elected_officials=[ResearchedPerson(name="michelle drass", roles=["mayor"], designations=[])]
)

officials = [make_official("michelle drass")]
people = [make_official("michelle drass")]
errors = get_identity_mismatches(research, config, people)
errors = get_identity_mismatches(officials, config, people)
assert errors == []

def test_alias_match():
config = WorkflowConfig(
url="https://city.gov",
identities={"michelle drass": ["michelle d rass"]}
)
research = ResearchMunicipalityStep(
people=[],
elected_officials=[ResearchedPerson(name="michelle drass", roles=["mayor"], designations=[])]
)
people = [make_official("michelle d rass")]
errors = get_identity_mismatches(research, config, people)
officials = [make_official("michelle drass")]
errors = get_identity_mismatches(officials, config, people)
assert errors == []

def test_missing_official():
config = WorkflowConfig(
url="https://city.gov",
identities={"michelle drass": ["michelle d rass"]}
)
research = ResearchMunicipalityStep(
people=[],
elected_officials=[ResearchedPerson(name="michelle drass", roles=["mayor"], designations=[])]
)
people = [make_official("john smith")]
errors = get_identity_mismatches(research, config, people)
officials = [make_official("michelle drass")]
errors = get_identity_mismatches(officials, config, people)
assert errors == [
"Extra official: john smith",
"Missing official: michelle drass"
Expand All @@ -232,7 +224,8 @@ def test_multiple_officials_some_missing():
]
)
people = [make_official("michelle d rass"), make_official("john smith")]
errors = get_identity_mismatches(research, config, people)
officials = [make_official("michelle drass"), make_official("jane smith")]
errors = get_identity_mismatches(officials, config, people)
assert errors == [
"Extra official: john smith",
"Missing official: jane smith"
Expand All @@ -243,44 +236,32 @@ def test_extra_official_in_people():
url="https://city.gov",
identities={"michelle drass": ["michelle d rass"]}
)
research = ResearchMunicipalityStep(
people=[],
elected_officials=[ResearchedPerson(name="michelle drass", roles=["mayor"], designations=[])]
)
people = [make_official("michelle drass"), make_official("john smith")]
errors = get_identity_mismatches(research, config, people)

officials = [make_official("michelle drass")]
errors = get_identity_mismatches(officials, config, people)
assert errors == ["Extra official: john smith"]

def test_extra_official_in_research():
config = WorkflowConfig(
url="https://city.gov",
identities={"michelle drass": ["michelle d rass"]}
)
research = ResearchMunicipalityStep(
people=[],
elected_officials=[
ResearchedPerson(name="michelle drass", roles=["mayor"], designations=[]),
ResearchedPerson(name="jane smith", roles=["council"], designations=[])
]
)

people = [make_official("michelle d rass")]
errors = get_identity_mismatches(research, config, people)
officials = [make_official("michelle drass"), make_official("jane smith")]
errors = get_identity_mismatches(officials, config, people)
assert errors == ["Missing official: jane smith"]

def test_both_extra_and_missing_officials():
config = WorkflowConfig(
url="https://city.gov",
identities={"michelle drass": ["michelle d rass"]}
)
research = ResearchMunicipalityStep(
people=[],
elected_officials=[
ResearchedPerson(name="michelle drass", roles=["mayor"], designations=[]),
ResearchedPerson(name="jane smith", roles=["council"], designations=[])
]
)

people = [make_official("michelle d rass"), make_official("john smith")]
errors = get_identity_mismatches(research, config, people)
officials = [make_official("michelle drass"), make_official("jane smith")]
errors = get_identity_mismatches(officials, config, people)
assert errors == [
"Extra official: john smith",
"Missing official: jane smith"
Expand All @@ -291,10 +272,7 @@ def test_no_officials():
url="https://city.gov",
identities={}
)
research = ResearchMunicipalityStep(
people=[],
elected_officials=[]
)

people = []
errors = get_identity_mismatches(research, config, people)
errors = get_identity_mismatches([], config, people)
assert errors == []
2 changes: 1 addition & 1 deletion civicpatch/tests/unit/utils/test_people_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@pytest.mark.parametrize("roles, expected", [
(["Mayor", "mayor"], ["Mayor"]), # Case-insensitive deduplication
(["Mayor", "Chief Executive"], ["Mayor"]), # Alias normalization
(["Mayor", "Chief Executive"], ["Mayor", "Chief Executive"]), # Alias normalization
([], []), # Empty input
([None, ""], []), # Invalid roles
([" mayor ", "MAYOR"], ["Mayor"]), # Mixed case and whitespace
Expand Down
Loading