From 20889d67f5fc1f7f81ab5987fdf819e3093a44f9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 08 2015 07:57:42 +0000 Subject: Merge pull request #55 from NerdsvilleCEO/fix_candidate_modification_bug Candidate modification revote bug --- diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py index 4b65e75..14b777c 100644 --- a/fedora_elections/elections.py +++ b/fedora_elections/elections.py @@ -374,7 +374,7 @@ def election_results_text(election_alias): def process_vote(candidates, election, votes, revote, cand_name=None, value=None): for index in range(len(candidates)): candidate = candidates[index] - if revote: + if revote and (index+1 <= len(votes)): vote = votes[index] if value is not None: vote.candidate_id = candidate.data diff --git a/tests/test_flask_range_voting.py b/tests/test_flask_range_voting.py index c18aca9..494c6e5 100644 --- a/tests/test_flask_range_voting.py +++ b/tests/test_flask_range_voting.py @@ -314,11 +314,21 @@ class FlaskRangeElectionstests(ModelFlasktests): #Let's not do repetition of what is tested above we aren't testing the #functionality of voting as that has already been asserted + obj = fedora_elections.models.Candidate( # id:16 + election_id=3, + name='Josh', + url='https://fedoraproject.org/wiki/User:Nerdsville', + ) + self.session.add(obj) + self.session.commit() + + #Next, we need to try revoting newdata = { '4': 2, '5': 1, '6': 1, + '16': 0, 'action': 'submit', 'csrf_token': csrf_token, } @@ -336,6 +346,7 @@ class FlaskRangeElectionstests(ModelFlasktests): self.assertEqual(votes[0].value, 2) self.assertEqual(votes[1].value, 1) self.assertEqual(votes[2].value, 1) + self.assertEqual(votes[3].value, 0) #If we haven't failed yet, HOORAY!