mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 04:20:12 +03:00
Add test for AutoSchema on detail_route (#5630)
This commit is contained in:
parent
743fc247eb
commit
e2793aced1
|
@ -7,7 +7,7 @@ from django.http import Http404
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
|
||||||
from rest_framework import (
|
from rest_framework import (
|
||||||
filters, generics, pagination, permissions, serializers
|
filters, generics, pagination, permissions, serializers, routers
|
||||||
)
|
)
|
||||||
from rest_framework.compat import coreapi, coreschema, get_regex_pattern
|
from rest_framework.compat import coreapi, coreschema, get_regex_pattern
|
||||||
from rest_framework.decorators import (
|
from rest_framework.decorators import (
|
||||||
|
@ -547,6 +547,33 @@ class TestDescriptor(TestCase):
|
||||||
assert len(fields) == 2
|
assert len(fields) == 2
|
||||||
assert "my_extra_field" in [f.name for f in fields]
|
assert "my_extra_field" in [f.name for f in fields]
|
||||||
|
|
||||||
|
def test_detail_route(self):
|
||||||
|
|
||||||
|
class AViewSet(GenericViewSet):
|
||||||
|
@detail_route(schema=AutoSchema(manual_fields=[
|
||||||
|
coreapi.Field(
|
||||||
|
"my_extra_field",
|
||||||
|
required=True,
|
||||||
|
location="path",
|
||||||
|
schema=coreschema.String()
|
||||||
|
),
|
||||||
|
]))
|
||||||
|
def a_detail_route(self, request, my_normal_field):
|
||||||
|
pass
|
||||||
|
|
||||||
|
router = routers.SimpleRouter()
|
||||||
|
router.register(r'detail', AViewSet, base_name='detail')
|
||||||
|
routes = router.urls
|
||||||
|
|
||||||
|
callback = routes[0].callback
|
||||||
|
generator = SchemaGenerator()
|
||||||
|
view = generator.create_view(callback, 'GET')
|
||||||
|
link = view.schema.get_link('/a/url/{id}/', 'GET', '')
|
||||||
|
fields = link.fields
|
||||||
|
|
||||||
|
assert len(fields) == 2
|
||||||
|
assert "my_extra_field" in [f.name for f in fields]
|
||||||
|
|
||||||
def test_view_with_manual_schema(self):
|
def test_view_with_manual_schema(self):
|
||||||
|
|
||||||
path = '/example'
|
path = '/example'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user