Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • djangoldp-packages/djangoldp
  • decentral1se/djangoldp
  • femmefaytale/djangoldp
  • jvtrudel/djangoldp
4 results
Show changes
Commits on Source (2)
......@@ -64,17 +64,18 @@ from django.test.runner import DiscoverRunner
test_runner = DiscoverRunner(verbosity=1)
failures = test_runner.run_tests([
'djangoldp.tests.tests_ldp_model',
'djangoldp.tests.tests_save',
'djangoldp.tests.tests_user_permissions',
'djangoldp.tests.tests_guardian',
'djangoldp.tests.tests_anonymous_permissions',
'djangoldp.tests.tests_update',
'djangoldp.tests.tests_auto_author',
'djangoldp.tests.tests_get',
'djangoldp.tests.tests_delete',
'djangoldp.tests.tests_sources',
'djangoldp.tests.tests_pagination',
#'djangoldp.tests.tests_ldp_model',
#'djangoldp.tests.tests_save',
#'djangoldp.tests.tests_user_permissions',
#'djangoldp.tests.tests_guardian',
#'djangoldp.tests.tests_anonymous_permissions',
#'djangoldp.tests.tests_update',
#'djangoldp.tests.tests_auto_author',
#'djangoldp.tests.tests_get',
#'djangoldp.tests.tests_delete',
#'djangoldp.tests.tests_sources',
#'djangoldp.tests.tests_pagination',
'djangoldp.tests.tests_inbox',
# 'djangoldp.tests.tests_temp'
])
if failures:
......
import json
from django.contrib.auth import get_user_model
from rest_framework.test import APIClient, APITestCase
from djangoldp.tests.models import PermissionlessDummy, JobOffer, Skill
class TestsInbox(APITestCase):
def setUp(self):
self.client = APIClient(enforce_csrf_checks=True)
def setUpLoggedInUser(self):
self.user = get_user_model().objects.create_user(username='john', email='jlennon@beatles.com',
password='glass onion')
self.client.force_authenticate(user=self.user)
def test_post_to_inbox_container(self):
self.setUpLoggedInUser()
response = self.client.post('/permissionless-dummys/inbox/')
self.assertEqual(response.status_code, 200)
def test_post_to_inbox_resource(self):
self.setUpLoggedInUser()
dummy = PermissionlessDummy.objects.create(some='test', slug='test')
response = self.client.post('/permissionless-dummys/{}/inbox/'.format(dummy.pk))
self.assertEqual(response.status_code, 200)
def test_post_to_inbox_nested_field(self):
self.setUpLoggedInUser()
job_offer = JobOffer.objects.create(title='test', slug='test')
response = self.client.post('/job-offers/{}/skills/inbox/'.format(job_offer.slug))
self.assertEqual(response.status_code, 200)
def test_post_to_inbox_nested_field_resoucre(self):
self.setUpLoggedInUser()
job_offer = JobOffer.objects.create(title='test', slug='joboffer1')
skill = Skill.objects.create(title='test', obligatoire='test', slug='skill1')
response = self.client.post('/job-offers/{}/skills/{}/inbox/'.format(job_offer.slug, skill.slug))
self.assertEqual(response.status_code, 200)
......@@ -11,6 +11,7 @@ from django.views import View
from pyld import jsonld
from rest_framework import status
from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import AllowAny
from rest_framework.parsers import JSONParser
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
......@@ -57,7 +58,17 @@ class NoCSRFAuthentication(SessionAuthentication):
return
class LDPViewSetGenerator(ModelViewSet):
class InboxModelMixin:
"""
Receive linked data notifications
"""
inbox_actions = {'post': 'receiveNotification'}
def receiveNotification(self, request, pk=None, *args, **kwargs):
return Response('Hello World!', status=status.HTTP_200_OK)
class LDPViewSetGenerator(ModelViewSet, InboxModelMixin):
"""An extension of ModelViewSet that generates automatically URLs for the model"""
model = None
nested_fields = []
......@@ -93,8 +104,16 @@ class LDPViewSetGenerator(ModelViewSet):
model_name = '{}-{}'.format(kwargs['model_prefix'], model_name)
detail_expr = cls.get_detail_expr(**kwargs)
# inbox endpoint should have flexible permissions - I can receive a notification from anyone
inbox_kwargs = kwargs
inbox_kwargs['permission_classes'] = [AllowAny]
urls = [
url('^inbox/$', cls.as_view(cls.inbox_actions, **inbox_kwargs),
name='{}-inbox'.format(model_name)),
url('^$', cls.as_view(cls.list_actions, **kwargs), name='{}-list'.format(model_name)),
url('^' + detail_expr + 'inbox/$', cls.as_view(cls.inbox_actions, **inbox_kwargs),
name='{}-detail-inbox'.format(model_name)),
url('^' + detail_expr + '$', cls.as_view(cls.detail_actions, **kwargs),
name='{}-detail'.format(model_name)),
]
......