update: updated to new DjangoLDP cache

removed workaround, updated tests
This commit is contained in:
Calum Mackervoy
2021-04-27 15:46:26 +00:00
committed by Jean-Baptiste Pasquier
parent 1e184776a4
commit d0f4f5380a
4 changed files with 52 additions and 14 deletions

View File

@ -2,7 +2,9 @@ import uuid
import json
from rest_framework.test import APITestCase, APIClient
from djangoldp.serializers import LDListMixin, LDPSerializer
from django.conf import settings
from djangoldp.models import Model
from djangoldp.serializers import GLOBAL_SERIALIZER_CACHE
from djangoldp_account.models import LDPUser
from djangoldp_notification.models import Notification
@ -22,8 +24,6 @@ class TestSubscription(APITestCase):
def setUp(self):
self.client = APIClient()
LDListMixin.to_representation_cache.reset()
LDPSerializer.to_representation_cache.reset()
def test_indirect_cache(self):
self.setUpLoggedInUser()
@ -55,3 +55,32 @@ class TestSubscription(APITestCase):
self.assertEqual(response.status_code, 200)
notif_serialized = response.data["ldp:contains"][0]
self.assertEqual(notif_serialized["unread"], False)
# NOTE: this would be our ideal cache behaviour
# the functionality for optimising it was removed because of an issue with extensibility
# https://git.startinblox.com/djangoldp-packages/djangoldp-notification/merge_requests/42#note_58559
'''def test_custom_cache_clear(self):
# going to create two notifications in two different inboxes
self.setUpLoggedInUser()
other_user = self._get_random_user()
notification = self._get_random_notification(recipient=self.user, author=other_user)
notification2 = self._get_random_notification(recipient=other_user, author=self.user)
# GET the inboxes and asser that the cache is set for both
self.client.get("/users/{}/inbox/".format(self.user.username))
self.client.get("/users/{}/inbox/".format(other_user.username))
# assert cache is set
my_container_urlid = '{}/users/{}/inbox/'.format(settings.SITE_URL, self.user.username)
their_container_urlid = '{}/users/{}/inbox/'.format(settings.SITE_URL, other_user.username)
self.assertTrue(GLOBAL_SERIALIZER_CACHE.has(Model.get_meta(Notification, 'label'), my_container_urlid))
self.assertTrue(GLOBAL_SERIALIZER_CACHE.has(Model.get_meta(Notification, 'label'), their_container_urlid))
# save my notification - should wipe the cache for my inbox...
notification.unread = False
notification.save()
self.assertFalse(GLOBAL_SERIALIZER_CACHE.has(Model.get_meta(Notification, 'label'), my_container_urlid))
# ...but not for theirs
self.assertTrue(GLOBAL_SERIALIZER_CACHE.has(Model.get_meta(Notification, 'label'), their_container_urlid))'''

View File

@ -1,7 +1,6 @@
import uuid
from rest_framework.test import APITestCase, APIClient
from djangoldp.serializers import LDListMixin, LDPSerializer
from djangoldp_account.models import LDPUser
from djangoldp_notification.models import Subscription
@ -23,8 +22,6 @@ class TestSubscription(APITestCase):
def setUp(self):
self.client = APIClient()
LDListMixin.to_representation_cache.reset()
LDPSerializer.to_representation_cache.reset()
self.user1 = self._get_random_user()
Subscription.objects.create(object=self.circle_user1_url, inbox="http://testserver/users/karl_marx/inbox/")