From e0d4c45c475e2dd6de4c67eb8ae7c17abdd91837 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 10 Feb 2017 14:00:06 +0000 Subject: [PATCH] Update to latest version of coreapi --- requirements/requirements-optionals.txt | 4 +- rest_framework/filters.py | 13 +++++-- rest_framework/pagination.py | 5 ++- tests/test_api_client.py | 4 +- tests/test_schemas.py | 51 +++++++++++-------------- 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/requirements/requirements-optionals.txt b/requirements/requirements-optionals.txt index 74ea29477..c4882fead 100644 --- a/requirements/requirements-optionals.txt +++ b/requirements/requirements-optionals.txt @@ -2,5 +2,5 @@ markdown==2.6.4 django-guardian==1.4.6 django-filter==1.0.0 -coreapi==2.2.0 -coreschema==0.0.2 +coreapi==2.2.4 +coreschema==0.0.4 diff --git a/rest_framework/filters.py b/rest_framework/filters.py index db116efb0..e2698fa0a 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -13,6 +13,7 @@ from django.db import models from django.db.models.constants import LOOKUP_SEP from django.template import loader from django.utils import six +from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ from rest_framework.compat import ( @@ -83,6 +84,8 @@ class SearchFilter(BaseFilterBackend): '@': 'search', '$': 'iregex', } + search_title = _('Search') + search_description = _('A search term.') def get_search_terms(self, request): """ @@ -170,8 +173,8 @@ class SearchFilter(BaseFilterBackend): required=False, location='query', schema=coreschema.String( - title='Search', - description='...' + title=force_text(self.search_title), + description=force_text(self.search_description) ) ) ] @@ -181,6 +184,8 @@ class OrderingFilter(BaseFilterBackend): # The URL query parameter used for the ordering. ordering_param = api_settings.ORDERING_PARAM ordering_fields = None + ordering_title = _('Ordering') + ordering_description = _('Which field to use when ordering the results.') template = 'rest_framework/filters/ordering.html' def get_ordering(self, request, queryset, view): @@ -299,8 +304,8 @@ class OrderingFilter(BaseFilterBackend): required=False, location='query', schema=coreschema.String( - title='Ordering', - description='...' + title=force_text(self.ordering_title), + description=force_text(self.ordering_description) ) ) ] diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index f65da407f..100b31b71 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -307,7 +307,10 @@ class PageNumberPagination(BasePagination): name=self.page_size_query_param, required=False, location='query', - # description=force_text(self.page_size_query_description) + schema=coreschema.Integer( + title='Page size', + description=force_text(self.page_size_query_description) + ) ) ) return fields diff --git a/tests/test_api_client.py b/tests/test_api_client.py index 89ca0e58e..60c918701 100644 --- a/tests/test_api_client.py +++ b/tests/test_api_client.py @@ -7,9 +7,8 @@ import unittest from django.conf.urls import url from django.http import HttpResponse from django.test import override_settings -import coreschema -from rest_framework.compat import coreapi +from rest_framework.compat import coreapi, coreschema from rest_framework.parsers import FileUploadParser from rest_framework.renderers import CoreJSONRenderer from rest_framework.response import Response @@ -194,7 +193,6 @@ urlpatterns = [ @unittest.skipUnless(coreapi, 'coreapi not installed') @override_settings(ROOT_URLCONF='tests.test_api_client') class APIClientTests(APITestCase): - @unittest.expectedFailure def test_api_client(self): client = CoreAPIClient() schema = client.get('http://api.example.com/') diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 6b32f6f60..f75370170 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -4,10 +4,9 @@ from django.conf.urls import include, url from django.core.exceptions import PermissionDenied from django.http import Http404 from django.test import TestCase, override_settings -import coreschema from rest_framework import filters, pagination, permissions, serializers -from rest_framework.compat import coreapi +from rest_framework.compat import coreapi, coreschema from rest_framework.decorators import detail_route, list_route from rest_framework.request import Request from rest_framework.routers import DefaultRouter @@ -88,7 +87,6 @@ urlpatterns = [ @unittest.skipUnless(coreapi, 'coreapi is not installed') @override_settings(ROOT_URLCONF='tests.test_schemas') class TestRouterGeneratedSchema(TestCase): - @unittest.expectedFailure def test_anonymous_request(self): client = APIClient() response = client.get('/', HTTP_ACCEPT='application/coreapi+json') @@ -103,8 +101,8 @@ class TestRouterGeneratedSchema(TestCase): action='get', fields=[ coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')), - coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(description='Number of results to return per page.')), - coreapi.Field('ordering', required=False, location='query', schema=coreschema.Integer()) + coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')), + coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) ] ), 'custom_list_action': coreapi.Link( @@ -121,7 +119,7 @@ class TestRouterGeneratedSchema(TestCase): url='/example/{id}/', action='get', fields=[ - coreapi.Field('id', required=True, location='path') + coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] ) } @@ -129,7 +127,6 @@ class TestRouterGeneratedSchema(TestCase): ) assert response.data == expected - @unittest.expectedFailure def test_authenticated_request(self): client = APIClient() client.force_authenticate(MockUser()) @@ -145,8 +142,8 @@ class TestRouterGeneratedSchema(TestCase): action='get', fields=[ coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')), - coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(description='Number of results to return per page.')), - coreapi.Field('ordering', required=False, location='query', schema=coreschema.Integer()) + coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')), + coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) ] ), 'create': coreapi.Link( @@ -154,15 +151,15 @@ class TestRouterGeneratedSchema(TestCase): action='post', encoding='application/json', fields=[ - coreapi.Field('a', required=True, location='form', schema=coreschema.String(description='A field description')), - coreapi.Field('b', required=False, location='form', schema=coreschema.String()) + coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description='A field description')), + coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')) ] ), 'read': coreapi.Link( url='/example/{id}/', action='get', fields=[ - coreapi.Field('id', required=True, location='path') + coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] ), 'custom_action': coreapi.Link( @@ -171,9 +168,9 @@ class TestRouterGeneratedSchema(TestCase): encoding='application/json', description='A description of custom action.', fields=[ - coreapi.Field('id', required=True, location='path'), - coreapi.Field('c', required=True, location='form', schema=coreschema.String()), - coreapi.Field('d', required=False, location='form', schema=coreschema.String()), + coreapi.Field('id', required=True, location='path', schema=coreschema.String()), + coreapi.Field('c', required=True, location='form', schema=coreschema.String(title='C')), + coreapi.Field('d', required=False, location='form', schema=coreschema.String(title='D')), ] ), 'custom_list_action': coreapi.Link( @@ -195,9 +192,9 @@ class TestRouterGeneratedSchema(TestCase): action='put', encoding='application/json', fields=[ - coreapi.Field('id', required=True, location='path'), - coreapi.Field('a', required=True, location='form', schema=coreschema.String(description=('A field description'))), - coreapi.Field('b', required=False, location='form', schema=coreschema.String()) + coreapi.Field('id', required=True, location='path', schema=coreschema.String()), + coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description=('A field description'))), + coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')) ] ), 'partial_update': coreapi.Link( @@ -205,16 +202,16 @@ class TestRouterGeneratedSchema(TestCase): action='patch', encoding='application/json', fields=[ - coreapi.Field('id', required=True, location='path'), - coreapi.Field('a', required=False, location='form', schema=coreschema.String(description='A field description')), - coreapi.Field('b', required=False, location='form', schema=coreschema.String()) + coreapi.Field('id', required=True, location='path', schema=coreschema.String()), + coreapi.Field('a', required=False, location='form', schema=coreschema.String(title='A', description='A field description')), + coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')) ] ), 'delete': coreapi.Link( url='/example/{id}/', action='delete', fields=[ - coreapi.Field('id', required=True, location='path') + coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] ) } @@ -275,7 +272,6 @@ class TestSchemaGenerator(TestCase): url('^example/(?P\d+)/sub/?$', ExampleDetailView.as_view()), ] - @unittest.expectedFailure def test_schema_for_regular_views(self): """ Ensure that schema generation works for APIView classes. @@ -301,7 +297,7 @@ class TestSchemaGenerator(TestCase): url='/example/{id}/', action='get', fields=[ - coreapi.Field('id', required=True, location='path') + coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] ), 'sub': { @@ -309,7 +305,7 @@ class TestSchemaGenerator(TestCase): url='/example/{id}/sub/', action='get', fields=[ - coreapi.Field('id', required=True, location='path') + coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] ) } @@ -328,7 +324,6 @@ class TestSchemaGeneratorNotAtRoot(TestCase): url('^api/v1/example/(?P\d+)/sub/?$', ExampleDetailView.as_view()), ] - @unittest.expectedFailure def test_schema_for_regular_views(self): """ Ensure that schema generation with an API that is not at the URL @@ -355,7 +350,7 @@ class TestSchemaGeneratorNotAtRoot(TestCase): url='/api/v1/example/{id}/', action='get', fields=[ - coreapi.Field('id', required=True, location='path') + coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] ), 'sub': { @@ -363,7 +358,7 @@ class TestSchemaGeneratorNotAtRoot(TestCase): url='/api/v1/example/{id}/sub/', action='get', fields=[ - coreapi.Field('id', required=True, location='path') + coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] ) }