Skip to content
Snippets Groups Projects
Unverified Commit 69ec942a authored by Marco Ciotola's avatar Marco Ciotola
Browse files

[tests] Extend setup_login capabilities

parent 1df36cdf
Branches
No related tags found
No related merge requests found
...@@ -393,10 +393,17 @@ class ElectionBlackboxTests(WebTest): ...@@ -393,10 +393,17 @@ class ElectionBlackboxTests(WebTest):
self.election = models.Election.objects.all()[0] self.election = models.Election.objects.all()[0]
self.user = auth_models.User.objects.get(user_id='ben@adida.net', user_type='google') self.user = auth_models.User.objects.get(user_id='ben@adida.net', user_type='google')
def setup_login(self): def setup_login(self, from_scratch=False, **kwargs):
if from_scratch:
# a bogus call to set up the session
self.client.get("/")
# set up the session # set up the session
session = self.client.session session = self.client.session
session['user'] = {'type': self.user.user_type, 'user_id': self.user.user_id} if kwargs:
user = auth_models.User.objects.get(**kwargs)
else:
user = self.user
session['user'] = {'type': user.user_type, 'user_id': user.user_id}
session.save() session.save()
# set up the app, too # set up the app, too
...@@ -468,10 +475,7 @@ class ElectionBlackboxTests(WebTest): ...@@ -468,10 +475,7 @@ class ElectionBlackboxTests(WebTest):
self.assertRedirects(response, "/auth/?return_url=/helios/elections/new") self.assertRedirects(response, "/auth/?return_url=/helios/elections/new")
def test_election_edit(self): def test_election_edit(self):
# a bogus call to set up the session self.setup_login(from_scratch=True)
self.client.get("/")
self.setup_login()
response = self.client.get("/helios/elections/%s/edit" % self.election.uuid) response = self.client.get("/helios/elections/%s/edit" % self.election.uuid)
response = self.client.post("/helios/elections/%s/edit" % self.election.uuid, { response = self.client.post("/helios/elections/%s/edit" % self.election.uuid, {
"short_name" : self.election.short_name + "-2", "short_name" : self.election.short_name + "-2",
...@@ -490,11 +494,8 @@ class ElectionBlackboxTests(WebTest): ...@@ -490,11 +494,8 @@ class ElectionBlackboxTests(WebTest):
def _setup_complete_election(self, election_params=None): def _setup_complete_election(self, election_params=None):
"do the setup part of a whole election" "do the setup part of a whole election"
# a bogus call to set up the session
self.client.get("/")
# REPLACE with params? # REPLACE with params?
self.setup_login() self.setup_login(from_scratch=True)
# create the election # create the election
full_election_params = { full_election_params = {
...@@ -755,8 +756,7 @@ class ElectionBlackboxTests(WebTest): ...@@ -755,8 +756,7 @@ class ElectionBlackboxTests(WebTest):
def test_election_voters_eligibility(self): def test_election_voters_eligibility(self):
# create the election # create the election
self.client.get("/") self.setup_login(from_scratch=True)
self.setup_login()
response = self.client.post("/helios/elections/new", { response = self.client.post("/helios/elections/new", {
"short_name" : "test-eligibility", "short_name" : "test-eligibility",
"name" : "Test Eligibility", "name" : "Test Eligibility",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment