withUserTestCase.py 2.54 KB
Newer Older
1 2 3 4 5 6 7 8
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
9 10
    @classmethod
    def setUpTestData(cls):
11 12
        password = '123456'

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

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

32 33 34 35 36 37 38 39 40 41 42
        cls.dri_user = User.objects.create_user(
            username='dri_member',
            email='dri@dri.fr',
            password=password
        )
        cls.dri_group = Group.objects.get_or_create(
            name='DRI'
        )[0]
        cls.dri_group.user_set.add(cls.dri_user)
        cls.dri_group.save()

Florent Chehab's avatar
Florent Chehab committed
43
        cls.authenticated_user = User.objects.create_user(
44 45 46 47 48
            username='authenticated_user',
            email='authenticated@authenticated.fr',
            password=password
        )

Florent Chehab's avatar
Florent Chehab committed
49 50 51
        cls.authenticated_user_2 = User.objects.create_user(
            username='authenticated_user_2',
            email='authenticated_2@authenticated.fr',
52 53 54
            password=password
        )

Florent Chehab's avatar
Florent Chehab committed
55 56 57
        cls.staff_client = APIClient()
        cls.staff_client.login(
            username=cls.staff_user.username,
58 59 60
            password=password
        )

Florent Chehab's avatar
Florent Chehab committed
61 62 63
        cls.moderator_client = APIClient()
        cls.moderator_client.login(
            username=cls.moderator_user.username,
64 65 66
            password=password
        )

67 68 69 70 71 72
        cls.dri_client = APIClient()
        cls.dri_client.login(
            username=cls.dri_user.username,
            password=password
        )

Florent Chehab's avatar
Florent Chehab committed
73 74 75 76 77 78 79 80 81 82 83 84 85
        cls.authenticated_client = APIClient()
        cls.authenticated_client.login(
            username=cls.authenticated_user.username,
            password=password
        )

        cls.authenticated_client_2 = APIClient()
        cls.authenticated_client_2.login(
            username=cls.authenticated_user_2.username,
            password=password
        )

        cls.unauthenticated_client = APIClient()
86

Florent Chehab's avatar
Florent Chehab committed
87
        cls.setUpMoreTestData()
88

Florent Chehab's avatar
Florent Chehab committed
89 90
    @classmethod
    def setUpMoreTestData(cls):
91
        pass