mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 12:18:45 -05:00
implemented pagination on Log apis
This commit is contained in:
@@ -104,8 +104,7 @@ class TreeModel(MP_Node):
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
|
||||
|
||||
class PermissionModelMixin:
|
||||
@staticmethod
|
||||
|
||||
@@ -33,21 +33,21 @@ def test_list_permission(arg, request):
|
||||
|
||||
|
||||
def test_list_space(obj_1, obj_2, u1_s1, u1_s2, space_2):
|
||||
assert len(json.loads(u1_s1.get(reverse(LIST_URL)).content)) == 2
|
||||
assert len(json.loads(u1_s2.get(reverse(LIST_URL)).content)) == 0
|
||||
assert json.loads(u1_s1.get(reverse(LIST_URL)).content)['count'] == 2
|
||||
assert json.loads(u1_s2.get(reverse(LIST_URL)).content)['count'] == 0
|
||||
|
||||
obj_1.space = space_2
|
||||
obj_1.save()
|
||||
|
||||
assert len(json.loads(u1_s1.get(reverse(LIST_URL)).content)) == 1
|
||||
assert len(json.loads(u1_s2.get(reverse(LIST_URL)).content)) == 0
|
||||
assert json.loads(u1_s1.get(reverse(LIST_URL)).content)['count'] == 1
|
||||
assert json.loads(u1_s2.get(reverse(LIST_URL)).content)['count'] == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 403],
|
||||
['g1_s1', 404],
|
||||
['g1_s1', 403], # changed expected value. based on list permissions the log is visible, but not editable
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 404],
|
||||
['a1_s1', 403], # changed expected value. based on list permissions the log is visible, but not editable
|
||||
['g1_s2', 404],
|
||||
['u1_s2', 404],
|
||||
['a1_s2', 404],
|
||||
@@ -68,31 +68,29 @@ def test_update(arg, request, obj_1):
|
||||
assert response['servings'] == 2
|
||||
|
||||
|
||||
# TODO disabled until https://github.com/vabene1111/recipes/issues/484
|
||||
|
||||
# @pytest.mark.parametrize("arg", [
|
||||
# ['a_u', 403],
|
||||
# ['g1_s1', 201],
|
||||
# ['u1_s1', 201],
|
||||
# ['a1_s1', 201],
|
||||
# ])
|
||||
# def test_add(arg, request, u1_s2, u2_s1, recipe_1_s1):
|
||||
# c = request.getfixturevalue(arg[0])
|
||||
# r = c.post(
|
||||
# reverse(LIST_URL),
|
||||
# {'recipe': recipe_1_s1.id},
|
||||
# content_type='application/json'
|
||||
# )
|
||||
# response = json.loads(r.content)
|
||||
# assert r.status_code == arg[1]
|
||||
# if r.status_code == 201:
|
||||
# assert response['recipe'] == recipe_1_s1.id
|
||||
# r = c.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
# assert r.status_code == 200
|
||||
# r = u2_s1.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
# assert r.status_code == 404
|
||||
# r = u1_s2.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
# assert r.status_code == 404
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 403],
|
||||
['g1_s1', 201],
|
||||
['u1_s1', 201],
|
||||
['a1_s1', 201],
|
||||
])
|
||||
def test_add(arg, request, u1_s2, u2_s1, recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
r = c.post(
|
||||
reverse(LIST_URL),
|
||||
{'recipe': recipe_1_s1.id},
|
||||
content_type='application/json'
|
||||
)
|
||||
assert r.status_code == arg[1]
|
||||
if r.status_code == 201:
|
||||
response = json.loads(r.content)
|
||||
assert response['recipe'] == recipe_1_s1.id
|
||||
r = c.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
assert r.status_code == 200
|
||||
r = u2_s1.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
assert r.status_code == 403 # expected value changed. user can list the log - detail should be 403 as no reason to 'hide' that it actually exists
|
||||
r = u1_s2.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_delete(u1_s1, u1_s2, obj_1):
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Keyword, CookLog, ViewLog, ImportLog
|
||||
from cookbook.models import ImportLog
|
||||
|
||||
LIST_URL = 'api:importlog-list'
|
||||
DETAIL_URL = 'api:importlog-detail'
|
||||
@@ -33,14 +33,14 @@ def test_list_permission(arg, request):
|
||||
|
||||
|
||||
def test_list_space(obj_1, obj_2, u1_s1, u1_s2, space_2):
|
||||
assert len(json.loads(u1_s1.get(reverse(LIST_URL)).content)) == 2
|
||||
assert len(json.loads(u1_s2.get(reverse(LIST_URL)).content)) == 0
|
||||
assert json.loads(u1_s1.get(reverse(LIST_URL)).content)['count'] == 2
|
||||
assert json.loads(u1_s2.get(reverse(LIST_URL)).content)['count'] == 0
|
||||
|
||||
obj_1.space = space_2
|
||||
obj_1.save()
|
||||
|
||||
assert len(json.loads(u1_s1.get(reverse(LIST_URL)).content)) == 1
|
||||
assert len(json.loads(u1_s2.get(reverse(LIST_URL)).content)) == 1
|
||||
assert json.loads(u1_s1.get(reverse(LIST_URL)).content)['count'] == 1
|
||||
assert json.loads(u1_s2.get(reverse(LIST_URL)).content)['count'] == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
|
||||
@@ -3,9 +3,8 @@ import json
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import RecipeBook, Storage, Sync, SyncLog
|
||||
from cookbook.models import Storage, Sync, SyncLog
|
||||
|
||||
LIST_URL = 'api:synclog-list'
|
||||
DETAIL_URL = 'api:synclog-detail'
|
||||
@@ -37,14 +36,14 @@ def test_list_permission(arg, request):
|
||||
|
||||
|
||||
def test_list_space(obj_1, obj_2, a1_s1, a1_s2, space_2):
|
||||
assert len(json.loads(a1_s1.get(reverse(LIST_URL)).content)) == 2
|
||||
assert len(json.loads(a1_s2.get(reverse(LIST_URL)).content)) == 0
|
||||
assert json.loads(a1_s1.get(reverse(LIST_URL)).content)['count'] == 2
|
||||
assert json.loads(a1_s2.get(reverse(LIST_URL)).content)['count'] == 0
|
||||
|
||||
obj_1.sync.space = space_2
|
||||
obj_1.sync.save()
|
||||
|
||||
assert len(json.loads(a1_s1.get(reverse(LIST_URL)).content)) == 1
|
||||
assert len(json.loads(a1_s2.get(reverse(LIST_URL)).content)) == 1
|
||||
assert json.loads(a1_s1.get(reverse(LIST_URL)).content)['count'] == 1
|
||||
assert json.loads(a1_s2.get(reverse(LIST_URL)).content)['count'] == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
@@ -82,7 +81,6 @@ def test_add(arg, request, a1_s2, obj_1):
|
||||
{'msg': 'test'},
|
||||
content_type='application/json'
|
||||
)
|
||||
response = json.loads(r.content)
|
||||
assert r.status_code == arg[1]
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Keyword, CookLog, ViewLog
|
||||
from cookbook.models import ViewLog
|
||||
|
||||
LIST_URL = 'api:viewlog-list'
|
||||
DETAIL_URL = 'api:viewlog-detail'
|
||||
@@ -33,14 +33,14 @@ def test_list_permission(arg, request):
|
||||
|
||||
|
||||
def test_list_space(obj_1, obj_2, u1_s1, u1_s2, space_2):
|
||||
assert len(json.loads(u1_s1.get(reverse(LIST_URL)).content)) == 2
|
||||
assert len(json.loads(u1_s2.get(reverse(LIST_URL)).content)) == 0
|
||||
assert json.loads(u1_s1.get(reverse(LIST_URL)).content)['count'] == 2
|
||||
assert json.loads(u1_s2.get(reverse(LIST_URL)).content)['count'] == 0
|
||||
|
||||
obj_1.space = space_2
|
||||
obj_1.save()
|
||||
|
||||
assert len(json.loads(u1_s1.get(reverse(LIST_URL)).content)) == 1
|
||||
assert len(json.loads(u1_s2.get(reverse(LIST_URL)).content)) == 0
|
||||
assert json.loads(u1_s1.get(reverse(LIST_URL)).content)['count'] == 1
|
||||
assert json.loads(u1_s2.get(reverse(LIST_URL)).content)['count'] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
@@ -52,6 +52,7 @@ def test_list_space(obj_1, obj_2, u1_s1, u1_s2, space_2):
|
||||
['u1_s2', 404],
|
||||
['a1_s2', 404],
|
||||
])
|
||||
# TODO: should logs be updateable at all?
|
||||
def test_update(arg, request, obj_1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
r = c.patch(
|
||||
@@ -65,31 +66,29 @@ def test_update(arg, request, obj_1):
|
||||
assert r.status_code == arg[1]
|
||||
|
||||
|
||||
# TODO disabled until https://github.com/vabene1111/recipes/issues/484
|
||||
|
||||
# @pytest.mark.parametrize("arg", [
|
||||
# ['a_u', 403],
|
||||
# ['g1_s1', 201],
|
||||
# ['u1_s1', 201],
|
||||
# ['a1_s1', 201],
|
||||
# ])
|
||||
# def test_add(arg, request, u1_s2, u2_s1, recipe_1_s1):
|
||||
# c = request.getfixturevalue(arg[0])
|
||||
# r = c.post(
|
||||
# reverse(LIST_URL),
|
||||
# {'recipe': recipe_1_s1.id},
|
||||
# content_type='application/json'
|
||||
# )
|
||||
# response = json.loads(r.content)
|
||||
# assert r.status_code == arg[1]
|
||||
# if r.status_code == 201:
|
||||
# assert response['recipe'] == recipe_1_s1.id
|
||||
# r = c.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
# assert r.status_code == 200
|
||||
# r = u2_s1.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
# assert r.status_code == 404
|
||||
# r = u1_s2.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
# assert r.status_code == 404
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 403],
|
||||
['g1_s1', 201],
|
||||
['u1_s1', 201],
|
||||
['a1_s1', 201],
|
||||
])
|
||||
def test_add(arg, request, u1_s2, u2_s1, recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
r = c.post(
|
||||
reverse(LIST_URL),
|
||||
{'recipe': recipe_1_s1.id},
|
||||
content_type='application/json'
|
||||
)
|
||||
response = json.loads(r.content)
|
||||
assert r.status_code == arg[1]
|
||||
if r.status_code == 201:
|
||||
assert response['recipe'] == recipe_1_s1.id
|
||||
r = c.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
assert r.status_code == 200
|
||||
r = u2_s1.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
assert r.status_code == 404
|
||||
r = u1_s2.get(reverse(DETAIL_URL, args={response['id']}))
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_delete(u1_s1, u1_s2, obj_1):
|
||||
|
||||
@@ -119,7 +119,6 @@ class FuzzyFilterMixin(ViewSetMixin):
|
||||
.filter(name__icontains=query).order_by('-exact')
|
||||
)
|
||||
|
||||
|
||||
updated_at = self.request.query_params.get('updated_at', None)
|
||||
if updated_at is not None:
|
||||
try:
|
||||
@@ -319,6 +318,7 @@ class SyncLogViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
queryset = SyncLog.objects
|
||||
serializer_class = SyncLogSerializer
|
||||
permission_classes = [CustomIsAdmin, ]
|
||||
pagination_class = DefaultPagination
|
||||
|
||||
def get_queryset(self):
|
||||
return self.queryset.filter(sync__space=self.request.space)
|
||||
@@ -598,35 +598,31 @@ class ViewLogViewSet(viewsets.ModelViewSet):
|
||||
queryset = ViewLog.objects
|
||||
serializer_class = ViewLogSerializer
|
||||
permission_classes = [CustomIsOwner]
|
||||
pagination_class = DefaultPagination
|
||||
|
||||
def get_queryset(self):
|
||||
self.queryset = self.queryset.filter(created_by=self.request.user).filter(space=self.request.space).all()
|
||||
if self.request.method == 'GET':
|
||||
return self.queryset[:5]
|
||||
else:
|
||||
return self.queryset
|
||||
# working backwards from the test - this is supposed to be limited to user view logs only??
|
||||
return self.queryset.filter(created_by=self.request.user).filter(space=self.request.space)
|
||||
|
||||
|
||||
class CookLogViewSet(viewsets.ModelViewSet):
|
||||
queryset = CookLog.objects
|
||||
serializer_class = CookLogSerializer
|
||||
permission_classes = [CustomIsOwner]
|
||||
permission_classes = [CustomIsOwner] # CustomIsShared? since ratings are in the cooklog?
|
||||
pagination_class = DefaultPagination
|
||||
|
||||
def get_queryset(self):
|
||||
self.queryset = self.queryset.filter(created_by=self.request.user).filter(space=self.request.space).all()
|
||||
if self.request.method == 'GET':
|
||||
return self.queryset[:5]
|
||||
else:
|
||||
return self.queryset
|
||||
return self.queryset.filter(space=self.request.space)
|
||||
|
||||
|
||||
class ImportLogViewSet(viewsets.ModelViewSet):
|
||||
queryset = ImportLog.objects
|
||||
serializer_class = ImportLogSerializer
|
||||
permission_classes = [CustomIsUser]
|
||||
pagination_class = DefaultPagination
|
||||
|
||||
def get_queryset(self):
|
||||
return self.queryset.filter(space=self.request.space).all()
|
||||
return self.queryset.filter(space=self.request.space)
|
||||
|
||||
|
||||
class BookmarkletImportViewSet(viewsets.ModelViewSet):
|
||||
|
||||
Reference in New Issue
Block a user