Skip to content
Snippets Groups Projects
Commit f1b46067 authored by Ben Adida's avatar Ben Adida
Browse files

fixed tests for python 2.7, will need to check python 2.6

parent 248698b6
Branches
Tags
No related merge requests found
......@@ -2,7 +2,7 @@
Unit Tests for Helios
"""
import unittest, datetime, re
import unittest, datetime, re, urllib
import django_webtest
import models
......@@ -346,19 +346,40 @@ class WebTest(django_webtest.WebTest):
def assertRedirects(self, response, url):
"""
reimplement this in case it's a WebOp response
and it seems to be screwing up in a few places too
thus the localhost exception
"""
if hasattr(response, 'status_code'):
return super(django_webtest.WebTest, self).assertRedirects(response, url)
if hasattr(response, 'location'):
assert url in response.location
else:
assert url in response._headers['location'][1]
self.assertEqual(response.status_code, 302)
#return super(django_webtest.WebTest, self).assertRedirects(response, url)
#if hasattr(response, 'status_code') and hasattr(response, 'location'):
assert response.status_int == 302
assert url in response.location, "redirected to %s instead of %s" % (response.location, url)
#if hasattr(response, 'status_code'):
# assert response.status_code == 302
#else:
# assert response.status_int == 302
#assert url in response.location, "redirected to %s instead of %s" % (response.location, url)
def assertContains(self, response, text):
if hasattr(response, 'status_code'):
return super(django_webtest.WebTest, self).assertContains(response, text)
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
##
......@@ -567,7 +588,10 @@ class ElectionBlackboxTests(WebTest):
# vote by preparing a ballot via the server-side encryption
response = self.app.post("/helios/elections/%s/encrypt-ballot" % election_id, {
'answers_json': utils.to_json([[1]])})
try:
self.assertContains(response, "answers")
except:
import pdb; pdb.set_trace()
# parse it as an encrypted vote with randomness, and make sure randomness is there
the_ballot = utils.from_json(response.testbody)
......@@ -692,7 +716,7 @@ class ElectionBlackboxTests(WebTest):
response = self.app.get("/helios/elections/%s/view" % election_id)
# ensure it redirects
self.assertRedirects(response, "/helios/elections/%s/password_voter_login" % election_id)
self.assertRedirects(response, "/helios/elections/%s/password_voter_login?%s" % (election_id, urllib.urlencode({"return_url": "/helios/elections/%s/view" % election_id})))
login_form = response.follow().form
......
......@@ -186,3 +186,6 @@ import djcelery
djcelery.setup_loader()
BROKER_BACKEND = "djkombu.transport.DatabaseTransport"
CELERY_RESULT_DBURI = DATABASES['default']
# for testing
CELERY_ALWAYS_EAGER = True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment