2016-01-29 14:20:00 +00:00
|
|
|
from django.test import TestCase
|
2016-03-22 08:01:24 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.core.management import call_command
|
2016-01-29 14:20:00 +00:00
|
|
|
|
2016-08-02 20:20:06 +00:00
|
|
|
from core.models import User
|
|
|
|
from club.models import Club
|
|
|
|
|
2016-01-29 14:20:00 +00:00
|
|
|
# Create your tests here.
|
2016-03-22 08:01:24 +00:00
|
|
|
|
|
|
|
class ClubTest(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command("populate")
|
2016-08-02 20:20:06 +00:00
|
|
|
self.skia = User.objects.filter(username="skia").first()
|
|
|
|
self.rbatsbak = User.objects.filter(username="rbatsbak").first()
|
2016-11-06 10:36:54 +00:00
|
|
|
self.guy = User.objects.filter(username="guy").first()
|
2016-08-02 20:20:06 +00:00
|
|
|
self.bdf = Club.objects.filter(unix_name="bdf").first()
|
2016-03-22 08:01:24 +00:00
|
|
|
|
|
|
|
def test_create_add_user_to_club_from_root_ok(self):
|
|
|
|
self.client.login(username='root', password='plop')
|
2016-08-02 20:20:06 +00:00
|
|
|
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 3})
|
|
|
|
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
|
2016-03-22 08:01:24 +00:00
|
|
|
self.assertTrue(response.status_code == 200)
|
2016-11-06 10:36:54 +00:00
|
|
|
self.assertTrue("S' Kia</a></td>\\n <td>Responsable info</td>" in str(response.content))
|
2016-03-22 08:01:24 +00:00
|
|
|
|
|
|
|
def test_create_add_user_to_club_from_root_fail_not_subscriber(self):
|
|
|
|
self.client.login(username='root', password='plop')
|
2016-11-06 10:36:54 +00:00
|
|
|
response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.guy.id, "role": 3})
|
2016-03-22 08:01:24 +00:00
|
|
|
self.assertTrue(response.status_code == 200)
|
2016-08-02 20:20:06 +00:00
|
|
|
self.assertTrue('<ul class="errorlist nonfield"><li>' in str(response.content))
|
|
|
|
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
|
2016-11-06 10:36:54 +00:00
|
|
|
self.assertFalse("Guy Carlier</a></td>\\n <td>Responsable info</td>" in str(response.content))
|
2016-03-22 08:01:24 +00:00
|
|
|
|
|
|
|
def test_create_add_user_to_club_from_root_fail_already_in_club(self):
|
|
|
|
self.client.login(username='root', password='plop')
|
2016-11-06 10:36:54 +00:00
|
|
|
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 3})
|
2016-08-02 20:20:06 +00:00
|
|
|
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
|
2016-11-06 10:36:54 +00:00
|
|
|
self.assertTrue("S' Kia</a></td>\\n <td>Responsable info</td>" in str(response.content))
|
|
|
|
response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 4})
|
2016-03-22 08:01:24 +00:00
|
|
|
self.assertTrue(response.status_code == 200)
|
2016-11-06 10:36:54 +00:00
|
|
|
self.assertFalse("S' Kia</a></td>\\n <td>Secrétaire</td>" in str(response.content))
|
2016-03-22 08:01:24 +00:00
|
|
|
|
|
|
|
def test_create_add_user_to_club_from_skia_ok(self):
|
|
|
|
self.client.login(username='root', password='plop')
|
2016-11-06 10:36:54 +00:00
|
|
|
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 10})
|
2016-03-22 08:01:24 +00:00
|
|
|
self.client.login(username='skia', password='plop')
|
2016-08-02 20:20:06 +00:00
|
|
|
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.rbatsbak.id, "role": 9})
|
|
|
|
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
|
2016-03-22 08:01:24 +00:00
|
|
|
self.assertTrue(response.status_code == 200)
|
2016-11-06 10:36:54 +00:00
|
|
|
self.assertTrue("""Richard Batsbak</a></td>\\n <td>Vice-Pr\\xc3\\xa9sident</td>""" in str(response.content))
|
2016-03-22 08:01:24 +00:00
|
|
|
|
2016-03-31 08:36:00 +00:00
|
|
|
def test_create_add_user_to_club_from_richard_fail(self):
|
2016-03-22 08:01:24 +00:00
|
|
|
self.client.login(username='root', password='plop')
|
2016-08-02 20:20:06 +00:00
|
|
|
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.rbatsbak.id, "role": 3})
|
2016-03-31 08:36:00 +00:00
|
|
|
self.client.login(username='rbatsbak', password='plop')
|
2016-11-06 10:36:54 +00:00
|
|
|
response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 10})
|
2016-03-22 08:01:24 +00:00
|
|
|
self.assertTrue(response.status_code == 200)
|
2016-11-08 18:07:25 +00:00
|
|
|
self.assertTrue("<li>Vous n'avez pas la permission de faire cela</li>" in str(response.content))
|
2016-08-02 20:20:06 +00:00
|
|
|
|