Commit e67821fe authored by Jean-Baptiste's avatar Jean-Baptiste

update: fix test by setting LDPPermissions on views.permissions_classes

parent 329e2185
Pipeline #4663 passed with stage
in 1 minute and 20 seconds
from rest_framework.permissions import DjangoObjectPermissions
from django.core.exceptions import PermissionDenied
class LDPPermissions(DjangoObjectPermissions):
"""
Default permissions
Anon: None
Auth: None but herit from Anon
Ownr: None but herit from Auth
Ownr: None but herit from Auth
"""
anonymous_perms = []
authenticated_perms = ['inherit']
......@@ -86,7 +87,6 @@ class LDPPermissions(DjangoObjectPermissions):
return True
def has_object_permission(self, request, view, obj):
"""
Access to objects
......@@ -100,4 +100,4 @@ class LDPPermissions(DjangoObjectPermissions):
read_perms = self.get_permissions('GET', obj)
return PermissionDenied
return True
\ No newline at end of file
return True
from django.contrib.auth.models import AnonymousUser
from django.test import TestCase
from rest_framework.test import APIRequestFactory
import json
from django.test import TestCase
from guardian.shortcuts import get_anonymous_user
from rest_framework.test import APIRequestFactory
from djangoldp.permissions import LDPPermissions
from djangoldp.tests.models import JobOffer
from djangoldp.views import LDPViewSet
import json
class TestAnonymousUserPermissions(TestCase):
def setUp(self):
......@@ -22,6 +21,8 @@ class TestAnonymousUserPermissions(TestCase):
my_view = LDPViewSet.as_view({'get': 'list'},
model=JobOffer,
nested_fields=["skills"])
my_view.cls.permission_classes = [LDPPermissions]
response = my_view(request)
self.assertEqual(response.status_code, 200)
......@@ -29,6 +30,8 @@ class TestAnonymousUserPermissions(TestCase):
data = {'title': 'new idea'}
request = self.factory.post('/job-offers/', json.dumps(data), content_type='application/ld+json')
my_view = LDPViewSet.as_view({'post': 'create'}, model=JobOffer, nested_fields=["skills"])
my_view.cls.permission_classes = [LDPPermissions]
response = my_view(request, pk=1)
self.assertEqual(response.status_code, 403)
......@@ -37,6 +40,8 @@ class TestAnonymousUserPermissions(TestCase):
my_view = LDPViewSet.as_view({'put': 'update'},
model=JobOffer,
nested_fields=["skills"])
my_view.cls.permission_classes = [LDPPermissions]
response = my_view(request, pk=self.job.pk)
self.assertEqual(response.status_code, 403)
......@@ -45,5 +50,6 @@ class TestAnonymousUserPermissions(TestCase):
my_view = LDPViewSet.as_view({'patch': 'partial_update'},
model=JobOffer,
nested_fields=["skills"])
my_view.cls.permission_classes = [LDPPermissions]
response = my_view(request, pk=self.job.pk)
self.assertEqual(response.status_code, 403)
from django.contrib.auth.models import User
from rest_framework.test import APIRequestFactory, APIClient, APITestCase
from djangoldp.permissions import LDPPermissions
from .models import JobOffer
from djangoldp.views import LDPViewSet
......@@ -22,6 +23,8 @@ class TestUserPermissions(APITestCase):
request = self.factory.get('/job-offers/')
request.user = self.user
my_view = LDPViewSet.as_view({'get': 'list'}, model=JobOffer)
my_view.cls.permission_classes = [LDPPermissions]
response = my_view(request)
self.assertEqual(response.status_code, 200)
......@@ -30,6 +33,8 @@ class TestUserPermissions(APITestCase):
request = self.factory.post('/job-offers/', json.dumps(data), content_type='application/ld+json')
request.user = self.user
my_view = LDPViewSet.as_view({'post': 'create'}, model=JobOffer, nested_fields=["skills"])
my_view.cls.permission_classes = [LDPPermissions]
response = my_view(request, pk=1)
self.assertEqual(response.status_code, 201)
......@@ -38,6 +43,8 @@ class TestUserPermissions(APITestCase):
# request = self.factory.put('/job-offers/' + str(self.job.pk) + "/", data)
# request.user = self.user
# my_view = LDPViewSet.as_view({'put': 'update'}, model=JobOffer)
# my_view.cls.permission_classes = [LDPPermissions]
#
# response = my_view(request, pk=self.job.pk)
# self.assertEqual(response.status_code, 200)
#
......@@ -45,5 +52,7 @@ class TestUserPermissions(APITestCase):
# request = self.factory.patch('/job-offers/' + str(self.job.pk) + "/")
# request.user = self.user
# my_view = LDPViewSet.as_view({'patch': 'partial_update'}, model=JobOffer)
# my_view.cls.permission_classes = [LDPPermissions]
#
# response = my_view(request, pk=self.job.pk)
# self.assertEqual(response.status_code, 200)
\ No newline at end of file
# self.assertEqual(response.status_code, 200)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment