forked from benadida/helios-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,14 +395,32 @@ def setUp(self): | |
self.election = models.Election.objects.all()[0] | ||
self.user = auth_models.User.objects.get(user_id='[email protected]', user_type='google') | ||
|
||
def assertContains(self, response, text): | ||
if hasattr(response, 'status_code'): | ||
assert response.status_code == 200 | ||
# return super(django_webtest.WebTest, self).assertContains(response, text) | ||
else: | ||
assert response.status_int == 200 | ||
|
||
|
||
if hasattr(response, "testbody"): | ||
assert text in response.testbody, "missing text %s" % text | ||
else: | ||
if hasattr(response, "body"): | ||
assert text in response.body, "missing text %s" % text | ||
else: | ||
assert text in response.content, "missing text %s" % text | ||
|
||
def setup_login(self): | ||
# set up the session | ||
session = self.client.session | ||
session['user'] = {'type': self.user.user_type, 'user_id': self.user.user_id} | ||
session.save() | ||
|
||
# set up the app, too | ||
self.app.cookies['sessionid'] = self.client.cookies.get('sessionid').value | ||
# this does not appear to work, boohoo | ||
session = self.app.session | ||
session['user'] = {'type': self.user.user_type, 'user_id': self.user.user_id} | ||
|
||
def clear_login(self): | ||
session = self.client.session | ||
|
@@ -732,7 +750,7 @@ def test_election_voters_eligibility(self): | |
# create the election | ||
self.client.get("/") | ||
self.setup_login() | ||
response = self.app.post("/helios/elections/new", { | ||
response = self.client.post("/helios/elections/new", { | ||
"short_name" : "test-eligibility", | ||
"name" : "Test Eligibility", | ||
"description" : "An election test for voter eligibility", | ||
|
@@ -741,22 +759,25 @@ def test_election_voters_eligibility(self): | |
"use_advanced_audit_features": "1", | ||
"private_p" : "0"}) | ||
|
||
election_id = re.match("(.*)/elections/(.*)/view", response.location).group(2) | ||
election_id = re.match("(.*)/elections/(.*)/view", response['Location']).group(2) | ||
|
||
# get the eligibility page | ||
eligibility_page = self.app.get("/helios/elections/%s/voters/list" % election_id) | ||
|
||
elig_form = eligibility_page.form | ||
elig_form['eligibility'] = 'openreg' | ||
elig_page = elig_form.submit().follow() | ||
# update eligiblity | ||
response = self.client.post("/helios/elections/%s/voters/eligibility" % election_id, { | ||
"csrf_token" : self.client.session['csrf_token'], | ||
"eligibility": "openreg"}) | ||
|
||
self.assertContains(elig_page, "Anyone can vote") | ||
self.clear_login() | ||
response = self.client.get("/helios/elections/%s/voters/list" % election_id) | ||
self.assertContains(response, "Anyone can vote") | ||
|
||
elig_form = elig_page.form | ||
elig_form['eligibility'] = 'closedreg' | ||
elig_page = elig_form.submit().follow() | ||
self.setup_login() | ||
response = self.client.post("/helios/elections/%s/voters/eligibility" % election_id, { | ||
"csrf_token" : self.client.session['csrf_token'], | ||
"eligibility": "closedreg"}) | ||
|
||
self.assertContains(elig_page, "Only the voters listed here") | ||
self.clear_login() | ||
response = self.client.get("/helios/elections/%s/voters/list" % election_id) | ||
self.assertContains(response, "Only the voters listed here") | ||
|
||
def test_do_complete_election_with_trustees(self): | ||
""" | ||
|