mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
Update to latest version of coreapi
This commit is contained in:
parent
b9a9d02162
commit
e0d4c45c47
|
@ -2,5 +2,5 @@
|
||||||
markdown==2.6.4
|
markdown==2.6.4
|
||||||
django-guardian==1.4.6
|
django-guardian==1.4.6
|
||||||
django-filter==1.0.0
|
django-filter==1.0.0
|
||||||
coreapi==2.2.0
|
coreapi==2.2.4
|
||||||
coreschema==0.0.2
|
coreschema==0.0.4
|
||||||
|
|
|
@ -13,6 +13,7 @@ from django.db import models
|
||||||
from django.db.models.constants import LOOKUP_SEP
|
from django.db.models.constants import LOOKUP_SEP
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
from django.utils.encoding import force_text
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from rest_framework.compat import (
|
from rest_framework.compat import (
|
||||||
|
@ -83,6 +84,8 @@ class SearchFilter(BaseFilterBackend):
|
||||||
'@': 'search',
|
'@': 'search',
|
||||||
'$': 'iregex',
|
'$': 'iregex',
|
||||||
}
|
}
|
||||||
|
search_title = _('Search')
|
||||||
|
search_description = _('A search term.')
|
||||||
|
|
||||||
def get_search_terms(self, request):
|
def get_search_terms(self, request):
|
||||||
"""
|
"""
|
||||||
|
@ -170,8 +173,8 @@ class SearchFilter(BaseFilterBackend):
|
||||||
required=False,
|
required=False,
|
||||||
location='query',
|
location='query',
|
||||||
schema=coreschema.String(
|
schema=coreschema.String(
|
||||||
title='Search',
|
title=force_text(self.search_title),
|
||||||
description='...'
|
description=force_text(self.search_description)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
@ -181,6 +184,8 @@ class OrderingFilter(BaseFilterBackend):
|
||||||
# The URL query parameter used for the ordering.
|
# The URL query parameter used for the ordering.
|
||||||
ordering_param = api_settings.ORDERING_PARAM
|
ordering_param = api_settings.ORDERING_PARAM
|
||||||
ordering_fields = None
|
ordering_fields = None
|
||||||
|
ordering_title = _('Ordering')
|
||||||
|
ordering_description = _('Which field to use when ordering the results.')
|
||||||
template = 'rest_framework/filters/ordering.html'
|
template = 'rest_framework/filters/ordering.html'
|
||||||
|
|
||||||
def get_ordering(self, request, queryset, view):
|
def get_ordering(self, request, queryset, view):
|
||||||
|
@ -299,8 +304,8 @@ class OrderingFilter(BaseFilterBackend):
|
||||||
required=False,
|
required=False,
|
||||||
location='query',
|
location='query',
|
||||||
schema=coreschema.String(
|
schema=coreschema.String(
|
||||||
title='Ordering',
|
title=force_text(self.ordering_title),
|
||||||
description='...'
|
description=force_text(self.ordering_description)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
|
@ -307,7 +307,10 @@ class PageNumberPagination(BasePagination):
|
||||||
name=self.page_size_query_param,
|
name=self.page_size_query_param,
|
||||||
required=False,
|
required=False,
|
||||||
location='query',
|
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
|
return fields
|
||||||
|
|
|
@ -7,9 +7,8 @@ import unittest
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.test import override_settings
|
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.parsers import FileUploadParser
|
||||||
from rest_framework.renderers import CoreJSONRenderer
|
from rest_framework.renderers import CoreJSONRenderer
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
@ -194,7 +193,6 @@ urlpatterns = [
|
||||||
@unittest.skipUnless(coreapi, 'coreapi not installed')
|
@unittest.skipUnless(coreapi, 'coreapi not installed')
|
||||||
@override_settings(ROOT_URLCONF='tests.test_api_client')
|
@override_settings(ROOT_URLCONF='tests.test_api_client')
|
||||||
class APIClientTests(APITestCase):
|
class APIClientTests(APITestCase):
|
||||||
@unittest.expectedFailure
|
|
||||||
def test_api_client(self):
|
def test_api_client(self):
|
||||||
client = CoreAPIClient()
|
client = CoreAPIClient()
|
||||||
schema = client.get('http://api.example.com/')
|
schema = client.get('http://api.example.com/')
|
||||||
|
|
|
@ -4,10 +4,9 @@ from django.conf.urls import include, url
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
import coreschema
|
|
||||||
|
|
||||||
from rest_framework import filters, pagination, permissions, serializers
|
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.decorators import detail_route, list_route
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
@ -88,7 +87,6 @@ urlpatterns = [
|
||||||
@unittest.skipUnless(coreapi, 'coreapi is not installed')
|
@unittest.skipUnless(coreapi, 'coreapi is not installed')
|
||||||
@override_settings(ROOT_URLCONF='tests.test_schemas')
|
@override_settings(ROOT_URLCONF='tests.test_schemas')
|
||||||
class TestRouterGeneratedSchema(TestCase):
|
class TestRouterGeneratedSchema(TestCase):
|
||||||
@unittest.expectedFailure
|
|
||||||
def test_anonymous_request(self):
|
def test_anonymous_request(self):
|
||||||
client = APIClient()
|
client = APIClient()
|
||||||
response = client.get('/', HTTP_ACCEPT='application/coreapi+json')
|
response = client.get('/', HTTP_ACCEPT='application/coreapi+json')
|
||||||
|
@ -103,8 +101,8 @@ class TestRouterGeneratedSchema(TestCase):
|
||||||
action='get',
|
action='get',
|
||||||
fields=[
|
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', 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('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.Integer())
|
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(
|
'custom_list_action': coreapi.Link(
|
||||||
|
@ -121,7 +119,7 @@ class TestRouterGeneratedSchema(TestCase):
|
||||||
url='/example/{id}/',
|
url='/example/{id}/',
|
||||||
action='get',
|
action='get',
|
||||||
fields=[
|
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
|
assert response.data == expected
|
||||||
|
|
||||||
@unittest.expectedFailure
|
|
||||||
def test_authenticated_request(self):
|
def test_authenticated_request(self):
|
||||||
client = APIClient()
|
client = APIClient()
|
||||||
client.force_authenticate(MockUser())
|
client.force_authenticate(MockUser())
|
||||||
|
@ -145,8 +142,8 @@ class TestRouterGeneratedSchema(TestCase):
|
||||||
action='get',
|
action='get',
|
||||||
fields=[
|
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', 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('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.Integer())
|
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'create': coreapi.Link(
|
'create': coreapi.Link(
|
||||||
|
@ -154,15 +151,15 @@ class TestRouterGeneratedSchema(TestCase):
|
||||||
action='post',
|
action='post',
|
||||||
encoding='application/json',
|
encoding='application/json',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('a', required=True, location='form', schema=coreschema.String(description='A field description')),
|
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())
|
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B'))
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'read': coreapi.Link(
|
'read': coreapi.Link(
|
||||||
url='/example/{id}/',
|
url='/example/{id}/',
|
||||||
action='get',
|
action='get',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('id', required=True, location='path')
|
coreapi.Field('id', required=True, location='path', schema=coreschema.String())
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'custom_action': coreapi.Link(
|
'custom_action': coreapi.Link(
|
||||||
|
@ -171,9 +168,9 @@ class TestRouterGeneratedSchema(TestCase):
|
||||||
encoding='application/json',
|
encoding='application/json',
|
||||||
description='A description of custom action.',
|
description='A description of custom action.',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('id', required=True, location='path'),
|
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
|
||||||
coreapi.Field('c', required=True, location='form', 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()),
|
coreapi.Field('d', required=False, location='form', schema=coreschema.String(title='D')),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'custom_list_action': coreapi.Link(
|
'custom_list_action': coreapi.Link(
|
||||||
|
@ -195,9 +192,9 @@ class TestRouterGeneratedSchema(TestCase):
|
||||||
action='put',
|
action='put',
|
||||||
encoding='application/json',
|
encoding='application/json',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('id', required=True, location='path'),
|
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
|
||||||
coreapi.Field('a', required=True, location='form', schema=coreschema.String(description=('A field description'))),
|
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())
|
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B'))
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'partial_update': coreapi.Link(
|
'partial_update': coreapi.Link(
|
||||||
|
@ -205,16 +202,16 @@ class TestRouterGeneratedSchema(TestCase):
|
||||||
action='patch',
|
action='patch',
|
||||||
encoding='application/json',
|
encoding='application/json',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('id', required=True, location='path'),
|
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
|
||||||
coreapi.Field('a', required=False, location='form', schema=coreschema.String(description='A field description')),
|
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())
|
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B'))
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'delete': coreapi.Link(
|
'delete': coreapi.Link(
|
||||||
url='/example/{id}/',
|
url='/example/{id}/',
|
||||||
action='delete',
|
action='delete',
|
||||||
fields=[
|
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<pk>\d+)/sub/?$', ExampleDetailView.as_view()),
|
url('^example/(?P<pk>\d+)/sub/?$', ExampleDetailView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
@unittest.expectedFailure
|
|
||||||
def test_schema_for_regular_views(self):
|
def test_schema_for_regular_views(self):
|
||||||
"""
|
"""
|
||||||
Ensure that schema generation works for APIView classes.
|
Ensure that schema generation works for APIView classes.
|
||||||
|
@ -301,7 +297,7 @@ class TestSchemaGenerator(TestCase):
|
||||||
url='/example/{id}/',
|
url='/example/{id}/',
|
||||||
action='get',
|
action='get',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('id', required=True, location='path')
|
coreapi.Field('id', required=True, location='path', schema=coreschema.String())
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'sub': {
|
'sub': {
|
||||||
|
@ -309,7 +305,7 @@ class TestSchemaGenerator(TestCase):
|
||||||
url='/example/{id}/sub/',
|
url='/example/{id}/sub/',
|
||||||
action='get',
|
action='get',
|
||||||
fields=[
|
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<pk>\d+)/sub/?$', ExampleDetailView.as_view()),
|
url('^api/v1/example/(?P<pk>\d+)/sub/?$', ExampleDetailView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
@unittest.expectedFailure
|
|
||||||
def test_schema_for_regular_views(self):
|
def test_schema_for_regular_views(self):
|
||||||
"""
|
"""
|
||||||
Ensure that schema generation with an API that is not at the URL
|
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}/',
|
url='/api/v1/example/{id}/',
|
||||||
action='get',
|
action='get',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('id', required=True, location='path')
|
coreapi.Field('id', required=True, location='path', schema=coreschema.String())
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'sub': {
|
'sub': {
|
||||||
|
@ -363,7 +358,7 @@ class TestSchemaGeneratorNotAtRoot(TestCase):
|
||||||
url='/api/v1/example/{id}/sub/',
|
url='/api/v1/example/{id}/sub/',
|
||||||
action='get',
|
action='get',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('id', required=True, location='path')
|
coreapi.Field('id', required=True, location='path', schema=coreschema.String())
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user