Sith/election/tests.py

65 lines
2.6 KiB
Python
Raw Normal View History

2017-06-07 14:22:04 +00:00
from django.test import TestCase
from django.urls import reverse
2017-02-01 16:38:16 +00:00
from django.core.management import call_command
from django.conf import settings
2016-12-05 19:18:03 +00:00
from core.models import User, Group
2017-02-01 17:09:47 +00:00
from election.models import Election
2017-02-01 16:38:16 +00:00
2017-02-01 17:09:47 +00:00
class MainElection(TestCase):
2017-02-01 16:38:16 +00:00
def setUp(self):
call_command("populate")
2017-02-01 17:09:47 +00:00
self.election = Election.objects.all().first()
self.public_group = Group.objects.get(id=settings.SITH_GROUP_PUBLIC_ID)
2018-10-04 19:29:19 +00:00
self.subscriber_group = Group.objects.get(name=settings.SITH_MAIN_MEMBERS_GROUP)
self.ae_board_group = Group.objects.get(name=settings.SITH_MAIN_BOARD_GROUP)
self.sli = User.objects.get(username="sli")
self.subscriber = User.objects.get(username="subscriber")
self.public = User.objects.get(username="public")
2017-02-01 17:09:47 +00:00
class ElectionDetailTest(MainElection):
2017-02-01 16:38:16 +00:00
def test_permission_denied(self):
self.election.view_groups.remove(self.public_group)
self.election.view_groups.add(self.subscriber_group)
self.election.save()
2018-10-04 19:29:19 +00:00
self.client.login(username=self.public.username, password="plop")
response_get = self.client.get(
reverse("election:detail", args=str(self.election.id))
)
response_post = self.client.get(
reverse("election:detail", args=str(self.election.id))
)
2017-02-01 16:38:16 +00:00
self.assertTrue(response_get.status_code == 403)
self.assertTrue(response_post.status_code == 403)
self.election.view_groups.remove(self.subscriber_group)
self.election.view_groups.add(self.public_group)
self.election.save()
def test_permisson_granted(self):
2018-10-04 19:29:19 +00:00
self.client.login(username=self.public.username, password="plop")
response_get = self.client.get(
reverse("election:detail", args=str(self.election.id))
)
response_post = self.client.post(
reverse("election:detail", args=str(self.election.id))
)
2017-02-01 16:38:16 +00:00
self.assertFalse(response_get.status_code == 403)
self.assertFalse(response_post.status_code == 403)
2018-10-04 19:29:19 +00:00
self.assertTrue("La roue tourne" in str(response_get.content))
2017-02-01 17:09:47 +00:00
class ElectionUpdateView(MainElection):
def test_permission_denied(self):
2018-10-04 19:29:19 +00:00
self.client.login(username=self.subscriber.username, password="plop")
response_get = self.client.get(
reverse("election:update", args=str(self.election.id))
)
response_post = self.client.post(
reverse("election:update", args=str(self.election.id))
)
2017-02-01 17:09:47 +00:00
self.assertTrue(response_get.status_code == 403)
self.assertTrue(response_post.status_code == 403)