fedora_elections/elections.py | 8 -
fedora_elections/forms.py | 10 -
fedora_elections/models.py | 2
tests/test_election.py | 2
tests/test_flask_for_abstain_against_voting.py | 157 -------------------------
tests/test_flask_irc.py | 157 +++++++++++++++++++++++++
6 files changed, 168 insertions(+), 168 deletions(-)
New commits:
commit 64c3628ffa812ad5e642e3fd28932d63a1e1bacc
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Tue Aug 26 16:27:59 2014 +0200
Change ``for_abstain_against`` voting to ``irc`` voting
diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py
index bfff1cd..2ad0e1e 100644
--- a/fedora_elections/elections.py
+++ b/fedora_elections/elections.py
@@ -117,8 +117,8 @@ def vote(election_alias):
return vote_simple(election)
elif election.voting_type == 'select':
return vote_select(election)
- elif election.voting_type == 'for_abstain_against':
- return vote_for_abstain_against(election)
+ elif election.voting_type == 'irc':
+ return vote_irc(election)
else: # pragma: no cover
flask.flash(
'Unknown election voting type: %s' % election.voting_type)
@@ -303,7 +303,7 @@ def vote_simple(election):
nextaction=next_action)
-def vote_for_abstain_against(election):
+def vote_irc(election):
votes = models.Vote.of_user_on_election(
SESSION, flask.g.fas_user.username, election.id, count=True)
@@ -314,7 +314,7 @@ def vote_for_abstain_against(election):
num_candidates = election.candidates.count()
next_action = 'confirm'
- form=forms.get_for_abstain_against_voting_form(
+ form=forms.get_irc_voting_form(
candidates=election.candidates,
fasusers=election.candidates_are_fasusers)
if form.validate_on_submit():
diff --git a/fedora_elections/forms.py b/fedora_elections/forms.py
index 50f676b..7150564 100644
--- a/fedora_elections/forms.py
+++ b/fedora_elections/forms.py
@@ -37,7 +37,7 @@ class ElectionForm(wtf.Form):
('range_3', 'Simplified Range Voting (max is set below)'),
('select', 'Select Voting (checkboxes for each candidate, '
'maximum number of votes set below)'),
- ('for_abstain_against', '+1/0/-1 voting'),
+ ('irc', '+1/0/-1 voting'),
],
default='range')
@@ -160,8 +160,8 @@ def get_simple_voting_form(candidates, fasusers):
return SimpleVoting()
-def get_for_abstain_against_voting_form(candidates, fasusers):
- class ForAbstainAgainstVoting(wtf.Form):
+def get_irc_voting_form(candidates, fasusers):
+ class IrcVoting(wtf.Form):
action = wtforms.HiddenField()
for candidate in candidates:
@@ -169,9 +169,9 @@ def get_for_abstain_against_voting_form(candidates, fasusers):
candidate.name,
choices=[('0',0),('1',1),('-1',-1)]
)
- setattr(ForAbstainAgainstVoting, candidate.name, field)
+ setattr(IrcVoting, candidate.name, field)
- return ForAbstainAgainstVoting()
+ return IrcVoting()
def get_select_voting_form(candidates, max_selection):
diff --git a/fedora_elections/models.py b/fedora_elections/models.py
index 1ff263f..74af82d 100644
--- a/fedora_elections/models.py
+++ b/fedora_elections/models.py
@@ -420,7 +420,7 @@ class Vote(BASE):
stats['max_vote'] = election.max_votes
elif election.voting_type == 'simple':
stats['max_vote'] = 1
- elif election.voting_type == 'for_abstain_against':
+ elif election.voting_type == 'irc':
stats['max_vote'] = 1
return stats
diff --git a/tests/test_election.py b/tests/test_election.py
index fe1e17e..583ce13 100644
--- a/tests/test_election.py
+++ b/tests/test_election.py
@@ -182,7 +182,7 @@ class Electiontests(Modeltests):
end_date=TODAY + timedelta(days=3),
seats_elected=1,
embargoed=1,
- voting_type='for_abstain_against',
+ voting_type='irc',
candidates_are_fasusers=0,
max_votes=1,
fas_user='nerdsville',
diff --git a/tests/test_flask_for_abstain_against_voting.py
b/tests/test_flask_for_abstain_against_voting.py
deleted file mode 100644
index 243159d..0000000
--- a/tests/test_flask_for_abstain_against_voting.py
+++ /dev/null
@@ -1,157 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-"""
- (c) 2014 - Copyright Joshua Santos
- Author: Joshua Santos <nerdsville(a)nerdsville.net>
-
-# This copyrighted material is made available to anyone wishing to use, modify,
-# copy, or redistribute it subject to the terms and conditions of the GNU
-# General Public License v.2, or (at your option) any later version. This
-# program is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY expressed or implied, including the implied warranties of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-# Public License for more details. You should have received a copy of the GNU
-# General Public License along with this program; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the source
-# code or documentation are not subject to the GNU General Public License and
-# may only be used or replicated with the express permission of Red Hat, Inc.
-
- fedora_elections.elections test script
-"""
-__requires__ = ['SQLAlchemy >= 0.7', 'jinja2 >= 2.4']
-import pkg_resources
-
-import logging
-import unittest
-import sys
-import os
-
-from datetime import time
-from datetime import timedelta
-
-import flask
-
-sys.path.insert(0, os.path.join(os.path.dirname(
- os.path.abspath(__file__)), '..'))
-
-import fedora_elections
-from tests import ModelFlasktests, Modeltests, TODAY, FakeUser, user_set
-
-
-# pylint: disable=R0904
-class FlaskSimpleElectionstests(ModelFlasktests):
- """ Flask application tests range voting. """
-
- def test_vote_for_abstain_against(self):
- """ Test the vote_for_abstain_against function - the preview part.
"""
- output = self.app.get(
- '/vote/test_election', follow_redirects=True)
- self.assertEqual(output.status_code, 200)
- self.assertTrue(
- '<title>OpenID transaction in progress</title>' in
output.data
- or 'discoveryfailure' in output.data)
-
- self.setup_db()
-
- user = FakeUser(['packager'], username='toshio')
- with user_set(fedora_elections.APP, user):
- output = self.app.get(
- '/vote/test_election7', follow_redirects=True)
- self.assertTrue(
- 'class="message">You have already voted in the
election!</'
- in output.data)
-
- user = FakeUser(['packager'], username='nerdsville')
- with user_set(fedora_elections.APP, user):
- output = self.app.get(
- '/vote/test_election7')
- self.assertTrue(
- '<h2>test election 7 shortdesc</h2>' in output.data)
- self.assertTrue(
- '<input type="hidden" name="action"
value="preview" />'
- in output.data)
-
- csrf_token = output.data.split(
- 'name="csrf_token" type="hidden"
value="')[1].split('">')[0]
-
- # Invalid vote: No candidate
- data = {
- 'action': 'preview',
- }
-
- output = self.app.post('/vote/test_election7', data=data)
- self.assertEqual(output.status_code, 200)
- self.assertTrue(
- '<h2>test election 7 shortdesc</h2>' in output.data)
-
- # Valid input
- data = {
- 'Kevin': -1,
- 'Toshio': '0',
- 'action': 'preview',
- 'csrf_token': csrf_token,
- }
-
- output = self.app.post('/vote/test_election7', data=data)
- self.assertEqual(output.status_code, 200)
- self.assertTrue(
- '<h2>test election 7 shortdesc</h2>' in output.data)
- self.assertTrue(
- '<input type="hidden" name="action"
value="submit" />'
- in output.data)
- self.assertTrue(
- '<li class="message">Please confirm your
vote!</li>'
- in output.data)
-
- def test_vote_for_abstain_against_process(self):
- """ Test the vote_for_abstain_against function - the voting part.
"""
- output = self.app.get(
- '/vote/test_election', follow_redirects=True)
- self.assertEqual(output.status_code, 200)
- self.assertTrue(
- '<title>OpenID transaction in progress</title>' in
output.data
- or 'discoveryfailure' in output.data)
-
- self.setup_db()
-
- user = FakeUser(['packager'], username='pingou')
- with user_set(fedora_elections.APP, user):
- # Invalid candidate id - no csrf
- data = {
- 'candidate': 1,
- 'action': 'submit',
- }
-
- output = self.app.post(
- '/vote/test_election7', data=data,
- follow_redirects=True)
- self.assertEqual(output.status_code, 200)
-
- csrf_token = output.data.split(
- 'name="csrf_token" type="hidden"
value="')[1].split('">')[0]
-
- # Valid input
- data = {
- 'Toshio': '0',
- 'Kevin': '1',
- 'action': 'submit',
- 'csrf_token': csrf_token,
- }
-
- output = self.app.post(
- '/vote/test_election7', data=data,
- follow_redirects=True)
- 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)
-
-
-if __name__ == '__main__':
- SUITE = unittest.TestLoader().loadTestsFromTestCase(FlaskSimpleElectionstests)
- unittest.TextTestRunner(verbosity=2).run(SUITE)
diff --git a/tests/test_flask_irc.py b/tests/test_flask_irc.py
new file mode 100644
index 0000000..44d467d
--- /dev/null
+++ b/tests/test_flask_irc.py
@@ -0,0 +1,157 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+"""
+ (c) 2014 - Copyright Joshua Santos
+ Author: Joshua Santos <nerdsville(a)nerdsville.net>
+
+# This copyrighted material is made available to anyone wishing to use, modify,
+# copy, or redistribute it subject to the terms and conditions of the GNU
+# General Public License v.2, or (at your option) any later version. This
+# program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details. You should have received a copy of the GNU
+# General Public License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the source
+# code or documentation are not subject to the GNU General Public License and
+# may only be used or replicated with the express permission of Red Hat, Inc.
+
+ fedora_elections.elections test script
+"""
+__requires__ = ['SQLAlchemy >= 0.7', 'jinja2 >= 2.4']
+import pkg_resources
+
+import logging
+import unittest
+import sys
+import os
+
+from datetime import time
+from datetime import timedelta
+
+import flask
+
+sys.path.insert(0, os.path.join(os.path.dirname(
+ os.path.abspath(__file__)), '..'))
+
+import fedora_elections
+from tests import ModelFlasktests, Modeltests, TODAY, FakeUser, user_set
+
+
+# pylint: disable=R0904
+class FlaskIrcElectionstests(ModelFlasktests):
+ """ Flask application tests irc voting. """
+
+ def test_vote_for_abstain_against(self):
+ """ Test the vote_for_abstain_against function - the preview part.
"""
+ output = self.app.get(
+ '/vote/test_election', follow_redirects=True)
+ self.assertEqual(output.status_code, 200)
+ self.assertTrue(
+ '<title>OpenID transaction in progress</title>' in
output.data
+ or 'discoveryfailure' in output.data)
+
+ self.setup_db()
+
+ user = FakeUser(['packager'], username='toshio')
+ with user_set(fedora_elections.APP, user):
+ output = self.app.get(
+ '/vote/test_election7', follow_redirects=True)
+ self.assertTrue(
+ 'class="message">You have already voted in the
election!</'
+ in output.data)
+
+ user = FakeUser(['packager'], username='nerdsville')
+ with user_set(fedora_elections.APP, user):
+ output = self.app.get(
+ '/vote/test_election7')
+ self.assertTrue(
+ '<h2>test election 7 shortdesc</h2>' in output.data)
+ self.assertTrue(
+ '<input type="hidden" name="action"
value="preview" />'
+ in output.data)
+
+ csrf_token = output.data.split(
+ 'name="csrf_token" type="hidden"
value="')[1].split('">')[0]
+
+ # Invalid vote: No candidate
+ data = {
+ 'action': 'preview',
+ }
+
+ output = self.app.post('/vote/test_election7', data=data)
+ self.assertEqual(output.status_code, 200)
+ self.assertTrue(
+ '<h2>test election 7 shortdesc</h2>' in output.data)
+
+ # Valid input
+ data = {
+ 'Kevin': -1,
+ 'Toshio': '0',
+ 'action': 'preview',
+ 'csrf_token': csrf_token,
+ }
+
+ output = self.app.post('/vote/test_election7', data=data)
+ self.assertEqual(output.status_code, 200)
+ self.assertTrue(
+ '<h2>test election 7 shortdesc</h2>' in output.data)
+ self.assertTrue(
+ '<input type="hidden" name="action"
value="submit" />'
+ in output.data)
+ self.assertTrue(
+ '<li class="message">Please confirm your
vote!</li>'
+ in output.data)
+
+ def test_vote_for_abstain_against_process(self):
+ """ Test the vote_for_abstain_against function - the voting part.
"""
+ output = self.app.get(
+ '/vote/test_election', follow_redirects=True)
+ self.assertEqual(output.status_code, 200)
+ self.assertTrue(
+ '<title>OpenID transaction in progress</title>' in
output.data
+ or 'discoveryfailure' in output.data)
+
+ self.setup_db()
+
+ user = FakeUser(['packager'], username='pingou')
+ with user_set(fedora_elections.APP, user):
+ # Invalid candidate id - no csrf
+ data = {
+ 'candidate': 1,
+ 'action': 'submit',
+ }
+
+ output = self.app.post(
+ '/vote/test_election7', data=data,
+ follow_redirects=True)
+ self.assertEqual(output.status_code, 200)
+
+ csrf_token = output.data.split(
+ 'name="csrf_token" type="hidden"
value="')[1].split('">')[0]
+
+ # Valid input
+ data = {
+ 'Toshio': '0',
+ 'Kevin': '1',
+ 'action': 'submit',
+ 'csrf_token': csrf_token,
+ }
+
+ output = self.app.post(
+ '/vote/test_election7', data=data,
+ follow_redirects=True)
+ 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)
+
+
+if __name__ == '__main__':
+ SUITE = unittest.TestLoader().loadTestsFromTestCase(FlaskIrcElectionstests)
+ unittest.TextTestRunner(verbosity=2).run(SUITE)