withUserTestCase.py 2.35 KB
Newer Older
1 2 3 4 5 6 7
from rest_framework.test import APIClient
from django.contrib.auth.models import User
from django.contrib.auth.models import Group
from django.test import TestCase


class WithUserTestCase(TestCase):
Florent Chehab's avatar
Florent Chehab committed
8 9
    @classmethod
    def setUpTestData(cls):
10
        password = "123456"
11

Florent Chehab's avatar
Florent Chehab committed
12
        cls.staff_user = User.objects.create_user(
13
            username="staff_member", email="master@master.fr", password=password
14
        )
Florent Chehab's avatar
Florent Chehab committed
15 16
        cls.staff_user.is_staff = True
        cls.staff_user.save()
17

Florent Chehab's avatar
Florent Chehab committed
18
        cls.moderator_user = User.objects.create_user(
19 20 21
            username="moderator_member",
            email="moderator@moderator.fr",
            password=password,
22
        )
23
        cls.moderator_group = Group.objects.get_or_create(name="Moderators")[0]
Florent Chehab's avatar
Florent Chehab committed
24 25
        cls.moderator_group.user_set.add(cls.moderator_user)
        cls.moderator_group.save()
26

27
        cls.dri_user = User.objects.create_user(
28
            username="dri_member", email="dri@dri.fr", password=password
29
        )
30
        cls.dri_group = Group.objects.get_or_create(name="DRI")[0]
31 32 33
        cls.dri_group.user_set.add(cls.dri_user)
        cls.dri_group.save()

Florent Chehab's avatar
Florent Chehab committed
34
        cls.authenticated_user = User.objects.create_user(
35 36 37
            username="authenticated_user",
            email="authenticated@authenticated.fr",
            password=password,
38 39
        )

Florent Chehab's avatar
Florent Chehab committed
40
        cls.authenticated_user_2 = User.objects.create_user(
41 42 43
            username="authenticated_user_2",
            email="authenticated_2@authenticated.fr",
            password=password,
44 45
        )

Florent Chehab's avatar
Florent Chehab committed
46
        cls.staff_client = APIClient()
47
        cls.staff_client.login(username=cls.staff_user.username, password=password)
48

Florent Chehab's avatar
Florent Chehab committed
49 50
        cls.moderator_client = APIClient()
        cls.moderator_client.login(
51
            username=cls.moderator_user.username, password=password
52 53
        )

54
        cls.dri_client = APIClient()
55
        cls.dri_client.login(username=cls.dri_user.username, password=password)
56

Florent Chehab's avatar
Florent Chehab committed
57 58
        cls.authenticated_client = APIClient()
        cls.authenticated_client.login(
59
            username=cls.authenticated_user.username, password=password
Florent Chehab's avatar
Florent Chehab committed
60 61 62 63
        )

        cls.authenticated_client_2 = APIClient()
        cls.authenticated_client_2.login(
64
            username=cls.authenticated_user_2.username, password=password
Florent Chehab's avatar
Florent Chehab committed
65 66 67
        )

        cls.unauthenticated_client = APIClient()
68

Florent Chehab's avatar
Florent Chehab committed
69
        cls.setUpMoreTestData()
70

Florent Chehab's avatar
Florent Chehab committed
71 72
    @classmethod
    def setUpMoreTestData(cls):
73
        pass