| |
@@ -32,6 +32,7 @@
|
| |
from datetime import timedelta
|
| |
|
| |
import flask
|
| |
+ from mock import patch, MagicMock
|
| |
|
| |
sys.path.insert(0, os.path.join(os.path.dirname(
|
| |
os.path.abspath(__file__)), '..'))
|
| |
@@ -49,16 +50,39 @@
|
| |
user = FakeUser(
|
| |
fedora_elections.APP.config['FEDORA_ELECTIONS_ADMIN_GROUP'],
|
| |
username='toshio')
|
| |
- with user_set(fedora_elections.APP, user):
|
| |
- output = self.app.get('/admin/election_test/')
|
| |
- self.assertEqual(output.status_code, 404)
|
| |
|
| |
+ with user_set(fedora_elections.APP, user, oidc_id_token='foobar'):
|
| |
+ with patch(
|
| |
+ 'fedora_elections.OIDC.user_getfield',
|
| |
+ MagicMock(return_value=['elections'])):
|
| |
+ output = self.app.get('/admin/election_test/')
|
| |
+ self.assertEqual(output.status_code, 404)
|
| |
+
|
| |
+ self.setup_db()
|
| |
+
|
| |
+ with user_set(fedora_elections.APP, user, oidc_id_token='foobar'):
|
| |
+ with patch(
|
| |
+ 'fedora_elections.OIDC.user_getfield',
|
| |
+ MagicMock(return_value=['elections'])):
|
| |
+ output = self.app.get('/admin/test_election/')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue('Candidates <span class="label label-pill label-default">3</span>' in output.data)
|
| |
+
|
| |
+ def test_admin_no_cla(self):
|
| |
+ """ Test the admin_new_election function. """
|
| |
self.setup_db()
|
| |
|
| |
- with user_set(fedora_elections.APP, user):
|
| |
- output = self.app.get('/admin/test_election/')
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue('Candidates <span class="label label-pill label-default">3</span>' in output.data)
|
| |
+ user = FakeUser(
|
| |
+ fedora_elections.APP.config['FEDORA_ELECTIONS_ADMIN_GROUP'],
|
| |
+ username='toshio')
|
| |
+
|
| |
+ user.cla_done = False
|
| |
+ with user_set(fedora_elections.APP, user, oidc_id_token='foobar'):
|
| |
+ with patch(
|
| |
+ 'fedora_elections.OIDC.user_getfield',
|
| |
+ MagicMock(return_value=['elections'])):
|
| |
+ output = self.app.get('/admin/new')
|
| |
+ self.assertEqual(output.status_code, 403)
|
| |
|
| |
def test_admin_new_election(self):
|
| |
""" Test the admin_new_election function. """
|
| |
@@ -67,410 +91,421 @@
|
| |
user = FakeUser(
|
| |
fedora_elections.APP.config['FEDORA_ELECTIONS_ADMIN_GROUP'],
|
| |
username='toshio')
|
| |
- with user_set(fedora_elections.APP, user):
|
| |
- output = self.app.get('/admin/new')
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- '<h2>Create new election</h2>' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
-
|
| |
- # No csrf provided
|
| |
- data = {
|
| |
- 'alias': 'new_election',
|
| |
- 'shortdesc': 'new election shortdesc',
|
| |
- 'description': 'new election description',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY + timedelta(days=2),
|
| |
- 'end_date': TODAY + timedelta(days=4),
|
| |
- 'seats_elected': '2',
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': True,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post('/admin/new', data=data)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- '<h2>Create new election</h2>' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
-
|
| |
- csrf_token = self.get_csrf(output=output)
|
| |
-
|
| |
- # Description missing
|
| |
- data = {
|
| |
- 'alias': 'new_election',
|
| |
- 'shortdesc': 'new election shortdesc',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY + timedelta(days=2),
|
| |
- 'end_date': TODAY + timedelta(days=4),
|
| |
- 'seats_elected': '2',
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': True,
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post('/admin/new', data=data)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- '<h2>Create new election</h2>' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
- self.assertTrue(
|
| |
- '<div class="form-control-feedback">This field is required.</div>'
|
| |
- in output.data)
|
| |
-
|
| |
- # Invalid alias
|
| |
- data = {
|
| |
- 'alias': 'new',
|
| |
- 'shortdesc': 'new election shortdesc',
|
| |
- 'description': 'new election description',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY + timedelta(days=2),
|
| |
- 'end_date': TODAY + timedelta(days=4),
|
| |
- 'seats_elected': 2,
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': True,
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post('/admin/new', data=data)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- '<h2>Create new election</h2>' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
- self.assertTrue(
|
| |
- '<div class="form-control-feedback">The alias cannot be <code>new</code>.</div>'
|
| |
- in output.data)
|
| |
-
|
| |
- # Invalid: end_date earlier than start_date
|
| |
- data = {
|
| |
- 'alias': 'new_election',
|
| |
- 'shortdesc': 'new election shortdesc',
|
| |
- 'description': 'new election description',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY + timedelta(days=6),
|
| |
- 'end_date': TODAY + timedelta(days=4),
|
| |
- 'seats_elected': 2,
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': True,
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post('/admin/new', data=data)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- '<h2>Create new election</h2>' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
+
|
| |
+ with user_set(fedora_elections.APP, user, oidc_id_token='foobar'):
|
| |
+ with patch(
|
| |
+ 'fedora_elections.OIDC.user_getfield',
|
| |
+ MagicMock(return_value=['elections'])):
|
| |
+ output = self.app.get('/admin/new')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ '<h2>Create new election</h2>' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
+
|
| |
+ # No csrf provided
|
| |
+ data = {
|
| |
+ 'alias': 'new_election',
|
| |
+ 'shortdesc': 'new election shortdesc',
|
| |
+ 'description': 'new election description',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY + timedelta(days=2),
|
| |
+ 'end_date': TODAY + timedelta(days=4),
|
| |
+ 'seats_elected': '2',
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': True,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post('/admin/new', data=data)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ '<h2>Create new election</h2>' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
+
|
| |
+ csrf_token = self.get_csrf(output=output)
|
| |
+
|
| |
+ # Description missing
|
| |
+ data = {
|
| |
+ 'alias': 'new_election',
|
| |
+ 'shortdesc': 'new election shortdesc',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY + timedelta(days=2),
|
| |
+ 'end_date': TODAY + timedelta(days=4),
|
| |
+ 'seats_elected': '2',
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': True,
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post('/admin/new', data=data)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ '<h2>Create new election</h2>' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
+ self.assertTrue(
|
| |
+ '<div class="form-control-feedback">This field is required.</div>'
|
| |
+ in output.data)
|
| |
+
|
| |
+ # Invalid alias
|
| |
+ data = {
|
| |
+ 'alias': 'new',
|
| |
+ 'shortdesc': 'new election shortdesc',
|
| |
+ 'description': 'new election description',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY + timedelta(days=2),
|
| |
+ 'end_date': TODAY + timedelta(days=4),
|
| |
+ 'seats_elected': 2,
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': True,
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post('/admin/new', data=data)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ '<h2>Create new election</h2>' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
+ self.assertTrue(
|
| |
+ '<div class="form-control-feedback">The alias cannot be <code>new</code>.</div>'
|
| |
+ in output.data)
|
| |
+
|
| |
+ # Invalid: end_date earlier than start_date
|
| |
+ data = {
|
| |
+ 'alias': 'new_election',
|
| |
+ 'shortdesc': 'new election shortdesc',
|
| |
+ 'description': 'new election description',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY + timedelta(days=6),
|
| |
+ 'end_date': TODAY + timedelta(days=4),
|
| |
+ 'seats_elected': 2,
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': True,
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post('/admin/new', data=data)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ '<h2>Create new election</h2>' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
+ self.assertTrue(
|
| |
+ 'class="form-control-feedback">End date must be later than start date.</div>'
|
| |
+ in output.data)
|
| |
+
|
| |
+ # Invalid: alias already taken
|
| |
+ data = {
|
| |
+ 'alias': 'test_election',
|
| |
+ 'shortdesc': 'new election shortdesc',
|
| |
+ 'description': 'new election description',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY + timedelta(days=6),
|
| |
+ 'end_date': TODAY + timedelta(days=4),
|
| |
+ 'seats_elected': 2,
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': True,
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post('/admin/new', data=data)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ '<h2>Create new election</h2>' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
+ self.assertTrue(
|
| |
+ '<div class="form-control-feedback">There is already another election with '
|
| |
+ 'this alias.</div>' in output.data)
|
| |
+
|
| |
+ # Invalid: shortdesc already taken
|
| |
+ data = {
|
| |
+ 'alias': 'new_election',
|
| |
+ 'shortdesc': 'test election shortdesc',
|
| |
+ 'description': 'new election description',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY + timedelta(days=6),
|
| |
+ 'end_date': TODAY + timedelta(days=4),
|
| |
+ 'seats_elected': 2,
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': True,
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post('/admin/new', data=data)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ '<h2>Create new election</h2>' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
+ self.assertTrue(
|
| |
+ '<div class="form-control-feedback">There is already another election with '
|
| |
+ 'this summary.</div>' in output.data)
|
| |
+
|
| |
+ # All good - max_votes is ignored as it is not a integer
|
| |
+ data = {
|
| |
+ 'alias': 'new_election',
|
| |
+ 'shortdesc': 'new election shortdesc',
|
| |
+ 'description': 'new election description',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY + timedelta(days=2),
|
| |
+ 'end_date': TODAY + timedelta(days=4),
|
| |
+ 'seats_elected': 2,
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': True,
|
| |
+ 'admin_grp': 'testers, sysadmin-main,,',
|
| |
+ 'lgl_voters': 'testers, packager,,',
|
| |
+ 'max_votes': 'wrong',
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post(
|
| |
+ '/admin/new', data=data, follow_redirects=True)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ 'Election "new_election" added'
|
| |
+ in output.data)
|
| |
+ self.assertTrue(
|
| |
+ 'There are no candidates.' in output.data)
|
| |
self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
+ 'input class="form-control" id="admin_grp" '
|
| |
+ 'name="admin_grp" type="text" '
|
| |
+ 'value="sysadmin-main, testers">', output.data)
|
| |
self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
- self.assertTrue(
|
| |
- 'class="form-control-feedback">End date must be later than start date.</div>'
|
| |
- in output.data)
|
| |
-
|
| |
- # Invalid: alias already taken
|
| |
- data = {
|
| |
- 'alias': 'test_election',
|
| |
- 'shortdesc': 'new election shortdesc',
|
| |
- 'description': 'new election description',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY + timedelta(days=6),
|
| |
- 'end_date': TODAY + timedelta(days=4),
|
| |
- 'seats_elected': 2,
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': True,
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post('/admin/new', data=data)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- '<h2>Create new election</h2>' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
+ 'input class="form-control" id="lgl_voters" '
|
| |
+ 'name="lgl_voters" type="text" '
|
| |
+ 'value="packager, testers">', output.data)
|
| |
self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
+ 'input class="form-control" id="max_votes" '
|
| |
+ 'name="max_votes" type="text" '
|
| |
+ 'value="">', output.data)
|
| |
+
|
| |
+ # All good - max_votes is ignored as it is not a integer
|
| |
+ data = {
|
| |
+ 'alias': 'new_election2',
|
| |
+ 'shortdesc': 'new election2 shortdesc',
|
| |
+ 'description': 'new election2 description',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY + timedelta(days=2),
|
| |
+ 'end_date': TODAY + timedelta(days=4),
|
| |
+ 'seats_elected': 2,
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': True,
|
| |
+ 'admin_grp': 'testers, , sysadmin-main,,',
|
| |
+ 'lgl_voters': 'testers, packager,,,',
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post(
|
| |
+ '/admin/new', data=data, follow_redirects=True)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ 'Election "new_election2" added'
|
| |
+ in output.data)
|
| |
+ self.assertTrue(
|
| |
+ 'There are no candidates.' in output.data)
|
| |
self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
- self.assertTrue(
|
| |
- '<div class="form-control-feedback">There is already another election with '
|
| |
- 'this alias.</div>' in output.data)
|
| |
-
|
| |
- # Invalid: shortdesc already taken
|
| |
- data = {
|
| |
- 'alias': 'new_election',
|
| |
- 'shortdesc': 'test election shortdesc',
|
| |
- 'description': 'new election description',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY + timedelta(days=6),
|
| |
- 'end_date': TODAY + timedelta(days=4),
|
| |
- 'seats_elected': 2,
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': True,
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post('/admin/new', data=data)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- '<h2>Create new election</h2>' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
+ 'input class="form-control" id="admin_grp" '
|
| |
+ 'name="admin_grp" type="text" '
|
| |
+ 'value="sysadmin-main, testers">', output.data)
|
| |
self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
+ 'input class="form-control" id="lgl_voters" '
|
| |
+ 'name="lgl_voters" type="text" '
|
| |
+ 'value="packager, testers">', output.data)
|
| |
self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
- self.assertTrue(
|
| |
- '<div class="form-control-feedback">There is already another election with '
|
| |
- 'this summary.</div>' in output.data)
|
| |
-
|
| |
- # All good - max_votes is ignored as it is not a integer
|
| |
- data = {
|
| |
- 'alias': 'new_election',
|
| |
- 'shortdesc': 'new election shortdesc',
|
| |
- 'description': 'new election description',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY + timedelta(days=2),
|
| |
- 'end_date': TODAY + timedelta(days=4),
|
| |
- 'seats_elected': 2,
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': True,
|
| |
- 'admin_grp': 'testers, sysadmin-main,,',
|
| |
- 'lgl_voters': 'testers, packager,,',
|
| |
- 'max_votes': 'wrong',
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post(
|
| |
- '/admin/new', data=data, follow_redirects=True)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- 'Election "new_election" added'
|
| |
- in output.data)
|
| |
- self.assertTrue(
|
| |
- 'There are no candidates.' in output.data)
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="admin_grp" '
|
| |
- 'name="admin_grp" type="text" '
|
| |
- 'value="sysadmin-main, testers">', output.data)
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="lgl_voters" '
|
| |
- 'name="lgl_voters" type="text" '
|
| |
- 'value="packager, testers">', output.data)
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="max_votes" '
|
| |
- 'name="max_votes" type="text" '
|
| |
- 'value="">', output.data)
|
| |
-
|
| |
- # All good - max_votes is ignored as it is not a integer
|
| |
- data = {
|
| |
- 'alias': 'new_election2',
|
| |
- 'shortdesc': 'new election2 shortdesc',
|
| |
- 'description': 'new election2 description',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY + timedelta(days=2),
|
| |
- 'end_date': TODAY + timedelta(days=4),
|
| |
- 'seats_elected': 2,
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': True,
|
| |
- 'admin_grp': 'testers, , sysadmin-main,,',
|
| |
- 'lgl_voters': 'testers, packager,,,',
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post(
|
| |
- '/admin/new', data=data, follow_redirects=True)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- 'Election "new_election2" added'
|
| |
- in output.data)
|
| |
- self.assertTrue(
|
| |
- 'There are no candidates.' in output.data)
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="admin_grp" '
|
| |
- 'name="admin_grp" type="text" '
|
| |
- 'value="sysadmin-main, testers">', output.data)
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="lgl_voters" '
|
| |
- 'name="lgl_voters" type="text" '
|
| |
- 'value="packager, testers">', output.data)
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="max_votes" '
|
| |
- 'name="max_votes" type="text" '
|
| |
- 'value="">', output.data)
|
| |
+ 'input class="form-control" id="max_votes" '
|
| |
+ 'name="max_votes" type="text" '
|
| |
+ 'value="">', output.data)
|
| |
|
| |
def test_admin_edit_election(self):
|
| |
""" Test the admin_edit_election function. """
|
| |
user = FakeUser(
|
| |
fedora_elections.APP.config['FEDORA_ELECTIONS_ADMIN_GROUP'],
|
| |
username='toshio')
|
| |
- with user_set(fedora_elections.APP, user):
|
| |
- output = self.app.get('/admin/test_election/')
|
| |
- self.assertEqual(output.status_code, 404)
|
| |
+
|
| |
+ with user_set(fedora_elections.APP, user, oidc_id_token='foobar'):
|
| |
+ with patch(
|
| |
+ 'fedora_elections.OIDC.user_getfield',
|
| |
+ MagicMock(return_value=['elections'])):
|
| |
+ output = self.app.get('/admin/test_election/')
|
| |
+ self.assertEqual(output.status_code, 404)
|
| |
|
| |
self.setup_db()
|
| |
|
| |
- with user_set(fedora_elections.APP, user):
|
| |
- output = self.app.get('/admin/test_election/')
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- 'Election Details' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
+ with user_set(fedora_elections.APP, user, oidc_id_token='foobar'):
|
| |
+ with patch(
|
| |
+ 'fedora_elections.OIDC.user_getfield',
|
| |
+ MagicMock(return_value=['elections'])):
|
| |
+ output = self.app.get('/admin/test_election/')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ 'Election Details' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
+
|
| |
+ data = {
|
| |
+ 'alias': 'test_election',
|
| |
+ 'shortdesc': 'test election shortdesc',
|
| |
+ 'description': 'test election description',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY - timedelta(days=10),
|
| |
+ 'end_date': TODAY - timedelta(days=8),
|
| |
+ 'seats_elected': '2',
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': False,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post('/admin/test_election/', data=data)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ 'Election Details' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
+
|
| |
+ csrf_token = self.get_csrf()
|
| |
+
|
| |
+ data = {
|
| |
+ 'alias': 'test_election',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY - timedelta(days=10),
|
| |
+ 'end_date': TODAY - timedelta(days=8),
|
| |
+ 'seats_elected': '2',
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': False,
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post(
|
| |
+ '/admin/test_election/', data=data)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ 'Election Details' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" required type="text" ', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="shortdesc" '
|
| |
+ 'name="shortdesc" type="text" ', output.data)
|
| |
self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
-
|
| |
- data = {
|
| |
- 'alias': 'test_election',
|
| |
- 'shortdesc': 'test election shortdesc',
|
| |
- 'description': 'test election description',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY - timedelta(days=10),
|
| |
- 'end_date': TODAY - timedelta(days=8),
|
| |
- 'seats_elected': '2',
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': False,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post('/admin/test_election/', data=data)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- 'Election Details' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
-
|
| |
- csrf_token = self.get_csrf()
|
| |
-
|
| |
- data = {
|
| |
- 'alias': 'test_election',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY - timedelta(days=10),
|
| |
- 'end_date': TODAY - timedelta(days=8),
|
| |
- 'seats_elected': '2',
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': False,
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post(
|
| |
- '/admin/test_election/', data=data)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- 'Election Details' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" required type="text" ', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="shortdesc" '
|
| |
- 'name="shortdesc" type="text" ', output.data)
|
| |
- self.assertIn(
|
| |
- '<div class="form-control-feedback">This field is required.</div>',
|
| |
- output.data)
|
| |
-
|
| |
- # Check election before edit
|
| |
- output = self.app.get('/admin/test_election/')
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue('Candidates <span class="label label-pill label-default">3</span>' in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" required type="text" '
|
| |
- 'value="1">', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" type="text" '
|
| |
- 'value="1">', output.data)
|
| |
-
|
| |
- data = {
|
| |
- 'alias': 'test_election',
|
| |
- 'shortdesc': 'test election shortdesc',
|
| |
- 'description': 'test election description',
|
| |
- 'voting_type': 'simple',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY - timedelta(days=10),
|
| |
- 'end_date': TODAY - timedelta(days=8),
|
| |
- 'seats_elected': '2',
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': False,
|
| |
- 'max_votes': 'wrong',
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post(
|
| |
- '/admin/test_election/', data=data, follow_redirects=True)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- 'Election "test_election" saved'
|
| |
- in output.data)
|
| |
- # We edited the seats_elected from 1 to 2
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" required type="text" '
|
| |
- 'value="2">', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" type="text" '
|
| |
- 'value="2">', output.data)
|
| |
- self.assertTrue('Candidates <span class="label label-pill label-default">3</span>' in output.data)
|
| |
+ '<div class="form-control-feedback">This field is required.</div>',
|
| |
+ output.data)
|
| |
+
|
| |
+ # Check election before edit
|
| |
+ output = self.app.get('/admin/test_election/')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue('Candidates <span class="label label-pill label-default">3</span>' in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" required type="text" '
|
| |
+ 'value="1">', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" type="text" '
|
| |
+ 'value="1">', output.data)
|
| |
+
|
| |
+ data = {
|
| |
+ 'alias': 'test_election',
|
| |
+ 'shortdesc': 'test election shortdesc',
|
| |
+ 'description': 'test election description',
|
| |
+ 'voting_type': 'simple',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY - timedelta(days=10),
|
| |
+ 'end_date': TODAY - timedelta(days=8),
|
| |
+ 'seats_elected': '2',
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': False,
|
| |
+ 'max_votes': 'wrong',
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post(
|
| |
+ '/admin/test_election/', data=data, follow_redirects=True)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ 'Election "test_election" saved'
|
| |
+ in output.data)
|
| |
+ # We edited the seats_elected from 1 to 2
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" required type="text" '
|
| |
+ 'value="2">', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" type="text" '
|
| |
+ 'value="2">', output.data)
|
| |
+ self.assertTrue('Candidates <span class="label label-pill label-default">3</span>' in output.data)
|
| |
|
| |
def test_admin_edit_election_admin_groups(self):
|
| |
""" Test the admin_edit_election function when editing admin groups.
|
| |
@@ -478,109 +513,116 @@
|
| |
user = FakeUser(
|
| |
fedora_elections.APP.config['FEDORA_ELECTIONS_ADMIN_GROUP'],
|
| |
username='toshio')
|
| |
- with user_set(fedora_elections.APP, user):
|
| |
- output = self.app.get('/admin/test_election/edit')
|
| |
- self.assertEqual(output.status_code, 404)
|
| |
-
|
| |
- self.setup_db()
|
| |
|
| |
- with user_set(fedora_elections.APP, user):
|
| |
- output = self.app.get('/admin/test_election2/')
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- csrf_token = self.get_csrf(output=output)
|
| |
+ with user_set(fedora_elections.APP, user, oidc_id_token='foobar'):
|
| |
+ with patch(
|
| |
+ 'fedora_elections.OIDC.user_getfield',
|
| |
+ MagicMock(return_value=['elections'])):
|
| |
+ output = self.app.get('/admin/test_election/edit')
|
| |
+ self.assertEqual(output.status_code, 404)
|
| |
|
| |
- # Edit Admin Group
|
| |
+ self.setup_db()
|
| |
|
| |
- # Check election before edit
|
| |
- output = self.app.get('/admin/test_election2/')
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" required type="text" '
|
| |
- 'value="1">', output.data)
|
| |
- else:
|
| |
+ with user_set(fedora_elections.APP, user, oidc_id_token='foobar'):
|
| |
+ with patch(
|
| |
+ 'fedora_elections.OIDC.user_getfield',
|
| |
+ MagicMock(return_value=['elections'])):
|
| |
+ output = self.app.get('/admin/test_election2/')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ csrf_token = self.get_csrf(output=output)
|
| |
+
|
| |
+ # Edit Admin Group
|
| |
+
|
| |
+ # Check election before edit
|
| |
+ output = self.app.get('/admin/test_election2/')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" required type="text" '
|
| |
+ 'value="1">', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" type="text" '
|
| |
+ 'value="1">', output.data)
|
| |
+ self.assertTrue('Candidates <span class="label' in output.data)
|
| |
+
|
| |
+ # Add a new admin group: sysadmin-main
|
| |
+ data = {
|
| |
+ 'alias': 'test_election2',
|
| |
+ 'shortdesc': 'test election 2 shortdesc',
|
| |
+ 'description': 'test election 2 description',
|
| |
+ 'voting_type': 'range',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY - timedelta(days=7),
|
| |
+ 'end_date': TODAY - timedelta(days=5),
|
| |
+ 'seats_elected': '2',
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': False,
|
| |
+ 'admin_grp': 'testers, sysadmin-main',
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post(
|
| |
+ '/admin/test_election2/', data=data, follow_redirects=True)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ 'Election "test_election2" saved'
|
| |
+ in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" required type="text" '
|
| |
+ 'value="2">', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" type="text" '
|
| |
+ 'value="2">', output.data)
|
| |
+ # We edited the admin groups
|
| |
self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" type="text" '
|
| |
- 'value="1">', output.data)
|
| |
- self.assertTrue('Candidates <span class="label' in output.data)
|
| |
-
|
| |
- # Add a new admin group: sysadmin-main
|
| |
- data = {
|
| |
- 'alias': 'test_election2',
|
| |
- 'shortdesc': 'test election 2 shortdesc',
|
| |
- 'description': 'test election 2 description',
|
| |
- 'voting_type': 'range',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY - timedelta(days=7),
|
| |
- 'end_date': TODAY - timedelta(days=5),
|
| |
- 'seats_elected': '2',
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': False,
|
| |
- 'admin_grp': 'testers, sysadmin-main',
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post(
|
| |
- '/admin/test_election2/', data=data, follow_redirects=True)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- 'Election "test_election2" saved'
|
| |
- in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
+ 'input class="form-control" id="admin_grp" '
|
| |
+ 'name="admin_grp" type="text" '
|
| |
+ 'value="sysadmin-main, testers">', output.data)
|
| |
+
|
| |
+ # Remove an existing group: testers
|
| |
+ data = {
|
| |
+ 'alias': 'test_election2',
|
| |
+ 'shortdesc': 'test election 2 shortdesc',
|
| |
+ 'description': 'test election 2 description',
|
| |
+ 'voting_type': 'range',
|
| |
+ 'url': 'https://fedoraproject.org',
|
| |
+ 'start_date': TODAY - timedelta(days=7),
|
| |
+ 'end_date': TODAY - timedelta(days=5),
|
| |
+ 'seats_elected': '2',
|
| |
+ 'candidates_are_fasusers': False,
|
| |
+ 'embargoed': False,
|
| |
+ 'admin_grp': 'sysadmin-main',
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ }
|
| |
+
|
| |
+ output = self.app.post(
|
| |
+ '/admin/test_election2/', data=data, follow_redirects=True)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ self.assertTrue(
|
| |
+ 'Election "test_election2" saved'
|
| |
+ in output.data)
|
| |
+ if self.get_wtforms_version() >= (2, 2):
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" required type="text" '
|
| |
+ 'value="2">', output.data)
|
| |
+ else:
|
| |
+ self.assertIn(
|
| |
+ 'input class="form-control" id="seats_elected" '
|
| |
+ 'name="seats_elected" type="text" '
|
| |
+ 'value="2">', output.data)
|
| |
+ # We edited the admin groups
|
| |
self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" required type="text" '
|
| |
- 'value="2">', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" type="text" '
|
| |
- 'value="2">', output.data)
|
| |
- # We edited the admin groups
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="admin_grp" '
|
| |
- 'name="admin_grp" type="text" '
|
| |
- 'value="sysadmin-main, testers">', output.data)
|
| |
-
|
| |
- # Remove an existing group: testers
|
| |
- data = {
|
| |
- 'alias': 'test_election2',
|
| |
- 'shortdesc': 'test election 2 shortdesc',
|
| |
- 'description': 'test election 2 description',
|
| |
- 'voting_type': 'range',
|
| |
- 'url': 'https://fedoraproject.org',
|
| |
- 'start_date': TODAY - timedelta(days=7),
|
| |
- 'end_date': TODAY - timedelta(days=5),
|
| |
- 'seats_elected': '2',
|
| |
- 'candidates_are_fasusers': False,
|
| |
- 'embargoed': False,
|
| |
- 'admin_grp': 'sysadmin-main',
|
| |
- 'csrf_token': csrf_token,
|
| |
- }
|
| |
-
|
| |
- output = self.app.post(
|
| |
- '/admin/test_election2/', data=data, follow_redirects=True)
|
| |
- self.assertEqual(output.status_code, 200)
|
| |
- self.assertTrue(
|
| |
- 'Election "test_election2" saved'
|
| |
- in output.data)
|
| |
- if self.get_wtforms_version() >= (2, 2):
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" required type="text" '
|
| |
- 'value="2">', output.data)
|
| |
- else:
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="seats_elected" '
|
| |
- 'name="seats_elected" type="text" '
|
| |
- 'value="2">', output.data)
|
| |
- # We edited the admin groups
|
| |
- self.assertIn(
|
| |
- 'input class="form-control" id="admin_grp" '
|
| |
- 'name="admin_grp" type="text" '
|
| |
- 'value="sysadmin-main">', output.data)
|
| |
+ 'input class="form-control" id="admin_grp" '
|
| |
+ 'name="admin_grp" type="text" '
|
| |
+ 'value="sysadmin-main">', output.data)
|
| |
|
| |
def test_admin_edit_election_legal_voters(self):
|
| |
""" Test the admin_edit_election function when editing legal voters.
|
| |
@@ -588,256 +630,275 @@
|
| |
user = FakeUser(
|
| |
fedora_elections.APP.config['FEDORA_ELECTIONS_ADMIN_GROUP'],
|
| |
username='toshio')
|
| |
- with user_set(fedora_elections.APP, user):
|
| |
- output = self.app.get('/admin/test_election/edit')
|
| |
Why the change in the port?