def audit_elections( data_opened: str, data_pre_election: str, data_tally: str, bb: str, tally_all: str, group_id: Optional[str] = typer.Argument(None), ): data_pre_election = _load_pre_election(data_pre_election) data_tally = _load_tally_data(data_tally) print("Auditing pre_election - data_tally...") with click_spinner.spinner(): valid = audit_pre_election_tables(data_pre_election, data_tally) print("valid" if valid else "not valid!") del data_pre_election data_opened = _load_opened_data(data_opened) print("Auditing data_tally - data_opened...") with click_spinner.spinner(): valid = audit_tables(data_opened, data_tally) print("valid" if valid else "not valid") del data_tally bb = _load_bb(bb) if group_id is not None: print( f"Filtering bulletin board is enabled, only votes for group {group_id} will be taken into account" ) bb_filtered = {} for vote_id, bb_entry in bb.items(): if bb_entry.group_id == group_id: bb_filtered[vote_id] = bb_entry bb = bb_filtered print("Auditing data_opened - bb...") with click_spinner.spinner(): valid = audit_bb(bb, data_opened) print("valid" if valid else "not valid") del bb tally_all = _load_tally(tally_all) print("Auditing data_opened - tally with all votes...") with click_spinner.spinner(): valid = audit_tables_tally(tally_all, data_opened) print("valid" if valid else "not valid")
def test_audit_bb_invalid_opened_data(bb: BulletinBoard, invalid_opened_data: AuditTables): assert audit_bb(bb, invalid_opened_data) is False
def test_audit_bb_voted_twice(bb_voted_twice: BulletinBoard, opened_data: AuditTables): assert audit_bb(bb_voted_twice, opened_data) is True
def test_audit_empty_bb(invalid_bb_empty: BulletinBoard): assert audit_bb(invalid_bb_empty, {}) is False
def test_audit_bb(bb: BulletinBoard, opened_data: AuditTables): assert audit_bb(bb, opened_data) is True