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-notification
  • decentral1se/djangoldp-notification
  • femmefaytale/djangoldp-notification
  • 3wc/djangoldp-notification
4 results
Show changes
import uuid
from rest_framework.test import APITestCase, APIClient
from djangoldp_account.models import LDPUser
from djangoldp_notification.models import Subscription
class TestModel(APITestCase):
circle_user1_url = "http://localhost:8000/circles/1/"
circle_user2_url = "http://localhost:8000/circles/2/"
def _get_random_user(self):
return LDPUser.objects.create(email='{}@test.co.uk'.format(str(uuid.uuid4())), first_name='Test',
last_name='Test', username=str(uuid.uuid4()))
def _auth_as_user(self, user):
self.client.force_authenticate(user=user)
def setUpLoggedInUser(self):
self.user = self._get_random_user()
self._auth_as_user(self.user)
def setUp(self):
self.client = APIClient()
self.user1 = self._get_random_user()
Subscription.objects.create(object=self.circle_user1_url, inbox="http://testserver/users/karl_marx/inbox/")
self.user2 = self._get_random_user()
Subscription.objects.create(object=self.circle_user2_url,
inbox="http://testserver/users/piotr_kropotkine/inbox/")
def test_not_logged_fails(self):
response = self.client.get("/subscriptions/")
self.assertEqual(response.status_code, 403)
def test_logged_in_succeeds(self):
self._auth_as_user(self.user2)
response = self.client.get("/subscriptions/").data.get("ldp:contains")
self.assertEqual(len(response), 2)
response = response[1]
self.assertEqual(response["object"], self.circle_user2_url)
self.assertEqual(response["inbox"], "http://testserver/users/piotr_kropotkine/inbox/")
# No more permissions serialised on users
# self.assertIn({'mode': {'@type': 'view'}}, response["permissions"])
# self.assertIn({'mode': {'@type': 'delete'}}, response["permissions"])
import uuid
import json
from django.conf import settings
from rest_framework.test import APITestCase, APIClient
from djangoldp_account.models import LDPUser
from djangoldp_notification.models import Notification, Subscription
class SubscriptionTestCase(APITestCase):
def setUp(self):
self.client = APIClient()
def _get_random_user(self):
return LDPUser.objects.create(email='{}@test.co.uk'.format(str(uuid.uuid4())), first_name='Test',
last_name='Test', username=str(uuid.uuid4()))
def _auth_as_user(self, user):
self.client.force_authenticate(user=user)
def setUpLoggedInUser(self):
self.user = self._get_random_user()
self._auth_as_user(self.user)
def test_can_subscribe_to_container(self):
self.setUpLoggedInUser()
users_container = "{}/users/".format(settings.SITE_URL)
Subscription.objects.create(object=users_container, inbox=self.user.urlid + "inbox/")
self.assertEqual(self.user.inbox.count(), 0)
self._get_random_user()
self.assertEqual(self.user.inbox.count(), 2)
notification = self.user.inbox.all()[0]
self.assertTrue(notification.object, users_container)
from django.conf import settings
from django.contrib.auth import get_user_model
from django.http import Http404
from rest_framework import status
from rest_framework.response import Response
from djangoldp.models import Model
from djangoldp.serializers import LDPSerializer
from djangoldp.views import LDPViewSet
from djangoldp.pagination import LDPPagination
import logging
logger = logging.getLogger('djangoldp')
class LDPNotificationsPagination(LDPPagination):
default_limit = 80
def filter_object_is_permitted(recipient, data):
'''
applies filter on passed object data
returns True if the object is permitted, False if not
'''
obj = data['object']
# if a str (urlid) is given then no filtering is to be applied
if isinstance(obj, str):
return True
# the type must be given for a filter to be resolved successfully
if not '@type' in obj or obj['@type'] is None:
logger.error('djangoldp_notification filter ERR in object serialization. received ' + str(obj) + ' without serialized type to identify model. Please include the @type in your serialization')
return False
object_model = Model.get_subclass_with_rdf_type(obj['@type'])
if object_model is None:
logger.error('djangoldp_notification filter ERR in object serialization. Cannot resolve type given ' + str(obj['type']))
return False
if not hasattr(object_model, 'permit_notification'):
logger.error('djangoldp_notification filter ERR. Resolved type ' + str(obj['@type']) + ' but this Model did not have the required function permit_notification defined on it')
return False
return object_model.permit_notification(recipient, data)
class LDPNotificationsViewSet(LDPViewSet):
'''overridden LDPViewSet to force pagination'''
pagination_class = LDPNotificationsPagination
depth = 0
...@@ -10,11 +10,13 @@ license = MIT ...@@ -10,11 +10,13 @@ license = MIT
[options] [options]
packages = find: packages = find:
install_requires = install_requires =
djangoldp~=0.5 djangoldp~=3.1.0
djangoldp_account~=3.1.0
[options.extras_require] [options.extras_require]
include_package_data = True
dev = dev =
factory_boy>=2.11.0 factory_boy>=2.12.0
[semantic_release] [semantic_release]
version_source = tag version_source = tag
......
...@@ -2,4 +2,6 @@ ...@@ -2,4 +2,6 @@
from setuptools import setup from setuptools import setup
setup() setup(
include_package_data=True
)