|
|
|
@ -72,7 +72,7 @@ class PollDetailsTests(
|
|
|
|
|
self,
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
If test user has not yet voted, options should be shown
|
|
|
|
|
If test user has already voted, results should be shown
|
|
|
|
|
"""
|
|
|
|
|
test_user = self.fresh_user_logged_in()
|
|
|
|
|
poll = self.create_poll_with_questions()
|
|
|
|
@ -111,7 +111,7 @@ class PollDetailsTests(
|
|
|
|
|
self,
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
If test user has not yet voted, options should be shown
|
|
|
|
|
If test user has already voted, voting again should not change anything
|
|
|
|
|
"""
|
|
|
|
|
test_user = self.fresh_user_logged_in()
|
|
|
|
|
poll = self.create_poll_with_questions()
|
|
|
|
@ -146,3 +146,37 @@ class PollDetailsTests(
|
|
|
|
|
Vote.objects.count(),
|
|
|
|
|
1,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_unauthenticated_user_cant_vote(
|
|
|
|
|
self,
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
If an unauthenticated user tries to vote it should fail
|
|
|
|
|
"""
|
|
|
|
|
poll = self.create_poll_with_questions()
|
|
|
|
|
options = Option.objects.filter(
|
|
|
|
|
poll=poll,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
Vote.objects.count(),
|
|
|
|
|
0,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response = self.client.post(
|
|
|
|
|
reverse(
|
|
|
|
|
"cast-vote",
|
|
|
|
|
kwargs={
|
|
|
|
|
"poll_id": poll.pk,
|
|
|
|
|
"option_id": options[0].pk,
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
self.assertNotEqual(
|
|
|
|
|
response.status_code,
|
|
|
|
|
200,
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
Vote.objects.count(),
|
|
|
|
|
0,
|
|
|
|
|
)
|
|
|
|
|