Example #1
0
    def test_catch_fraud(self):
        """
        Checks to make sure that if someone is caught voting twice:

        1. Only their first ballot is counted
        2. The fraudster's name is recorded
        """
        voter = all_voters[0]
        ballot_number1 = balloting.issue_ballot(voter.national_id)
        ballot_number2 = balloting.issue_ballot(voter.national_id)
        ballot_number3 = balloting.issue_ballot(voter.national_id)

        all_candidates = registry.get_all_candidates()
        ballot1 = Ballot(ballot_number1, all_candidates[0].candidate_id, "first ballot")
        ballot2 = Ballot(ballot_number2, all_candidates[0].candidate_id, "second ballot")
        ballot3 = Ballot(ballot_number3, all_candidates[0].candidate_id, "third ballot")

        # Have the voter commit fraud
        assert balloting.count_ballot(ballot1, voter.national_id) == BallotStatus.BALLOT_COUNTED
        assert balloting.count_ballot(ballot2, voter.national_id) == BallotStatus.FRAUD_COMMITTED
        assert registry.get_voter_status(voter.national_id) == VoterStatus.FRAUD_COMMITTED
        assert balloting.count_ballot(ballot3, voter.national_id) == BallotStatus.FRAUD_COMMITTED
        assert registry.get_voter_status(voter.national_id) == VoterStatus.FRAUD_COMMITTED

        # Make sure the fraudster's name is recorded
        fraudsters = balloting.get_all_fraudulent_voters()
        assert len(fraudsters) == 1
        assert (voter.first_name + " " + voter.last_name) in balloting.get_all_fraudulent_voters()

        # Make sure ballot 2 and 3 weren't counted
        ballot_comments = balloting.get_all_ballot_comments()
        assert len(ballot_comments) == 1
        assert "first ballot" in ballot_comments
Example #2
0
    def test_ballot_comment_redaction_national_id(self):
        """
        Checks that comment redaction works
        """
        voter = all_voters[0]
        ballot_number = balloting.issue_ballot(voter.national_id)

        original_comment = """
        345-23-2334
        345232334
        345 43 3452
        """.strip()

        all_candidates = registry.get_all_candidates()
        ballot = Ballot(ballot_number, all_candidates[0].candidate_id, original_comment)
        assert balloting.count_ballot(ballot, voter.national_id) == BallotStatus.BALLOT_COUNTED

        all_ballot_comments = balloting.get_all_ballot_comments()
        assert len(all_ballot_comments) == 1

        expected_redacted_comment = """
        [REDACTED NATIONAL ID]
        [REDACTED NATIONAL ID]
        [REDACTED NATIONAL ID]
        """.strip()
        assert list(all_ballot_comments)[0] == expected_redacted_comment
Example #3
0
    def test_invalidate_ballot_after_use(self):
        """
        Ensures that a ballot that is cast cannot be invalidated
        """
        voter = all_voters[0]
        ballot_number1 = balloting.issue_ballot(voter.national_id)

        all_candidates = registry.get_all_candidates()
        ballot1 = Ballot(ballot_number1, all_candidates[0].candidate_id, "valid now, but invalid later")

        assert balloting.count_ballot(ballot1, voter.national_id) == BallotStatus.BALLOT_COUNTED
        assert balloting.invalidate_ballot(ballot_number1) is False

        # The ballot cannot be invalidated after being cast - it should still be counted
        assert len(balloting.get_all_ballot_comments()) == 1
Example #4
0
    def test_count_ballot_mismatch(self):
        """
        If the wrong voter issues a ballot, the count_ballot endpoint should say so. The ballot should still remain
        for the true voter to used
        """
        voter1, voter2 = all_voters[0:2]
        ballot_number2 = balloting.issue_ballot(voter2.national_id)

        all_candidates = registry.get_all_candidates()

        # Have the wrong voter cast the ballot
        ballot2_attempt1 = Ballot(ballot_number2, all_candidates[0].candidate_id, "Attempt 1")
        assert balloting.count_ballot(ballot2_attempt1, voter1.national_id) == BallotStatus.VOTER_BALLOT_MISMATCH

        # Now, have the right voter cast the ballot
        ballot2_attempt2 = Ballot(ballot_number2, all_candidates[1].candidate_id, "Attempt 2")
        assert balloting.count_ballot(ballot2_attempt2, voter2.national_id) == BallotStatus.BALLOT_COUNTED

        ballot_comments = balloting.get_all_ballot_comments()
        assert len(ballot_comments) == 1
        assert "Attempt 2" in ballot_comments
Example #5
0
    def test_ballot_comment_redaction_composite(self):
        """
        Checks that comment redaction works
        """
        voter = all_voters[0]
        ballot_number = balloting.issue_ballot(voter.national_id)

        original_comment = """
        Hi there,
        My name is {0}, and prioritizing public transportation is _very_ important to me. It takes me at least 90
        minutes to get to work each day, largely because the infrastructure here hasn't been built yet. It's critical
        for us to invest in this. If you'd like to contact me please reach out to me at 329 112-4535, or at
        [email protected].

        Cheers,

        {0} {1}
        Id: {2}
        """.format(voter.first_name, voter.last_name, voter.national_id).strip()

        all_candidates = registry.get_all_candidates()
        ballot = Ballot(ballot_number, all_candidates[0].candidate_id, original_comment)
        assert balloting.count_ballot(ballot, voter.national_id) == BallotStatus.BALLOT_COUNTED

        all_ballot_comments = balloting.get_all_ballot_comments()
        assert len(all_ballot_comments) == 1

        expected_redacted_comment = """
        Hi there,
        My name is {0}, and prioritizing public transportation is _very_ important to me. It takes me at least 90
        minutes to get to work each day, largely because the infrastructure here hasn't been built yet. It's critical
        for us to invest in this. If you'd like to contact me please reach out to me at [REDACTED PHONE NUMBER], or at
        [REDACTED EMAIL].

        Cheers,

        {0} {1}
        Id: {2}
        """.format("[REDACTED NAME]", "[REDACTED NAME]", "[REDACTED NATIONAL ID]").strip()
        assert list(all_ballot_comments)[0] == expected_redacted_comment
Example #6
0
    def test_ballot_comment_redaction_phone_number(self):
        """
        Checks that comment redaction works
        """
        voter = all_voters[0]
        ballot_number = balloting.issue_ballot(voter.national_id)

        original_comment = """
        (839) 838-1627,839 838-1627,839-838-1627,8398381627
        """.strip()

        all_candidates = registry.get_all_candidates()
        ballot = Ballot(ballot_number, all_candidates[0].candidate_id, original_comment)
        assert balloting.count_ballot(ballot, voter.national_id) == BallotStatus.BALLOT_COUNTED

        all_ballot_comments = balloting.get_all_ballot_comments()
        assert len(all_ballot_comments) == 1

        expected_redacted_comment = """
        [REDACTED PHONE NUMBER],[REDACTED PHONE NUMBER],[REDACTED PHONE NUMBER],[REDACTED PHONE NUMBER]
        """.strip()
        assert list(all_ballot_comments)[0] == expected_redacted_comment