tests.py 3.69 KB
Newer Older
1
from django.test import TestCase
Skia's avatar
Skia committed
2
3
from django.core.urlresolvers import reverse
from django.core.management import call_command
4

Skia's avatar
Skia committed
5
6
7
from core.models import User
from club.models import Club

8
# Create your tests here.
Skia's avatar
Skia committed
9
10
11
12

class ClubTest(TestCase):
    def setUp(self):
        call_command("populate")
Skia's avatar
Skia committed
13
14
        self.skia = User.objects.filter(username="skia").first()
        self.rbatsbak = User.objects.filter(username="rbatsbak").first()
Skia's avatar
Skia committed
15
        self.guy = User.objects.filter(username="guy").first()
Skia's avatar
Skia committed
16
        self.bdf = Club.objects.filter(unix_name="bdf").first()
Skia's avatar
Skia committed
17
18
19

    def test_create_add_user_to_club_from_root_ok(self):
        self.client.login(username='root', password='plop')
Skia's avatar
Skia committed
20
21
        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}))
Skia's avatar
Skia committed
22
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
23
        self.assertTrue("S&#39; Kia</a></td>\\n                <td>Responsable info</td>" in str(response.content))
Skia's avatar
Skia committed
24
25
26

    def test_create_add_user_to_club_from_root_fail_not_subscriber(self):
        self.client.login(username='root', password='plop')
Skia's avatar
Skia committed
27
        response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.guy.id, "role": 3})
Skia's avatar
Skia committed
28
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
29
30
        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}))
Skia's avatar
Skia committed
31
        self.assertFalse("Guy Carlier</a></td>\\n                <td>Responsable info</td>" in str(response.content))
Skia's avatar
Skia committed
32
33
34

    def test_create_add_user_to_club_from_root_fail_already_in_club(self):
        self.client.login(username='root', password='plop')
Skia's avatar
Skia committed
35
        self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 3})
Skia's avatar
Skia committed
36
        response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
Skia's avatar
Skia committed
37
38
        self.assertTrue("S&#39; 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})
Skia's avatar
Skia committed
39
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
40
        self.assertFalse("S&#39; Kia</a></td>\\n                <td>Secrétaire</td>" in str(response.content))
Skia's avatar
Skia committed
41
42
43

    def test_create_add_user_to_club_from_skia_ok(self):
        self.client.login(username='root', password='plop')
Skia's avatar
Skia committed
44
        self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 10})
Skia's avatar
Skia committed
45
        self.client.login(username='skia', password='plop')
Skia's avatar
Skia committed
46
47
        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}))
Skia's avatar
Skia committed
48
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
49
        self.assertTrue("""Richard Batsbak</a></td>\\n                <td>Vice-Pr\\xc3\\xa9sident</td>""" in str(response.content))
Skia's avatar
Skia committed
50

Skia's avatar
Skia committed
51
    def test_create_add_user_to_club_from_richard_fail(self):
Skia's avatar
Skia committed
52
        self.client.login(username='root', password='plop')
Skia's avatar
Skia committed
53
        self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.rbatsbak.id, "role": 3})
Skia's avatar
Skia committed
54
        self.client.login(username='rbatsbak', password='plop')
Skia's avatar
Skia committed
55
        response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 10})
Skia's avatar
Skia committed
56
        self.assertTrue(response.status_code == 200)
Skia's avatar
Skia committed
57
        self.assertTrue("<li>Vous n&#39;avez pas la permission de faire cela</li>" in str(response.content))
Skia's avatar
Skia committed
58