init
This commit is contained in:
46
backend-django/backend/tests/views/notation.py
Normal file
46
backend-django/backend/tests/views/notation.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from backend.views import NotationView
|
||||
from django.contrib.auth import get_user_model
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from .constants import PASSWORD, USERNAME
|
||||
from .test_utils import TestUtilsMixin, disable_gestionnaire_permission
|
||||
|
||||
VIEW_TYPE = NotationView
|
||||
|
||||
class NotationViewTest(APITestCase, TestUtilsMixin):
|
||||
|
||||
basename = 'Notation'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
user = get_user_model().objects.create(id=1, username=USERNAME)
|
||||
user.set_password(PASSWORD)
|
||||
user.save()
|
||||
|
||||
def setUp(self):
|
||||
logged_in = self.client.login(username=USERNAME, password=PASSWORD)
|
||||
self.assertTrue(logged_in, "l'utilisateur devrait être connecté")
|
||||
|
||||
def tearDown(self):
|
||||
self.client.logout()
|
||||
|
||||
def test_list_anonymous(self):
|
||||
""" vérifie que l'accès anonyme est interdit """
|
||||
|
||||
self.client.logout()
|
||||
url = self._api_url()
|
||||
|
||||
response = self.client.get(url)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
@disable_gestionnaire_permission(VIEW_TYPE)
|
||||
def test_list_authenticated(self):
|
||||
""" vérifie que l'utilisateur authentifié peut récupérer des décisions """
|
||||
|
||||
url = self._api_url()
|
||||
|
||||
response = self.client.get(url)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user