fedora_elections/elections.py | 41 ++++++++++++++----------
fedora_elections/templates/index.html | 2 -
nosetests | 4 +-
tests/test_flask_select_voting.py | 56 +++++++++++++++++++++++++++++-----
4 files changed, 75 insertions(+), 28 deletions(-)
New commits:
commit 8dfa93269c7888f97fc4ef786571683323470788
Merge: aa3ce6c 095eb79
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Tue Sep 1 12:00:33 2015 +0200
Merge pull request #50 from fedora-infra/fix_tests
Let's not require a specific version of nose to run the tests
commit 095eb79d91b2d30a4abbba454ec56442516aecc5
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Tue Sep 1 10:28:24 2015 +0200
Let's not require a specific version of nose to run the tests
diff --git a/nosetests b/nosetests
index 42c36f1..d050ee4 100755
--- a/nosetests
+++ b/nosetests
@@ -1,10 +1,10 @@
#!/usr/bin/env python
# EASY-INSTALL-ENTRY-SCRIPT: 'nose==1.3.0','console_scripts','nosetests'
-__requires__ = ['nose==1.3.0', 'flask>=0.10']
+__requires__ = ['nose', 'flask>=0.10']
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
- load_entry_point('nose==1.3.0', 'console_scripts', 'nosetests')()
+ load_entry_point('nose', 'console_scripts', 'nosetests')()
)
commit aa3ce6cc434433c2b072b99030ca72e24363d186
Merge: 728c885 cc5e577
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Tue Sep 1 11:48:06 2015 +0200
Merge pull request #49 from NerdsvilleCEO/add-select-revote
Add select revote
commit cc5e57713f14e0f6cb7702eca3b1333aecbf65e2
Author: Joshua Santos <Nerdsville(a)nerdsville.net>
Date: Tue Aug 11 14:54:34 2015 -0700
Update elections.py
diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py
index 4ca1ec3..f37cbfa 100644
--- a/fedora_elections/elections.py
+++ b/fedora_elections/elections.py
@@ -214,10 +214,10 @@ def vote_select(election, revote):
else:
if form.action.data == 'submit':
candidates = [
- candidate
- for candidate in form
- if candidate and candidate.short_name not in ['csrf_token', 'action']
- ]
+ candidate
+ for candidate in form
+ if candidate and candidate.short_name not in ['csrf_token', 'action']
+ ]
for index in range(len(candidates)):
candidate = candidates[index]
if revote:
commit 68f4c1aa7a818a7e693a3484452902d3a0c41bea
Author: Joshua Santos <nerdsville(a)nerdsville.net>
Date: Tue Aug 11 10:28:20 2015 -0700
Add template condition
diff --git a/fedora_elections/templates/index.html b/fedora_elections/templates/index.html
index 2add908..c796319 100644
--- a/fedora_elections/templates/index.html
+++ b/fedora_elections/templates/index.html
@@ -32,7 +32,7 @@
<a href="{{ url_for('vote', election_alias=election.alias) }}">
Vote now!
</a>
- {% elif election.voting_type == 'range' %}
+ {% elif election.voting_type == 'range' or election.voting_type == 'select' %}
<a href="{{ url_for('vote', election_alias=election.alias) }}">
Change your vote!
</a>
commit 2dbf5f16bf42ab9a7547be6b56007f5b54c0397a
Author: Joshua Santos <nerdsville(a)nerdsville.net>
Date: Tue Aug 11 10:25:35 2015 -0700
Fix description of select revote test
diff --git a/tests/test_flask_select_voting.py b/tests/test_flask_select_voting.py
index 845d94e..a9ba872 100644
--- a/tests/test_flask_select_voting.py
+++ b/tests/test_flask_select_voting.py
@@ -161,7 +161,7 @@ class FlaskSimpleElectionstests(ModelFlasktests):
self.assertTrue('<h3>Last 2 elections</h3>' in output.data)
def test_vote_select_revote(self):
- """ Test the vote_range function - the re-voting part. """
+ """ Test the vote_select function - the re-voting part. """
#First we need to vote
self.setup_db()
commit 1667763a8af6b6e2aa76fa3536e90f69d50882ba
Author: Joshua Santos <nerdsville(a)nerdsville.net>
Date: Tue Aug 11 10:24:09 2015 -0700
Add select revote
diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py
index 1e6706c..4ca1ec3 100644
--- a/fedora_elections/elections.py
+++ b/fedora_elections/elections.py
@@ -114,7 +114,7 @@ def vote(election_alias):
elif election.voting_type == 'simple':
return vote_simple(election)
elif election.voting_type == 'select':
- return vote_select(election)
+ return vote_select(election, revote)
elif election.voting_type == 'irc':
return vote_irc(election)
else: # pragma: no cover
@@ -182,9 +182,9 @@ def vote_range(election, revote):
nextaction=next_action)
-def vote_select(election):
+def vote_select(election, revote):
votes = models.Vote.of_user_on_election(
- SESSION, flask.g.fas_user.username, election.id, count=True)
+ SESSION, flask.g.fas_user.username, election.id)
num_candidates = election.candidates.count()
@@ -213,20 +213,27 @@ def vote_select(election):
flask.flash('Too many candidates submitted', 'error')
else:
if form.action.data == 'submit':
- for candidate in form:
- if candidate.short_name in ['csrf_token', 'action']:
- continue
-
- new_vote = models.Vote(
- election_id=election.id,
- voter=flask.g.fas_user.username,
- timestamp=datetime.now(),
- candidate_id=cand_name[candidate.short_name],
- value=int(candidate.data),
- )
- SESSION.add(new_vote)
- SESSION.commit()
-
+ candidates = [
+ candidate
+ for candidate in form
+ if candidate and candidate.short_name not in ['csrf_token', 'action']
+ ]
+ for index in range(len(candidates)):
+ candidate = candidates[index]
+ if revote:
+ vote = votes[index]
+ vote.value = int(candidate.data)
+ SESSION.add(vote)
+ else:
+ new_vote = models.Vote(
+ election_id=election.id,
+ voter=flask.g.fas_user.username,
+ timestamp=datetime.now(),
+ candidate_id=cand_name[candidate.short_name],
+ value=int(candidate.data),
+ )
+ SESSION.add(new_vote)
+ SESSION.commit()
flask.flash("Your vote has been recorded. Thank you!")
return safe_redirect_back()
diff --git a/tests/test_flask_select_voting.py b/tests/test_flask_select_voting.py
index 73d2ca0..845d94e 100644
--- a/tests/test_flask_select_voting.py
+++ b/tests/test_flask_select_voting.py
@@ -55,14 +55,6 @@ class FlaskSimpleElectionstests(ModelFlasktests):
self.setup_db()
- user = FakeUser(['packager'], username='toshio')
- with user_set(fedora_elections.APP, user):
- output = self.app.get(
- '/vote/test_election6', follow_redirects=True)
- self.assertTrue(
- 'class="message">You have already voted in the election!</'
- in output.data)
-
user = FakeUser(['packager'], username='pingou')
with user_set(fedora_elections.APP, user):
output = self.app.get(
@@ -168,6 +160,54 @@ class FlaskSimpleElectionstests(ModelFlasktests):
self.assertTrue('<h3>Next 1 elections</h3>' in output.data)
self.assertTrue('<h3>Last 2 elections</h3>' in output.data)
+ def test_vote_select_revote(self):
+ """ Test the vote_range function - the re-voting part. """
+ #First we need to vote
+ self.setup_db()
+
+ user = FakeUser(['voters'], username='nerdsville')
+ with user_set(fedora_elections.APP, user):
+ retrieve_csrf = self.app.post('/vote/test_election6')
+ csrf_token = retrieve_csrf.data.split(
+ 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+
+ # Valid input
+ data = {
+ 'Kevin': True,
+ 'action': 'submit',
+ 'csrf_token': csrf_token,
+ }
+ self.app.post('/vote/test_election6', data=data, follow_redirects=True)
+ vote = fedora_elections.models.Vote
+ votes = vote.of_user_on_election(self.session, "nerdsville", '6')
+ self.assertEqual(votes[0].candidate.name, "Toshio")
+ self.assertEqual(votes[0].value, 0)
+ self.assertEqual(votes[1].candidate.name, "Kevin")
+ self.assertEqual(votes[1].value, 1)
+
+ #Next, we need to try revoting
+ newdata = {
+ 'Toshio': True,
+ 'action': 'submit',
+ 'csrf_token': csrf_token,
+ }
+ output = self.app.post('/vote/test_election6', data=newdata, follow_redirects=True)
+ #Next, we need to check if the vote has been recorded
+ self.assertEqual(output.status_code, 200)
+ self.assertTrue(
+ 'class="message">Your vote has been recorded. Thank you!</'
+ in output.data)
+ self.assertTrue('<h3>Current elections</h3>' in output.data)
+ self.assertTrue('<h3>Next 1 elections</h3>' in output.data)
+ self.assertTrue('<h3>Last 2 elections</h3>' in output.data)
+ vote = fedora_elections.models.Vote
+ votes = vote.of_user_on_election(self.session, "nerdsville", '6')
+ self.assertEqual(votes[0].value, 1)
+ self.assertEqual(votes[1].value, 0)
+
+
+ #If we haven't failed yet, HOORAY!
+
if __name__ == '__main__':
SUITE = unittest.TestLoader().loadTestsFromTestCase(