Sith/election/tests.py

69 lines
2.4 KiB
Python
Raw Normal View History

2023-04-06 11:08:42 +00:00
# -*- coding:utf-8 -*-
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr
# All contributors are listed in the CONTRIBUTORS file.
#
# This file is part of the website of the UTBM Student Association (AE UTBM),
# https://ae.utbm.fr.
#
# You can find the whole source code at https://github.com/ae-utbm/sith3
#
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
# OR WITHIN THE LOCAL FILE "LICENSE"
#
# PREVIOUSLY LICENSED UNDER THE MIT LICENSE,
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE.old
# OR WITHIN THE LOCAL FILE "LICENSE.old"
#
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
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):
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
class ElectionUpdateView(ElectionTest):
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