Skip to content

Commit

Permalink
fixed all but one tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benadida committed Aug 22, 2013
1 parent f276637 commit 5bbd7d5
Showing 1 changed file with 36 additions and 15 deletions.
51 changes: 36 additions & 15 deletions helios/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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):
"""
Expand Down

0 comments on commit 5bbd7d5

Please sign in to comment.