mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 17:36:49 +01:00
Fix API v1 tests
We're updated the BlogEntryPage model to use class-based api_fields but API v1 doesn't support them. This commit adds enough compatibility to make the v1 API tests work but issues a warning if the v1 API module encounters any new style configs that it doesn't support.
This commit is contained in:
parent
726e85f4a6
commit
12fa1ebee8
@ -1,5 +1,6 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import warnings
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.conf.urls import url
|
||||
@ -10,6 +11,7 @@ from rest_framework.renderers import BrowsableAPIRenderer, JSONRenderer
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
|
||||
from wagtail.api import APIField
|
||||
from wagtail.wagtailcore.models import Page
|
||||
from wagtail.wagtailcore.utils import resolve_model_string
|
||||
from wagtail.wagtaildocs.models import get_document_model
|
||||
@ -80,7 +82,23 @@ class BaseAPIEndpoint(GenericViewSet):
|
||||
if hasattr(model, 'api_fields'):
|
||||
api_fields.extend(model.api_fields)
|
||||
|
||||
return api_fields
|
||||
# Remove any new-style API field configs (only supported in v2)
|
||||
def convert_api_fields(fields):
|
||||
for field in fields:
|
||||
if isinstance(field, APIField):
|
||||
warnings.warn(
|
||||
"class-based api_fields are not supported by the v1 API module. "
|
||||
"Please update the .api_fields attribute of {}.{} or update to the "
|
||||
"v2 API.".format(model._meta.app_label, model.__name__)
|
||||
)
|
||||
|
||||
# Ignore fields with custom serializers
|
||||
if field.serializer is None:
|
||||
yield field.name
|
||||
else:
|
||||
yield field
|
||||
|
||||
return list(convert_api_fields(api_fields))
|
||||
|
||||
def check_query_parameters(self, queryset):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user