def test_add_vote(self, mock_boto3_resource, mock_boto3_client): manager = DynamoDBManager() voter_id = "1337" event_id = "1111" candidate = "Person Personson" # Case 1: everything is normal --------------------------------------------------------------------------------- response = manager.add_vote(voter_id, event_id, candidate) assert response == respond( 'Congratulations! You have successfully cast your vote for the candidate {candidate}!' .format(candidate=candidate), 200) # -------------------------------------------------------------------------------------------------------------- # Case 2: no such candidate ------------------------------------------------------------------------------------ manager.get_candidate = (lambda candidate_name: None) response = manager.add_vote(voter_id, event_id, candidate) assert response == respond( "NO SUCH CANDIDATE, PLEASE ENTER THE CORRECT FULL NAME", 404)
def test_get_candidate(self, mock_boto3_resource): manager = DynamoDBManager() candidate_full_name = "Person Personson" manager.get_candidate(candidate_full_name) manager.candidates_table.get_item.assert_called_with( Key={"full_name": candidate_full_name})