Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Improves error msgs for kandidatengde, fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas committed Aug 8, 2019
1 parent e41a98e commit 5267001
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions onegov/election_day/formats/election/wabstic_majorz.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def has_no_lines(lines, filename):
return True
return False


# Read the files
wm_wahl, error = load_csv(
file_wm_wahl, mimetype_wm_wahl,
Expand Down Expand Up @@ -340,17 +339,22 @@ def has_no_lines(lines, filename):
try:
entity_id = get_entity_id(line)
candidate_id = validate_column(line, 'knr')
assert candidate_id in added_candidates
votes = validate_integer(line, 'stimmen')
except (ValueError, AssertionError):
except ValueError:
line_errors.append(_("Invalid candidate results"))
else:
if added_candidates and candidate_id not in added_candidates:
line_errors.append(
_("Candidate with id ${id} not in wm_kandidaten",
mapping={'id': candidate_id}))
if entity_id == 0 and not election.expats:
# Skip expats if not enabled
continue

if entity_id not in added_entities:
line_errors.append(_("Invalid entity values"))
line_errors.append(
_("Entity with id ${id} not in wmstatic_gemeinden",
mapping={'id': entity_id}))

# Pass the errors and continue to next line
if line_errors:
Expand Down
2 changes: 1 addition & 1 deletion onegov/election_day/formats/election/wabstic_proporz.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def has_no_lines(lines, filename):
elected = True if line.gewaehlt == '1' else False
except (ValueError, AssertionError):
line_errors.append(
_("Candidate with id ${id} not in wpstatic_candidates",
_("Candidate with id ${id} not in wpstatic_kandidaten",
mapping={'id': candidate_id}))
else:
added_candidates[candidate_id]['elected'] = elected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ def test_import_wabstic_majorz_invalid_values(session):
('wm_gemeinden', 2, 'Invalid integer: stimmberechtigte'),
('wm_gemeinden', 2, 'Invalid integer: stmabgegeben'),
('wm_kandidatengde', 2, 'Invalid candidate results'),
('wm_kandidatengde', 3, 'Invalid candidate results'),
('wm_kandidatengde', 3, 'Candidate with id 100 not in wm_kandidaten'),
('wm_kandidatengde', 3, 'Entity with id 3256 not in wmstatic_gemeinden'),
('wm_wahl', 2, 'Invalid integer: absolutesmehr'),
('wm_wahl', 2, 'Value of ausmittlungsstand not between 0 and 3'),
('wmstatic_gemeinden', 2, '100 is unknown'),
Expand Down

0 comments on commit 5267001

Please sign in to comment.