Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Helios Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Helios Server
Commits
83b3c1a6
Unverified
Commit
83b3c1a6
authored
6 years ago
by
Marco Ciotola
Browse files
Options
Downloads
Patches
Plain Diff
Improvements to tests
parent
48e87d03
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
helios/tests.py
+29
-49
29 additions, 49 deletions
helios/tests.py
with
29 additions
and
49 deletions
helios/tests.py
+
29
−
49
View file @
83b3c1a6
...
...
@@ -348,6 +348,13 @@ class LegacyElectionBlackboxTests(DataFormatBlackboxTests, TestCase):
# EXPECTED_BALLOTS_FILE = 'helios/fixtures/v3.1-ballots-expected.json'
class
WebTest
(
django_webtest
.
WebTest
):
def
assertStatusCode
(
self
,
response
,
status_code
):
if
hasattr
(
response
,
'
status_code
'
):
assert
response
.
status_code
==
status_code
,
response
.
status_code
else
:
assert
response
.
status_int
==
status_code
,
response
.
status_int
def
assertRedirects
(
self
,
response
,
url
):
"""
reimplement this in case it
'
s a WebOp response
...
...
@@ -355,35 +362,20 @@ class WebTest(django_webtest.WebTest):
thus the localhost exception
"""
if
hasattr
(
response
,
'
location
'
):
assert
url
in
response
.
location
else
:
assert
url
in
response
.
_headers
[
'
location
'
][
1
]
if
hasattr
(
response
,
'
status_code
'
):
assert
response
.
status_code
==
302
assert
url
in
response
.
location
,
response
.
location
else
:
assert
response
.
status_int
==
302
#self.assertEqual(response.status_code, 302)
assert
url
in
response
[
'
location
'
],
response
[
'
location
'
]
self
.
assertStatusCode
(
response
,
302
)
#return super(django_webtest.WebTest, self).assertRedirects(response, url)
#if hasattr(response, 'status_code') and hasattr(response, 'location'):
#assert url in response.location, "redirected to %s instead of %s" % (response.location, url)
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
def
assertContains
(
self
,
response
,
text
):
self
.
assertStatusCode
(
response
,
200
)
if
hasattr
(
response
,
"
testbody
"
):
assert
text
in
response
.
testbody
,
"
missing text %s
"
%
text
else
:
if
hasattr
(
response
,
"
body
"
):
elif
hasattr
(
response
,
"
body
"
):
assert
text
in
response
.
body
,
"
missing text %s
"
%
text
else
:
assert
text
in
response
.
content
,
"
missing text %s
"
%
text
...
...
@@ -400,22 +392,6 @@ class ElectionBlackboxTests(WebTest):
self
.
election
=
models
.
Election
.
objects
.
all
()[
0
]
self
.
user
=
auth_models
.
User
.
objects
.
get
(
user_id
=
'
ben@adida.net
'
,
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
...
...
@@ -438,11 +414,11 @@ class ElectionBlackboxTests(WebTest):
def
test_election_404
(
self
):
response
=
self
.
client
.
get
(
"
/helios/elections/foobar
"
)
self
.
assert
Equals
(
response
.
status_cod
e
,
404
)
self
.
assert
StatusCode
(
respons
e
,
404
)
def
test_election_bad_trustee
(
self
):
response
=
self
.
client
.
get
(
"
/helios/t/%s/foobar@bar.com/badsecret
"
%
self
.
election
.
short_name
)
self
.
assert
Equals
(
response
.
status_cod
e
,
404
)
self
.
assert
StatusCode
(
respons
e
,
404
)
def
test_get_election_shortcut
(
self
):
response
=
self
.
client
.
get
(
"
/helios/e/%s
"
%
self
.
election
.
short_name
,
follow
=
True
)
...
...
@@ -510,7 +486,7 @@ class ElectionBlackboxTests(WebTest):
new_election
=
models
.
Election
.
objects
.
get
(
uuid
=
self
.
election
.
uuid
)
self
.
assertEquals
(
new_election
.
short_name
,
self
.
election
.
short_name
+
"
-2
"
)
def
_setup_complete_election
(
self
,
election_params
=
{}
):
def
_setup_complete_election
(
self
,
election_params
=
None
):
"
do the setup part of a whole election
"
# a bogus call to set up the session
...
...
@@ -532,12 +508,14 @@ class ElectionBlackboxTests(WebTest):
}
# override with the given
full_election_params
.
update
(
election_params
)
full_election_params
.
update
(
election_params
or
{}
)
response
=
self
.
client
.
post
(
"
/helios/elections/new
"
,
full_election_params
)
# we are redirected to the election, let's extract the ID out of the URL
election_id
=
re
.
search
(
'
/elections/([^/]+)/
'
,
str
(
response
[
'
Location
'
])).
group
(
1
)
election_id
=
re
.
search
(
'
/elections/([^/]+)/
'
,
str
(
response
[
'
Location
'
]))
self
.
assertIsNotNone
(
election_id
,
"
Election id not found in redirect: %s
"
%
str
(
response
[
'
Location
'
]))
election_id
=
election_id
.
group
(
1
)
# helios is automatically added as a trustee
...
...
@@ -577,7 +555,7 @@ class ElectionBlackboxTests(WebTest):
self
.
assertContains
(
response
,
'"
uuid
"
:
"
%s
"'
%
single_voter
.
uuid
)
response
=
self
.
client
.
get
(
"
/helios/elections/%s/voters/foobar
"
%
election_id
)
self
.
assert
Equals
(
response
.
status_cod
e
,
404
)
self
.
assert
StatusCode
(
respons
e
,
404
)
# add questions
response
=
self
.
client
.
post
(
"
/helios/elections/%s/save_questions
"
%
election_id
,
{
...
...
@@ -670,7 +648,7 @@ class ElectionBlackboxTests(WebTest):
# at this point an email should have gone out to the user
# at position num_messages after, since that was the len() before we cast this ballot
email_message
=
mail
.
outbox
[
len
(
mail
.
outbox
)
-
1
]
url
=
re
.
search
(
'
http://[^/]+(/[^
\n
]*)
'
,
email_message
.
body
).
group
(
1
)
url
=
re
.
search
(
'
http
s?
://[^/]+(/[^
\n
]*)
'
,
email_message
.
body
).
group
(
1
)
# check that we can get at that URL
if
not
need_login
:
...
...
@@ -690,7 +668,7 @@ class ElectionBlackboxTests(WebTest):
login_form
[
'
password
'
]
=
'
'
+
password
+
'
'
login_form
.
submit
()
response
=
self
.
app
.
get
(
url
)
response
=
self
.
app
.
get
(
url
,
auto_follow
=
True
)
self
.
assertContains
(
response
,
ballot
.
hash
)
self
.
assertContains
(
response
,
html_escape
(
encrypted_vote
))
...
...
@@ -723,7 +701,7 @@ class ElectionBlackboxTests(WebTest):
# check that we can't get the tally yet
response
=
self
.
client
.
get
(
"
/helios/elections/%s/result
"
%
election_id
)
self
.
assert
Equals
(
response
.
status_cod
e
,
403
)
self
.
assert
StatusCode
(
respons
e
,
403
)
# release
response
=
self
.
client
.
post
(
"
/helios/elections/%s/release_result
"
%
election_id
,
{
...
...
@@ -788,7 +766,9 @@ class ElectionBlackboxTests(WebTest):
"
private_p
"
:
"
False
"
,
'
csrf_token
'
:
self
.
client
.
session
[
'
csrf_token
'
]})
election_id
=
re
.
match
(
"
(.*)/elections/(.*)/view
"
,
response
[
'
Location
'
]).
group
(
2
)
election_id
=
re
.
match
(
"
(.*)/elections/(.*)/view
"
,
str
(
response
[
'
Location
'
]))
self
.
assertIsNotNone
(
election_id
,
"
Election id not found in redirect: %s
"
%
str
(
response
[
'
Location
'
]))
election_id
=
election_id
.
group
(
2
)
# update eligiblity
response
=
self
.
client
.
post
(
"
/helios/elections/%s/voters/eligibility
"
%
election_id
,
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment