test_write_access.py 1.19 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
from backend_app.models.university import University
from backend_app.tests.utils import WithUserTestCase


class WriteAccessTestCase(WithUserTestCase):
    """
    Test the write access to DRI restricted elements
    """

    @classmethod
    def setUpMoreTestData(cls):
        cls.univ = University.objects.create(name="Univ de test", utc_id=100)
13
        cls.api_dri = "/api/universityDri/?universities={}/".format(cls.univ.pk)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
        cls.post_data = dict(
            universities=[cls.univ.pk], title="qsdlkjqsmlkdj", useful_links="[]"
        )

    def test_write_dri_staff(self):
        response = self.staff_client.post(self.api_dri, self.post_data)
        self.assertEqual(response.status_code, 201)

    def test_write_dri_dri(self):
        response = self.dri_client.post(self.api_dri, self.post_data)
        self.assertEqual(response.status_code, 201)

    def test_write_dri_moderator(self):
        response = self.moderator_client.post(self.api_dri, self.post_data)
        self.assertEqual(response.status_code, 403)

    def test_write_dri_authentificated(self):
        response = self.authenticated_client.post(self.api_dri, self.post_data)
        self.assertEqual(response.status_code, 403)