added test to check for API pagination

This commit is contained in:
smilerz
2024-03-28 17:39:06 -05:00
parent f47c806ebd
commit e99ff005d6
5 changed files with 26 additions and 6 deletions

1
.gitignore vendored
View File

@@ -80,7 +80,6 @@ data/
/docker-compose.override.yml
vue/node_modules
/recipes/plugins
.vscode/
vetur.config.js
cookbook/static/vue
vue/webpack-stats.json

2
.vscode/launch.json vendored
View File

@@ -24,7 +24,7 @@
"console": "integratedTerminal",
"env": {
// coverage and pytest can't both be running at the same time
"PYTEST_ADDOPTS": "--no-cov"
"PYTEST_ADDOPTS": "--no-cov -n 0"
},
"django": true,
"justMyCode": true

View File

@@ -3,8 +3,8 @@ from django.contrib import auth
from mock.mock import Mock
from cookbook.connectors.connector import Connector
from cookbook.connectors.connector_manager import run_connectors, ActionType
from cookbook.models import ShoppingListEntry, Food
from cookbook.connectors.connector_manager import ActionType, run_connectors
from cookbook.models import Food, ShoppingListEntry
@pytest.fixture()
@@ -13,7 +13,7 @@ def obj_1(space_1, u1_s1):
return e
@pytest.mark.timeout(10)
@pytest.mark.timeout(10) # TODO this mark doesn't exist
@pytest.mark.asyncio
async def test_run_connectors(space_1, u1_s1, obj_1) -> None:
connector_mock = Mock(spec=Connector)

View File

@@ -0,0 +1,19 @@
import pytest
from cookbook.urls import router
exclude_endpoints = []
@pytest.mark.parametrize("route", router.registry)
def test_pagination_exists(route):
# route[0] = name
# route[1] = ViewSet class
# route[2] = reverse name
assert ('get' not in route[1].http_method_names
or 'get' in route[1].http_method_names and hasattr(route[1], 'pagination_class') and route[1].pagination_class is not None), f"API {route[0]} is not paginated."
def test_schema_completeness():
pass

View File

@@ -631,7 +631,7 @@ class FoodViewSet(TreeMixin):
food.properties_food_unit = Unit.objects.get_or_create(
base_unit__iexact='g',
space=self.request.space,
defaults={ 'name': 'g', 'base_unit': 'g', 'space': self.request.space}
defaults={'name': 'g', 'base_unit': 'g', 'space': self.request.space}
)[0]
food.save()
@@ -776,6 +776,7 @@ class MealPlanViewSet(viewsets.ModelViewSet):
class AutoPlanViewSet(viewsets.ViewSet):
http_method_names = ['post', 'options']
def create(self, request):
serializer = AutoMealPlanSerializer(data=request.data)
@@ -1693,6 +1694,7 @@ def share_link(request, pk):
return JsonResponse({'error': 'sharing_disabled'}, status=403)
# TODO does this need to be seperate from the Cooklog API?
@group_required('user')
@ajax_request
def log_cooking(request, recipe_id):