From b5363c298717c518d3e8a0adecb15385f539609b Mon Sep 17 00:00:00 2001 From: klmp200 Date: Wed, 1 Feb 2017 17:38:16 +0100 Subject: [PATCH] Firsts tests for elections --- core/management/commands/populate.py | 4 +-- election/tests.py | 50 ++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index bc9d8c32..438d2258 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -430,13 +430,13 @@ Welcome to the wiki page! # Create an election public_group = Group.objects.get(id=settings.SITH_GROUP_PUBLIC_ID) subscriber_group = Group.objects.get(name=settings.SITH_MAIN_MEMBERS_GROUP) - ae_board_gorup = Group.objects.get(name=settings.SITH_MAIN_BOARD_GROUP) + ae_board_group = Group.objects.get(name=settings.SITH_MAIN_BOARD_GROUP) el = Election(title="Élection 2017", description="La roue tourne", start_candidature='1942-06-12 10:28:45+01', end_candidature='2042-06-12 10:28:45+01',start_date='1942-06-12 10:28:45+01', end_date='7942-06-12 10:28:45+01') el.save() el.view_groups.add(public_group) - el.edit_groups.add(ae_board_gorup) + el.edit_groups.add(ae_board_group) el.candidature_groups.add(subscriber_group) el.vote_groups.add(subscriber_group) el.save() diff --git a/election/tests.py b/election/tests.py index 7ce503c2..4d85db18 100644 --- a/election/tests.py +++ b/election/tests.py @@ -1,3 +1,49 @@ -from django.test import TestCase +from django.test import Client, TestCase +from django.core.urlresolvers import reverse +from django.contrib.auth.models import Group +from django.core.management import call_command +from django.conf import settings +from datetime import date, datetime -# Create your tests here. +from core.models import User, Group +from election.models import Election, Role, ElectionList, Candidature, Vote + + +class MainElection(): + election = Election.objects.all().first() + public_group = Group.objects.get(id=settings.SITH_GROUP_PUBLIC_ID) + subscriber_group = Group.objects.get(name=settings.SITH_MAIN_MEMBERS_GROUP) + ae_board_group = Group.objects.get(name=settings.SITH_MAIN_BOARD_GROUP) + sli = User.objects.get(username='sli') + subscriber = User.objects.get(username='subscriber') + public = User.objects.get(username='public') + + +class ElectionDetailTest(MainElection, TestCase): + def setUp(self): + call_command("populate") + + def test_permission_denied(self): + self.election.view_groups.remove(self.public_group) + self.election.view_groups.add(self.subscriber_group) + self.election.save() + 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))) + 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): + 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))) + self.assertFalse(response_get.status_code == 403) + self.assertFalse(response_post.status_code == 403) + self.assertTrue('La roue tourne' in str(response_get.content))