Sith/election/tests.py
thomas girod d97602e60b
Use pytest for tests (#681)
* use pytest for tests

Eh ouais, il y a que la config qui change. Pytest est implémentable par étapes. Et ça c'est beau.

* rework tests with pytest

* remove unittest custom TestRunner

* Edit doc and CI
2024-06-26 19:10:24 +02:00

50 lines
1.8 KiB
Python

from django.conf import settings
from django.test import TestCase
from django.urls import reverse
from core.models import Group, User
from election.models import Election
class ElectionTest(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")
class ElectionDetailTest(ElectionTest):
def test_permission_denied(self):
self.election.view_groups.remove(self.public_group)
self.client.force_login(self.public)
response = self.client.get(
reverse("election:detail", args=str(self.election.id))
)
assert response.status_code == 403
def test_permisson_granted(self):
self.client.force_login(self.public)
response = self.client.get(
reverse("election:detail", args=str(self.election.id))
)
assert response.status_code == 200
assert "La roue tourne" in str(response.content)
class ElectionUpdateView(ElectionTest):
def test_permission_denied(self):
self.client.force_login(self.subscriber)
response = self.client.get(
reverse("election:update", args=str(self.election.id))
)
assert response.status_code == 403
response = self.client.post(
reverse("election:update", args=str(self.election.id))
)
assert response.status_code == 403