Sith/election/tests.py

50 lines
1.8 KiB
Python
Raw Permalink Normal View History

2024-06-24 11:07:36 +00:00
from django.conf import settings
2017-06-07 14:22:04 +00:00
from django.test import TestCase
from django.urls import reverse
2016-12-05 19:18:03 +00:00
2024-06-24 11:07:36 +00:00
from core.models import Group, User
2017-02-01 17:09:47 +00:00
from election.models import Election
2017-02-01 16:38:16 +00:00
2024-07-23 22:39:26 +00:00
class TestElection(TestCase):
@classmethod
def setUpTestData(cls):
cls.election = Election.objects.first()
cls.public_group = Group.objects.get(id=settings.SITH_GROUP_PUBLIC_ID)
cls.subscriber_group = Group.objects.get(name=settings.SITH_MAIN_MEMBERS_GROUP)
cls.ae_board_group = Group.objects.get(name=settings.SITH_MAIN_BOARD_GROUP)
cls.sli = User.objects.get(username="sli")
cls.subscriber = User.objects.get(username="subscriber")
cls.public = User.objects.get(username="public")
2024-07-23 22:39:26 +00:00
class TestElectionDetail(TestElection):
2017-02-01 16:38:16 +00:00
def test_permission_denied(self):
self.election.view_groups.remove(self.public_group)
self.client.force_login(self.public)
response = self.client.get(
2018-10-04 19:29:19 +00:00
reverse("election:detail", args=str(self.election.id))
)
assert response.status_code == 403
2017-02-01 16:38:16 +00:00
def test_permisson_granted(self):
self.client.force_login(self.public)
response = self.client.get(
2018-10-04 19:29:19 +00:00
reverse("election:detail", args=str(self.election.id))
)
assert response.status_code == 200
assert "La roue tourne" in str(response.content)
2017-02-01 17:09:47 +00:00
2024-07-23 22:39:26 +00:00
class TestElectionUpdateView(TestElection):
2017-02-01 17:09:47 +00:00
def test_permission_denied(self):
self.client.force_login(self.subscriber)
response = self.client.get(
2018-10-04 19:29:19 +00:00
reverse("election:update", args=str(self.election.id))
)
assert response.status_code == 403
response = self.client.post(
2018-10-04 19:29:19 +00:00
reverse("election:update", args=str(self.election.id))
)
assert response.status_code == 403