mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-06 21:33:34 +03:00
Merge e0c2e6fdc2
into 3038494705
This commit is contained in:
commit
10a8baea83
|
@ -70,6 +70,9 @@ def api_view(http_method_names=None):
|
||||||
WrappedAPIView.permission_classes = getattr(func, 'permission_classes',
|
WrappedAPIView.permission_classes = getattr(func, 'permission_classes',
|
||||||
APIView.permission_classes)
|
APIView.permission_classes)
|
||||||
|
|
||||||
|
WrappedAPIView.versioning_class = getattr(func, "versioning_class",
|
||||||
|
APIView.versioning_class)
|
||||||
|
|
||||||
WrappedAPIView.schema = getattr(func, 'schema',
|
WrappedAPIView.schema = getattr(func, 'schema',
|
||||||
APIView.schema)
|
APIView.schema)
|
||||||
|
|
||||||
|
@ -113,6 +116,13 @@ def permission_classes(permission_classes):
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
def versioning_class(versioning_class):
|
||||||
|
def decorator(func):
|
||||||
|
func.versioning_class = versioning_class
|
||||||
|
return func
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def schema(view_inspector):
|
def schema(view_inspector):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
func.schema = view_inspector
|
func.schema = view_inspector
|
||||||
|
|
|
@ -7,7 +7,8 @@ from rest_framework import status
|
||||||
from rest_framework.authentication import BasicAuthentication
|
from rest_framework.authentication import BasicAuthentication
|
||||||
from rest_framework.decorators import (
|
from rest_framework.decorators import (
|
||||||
action, api_view, authentication_classes, parser_classes,
|
action, api_view, authentication_classes, parser_classes,
|
||||||
permission_classes, renderer_classes, schema, throttle_classes
|
permission_classes, renderer_classes, schema, throttle_classes,
|
||||||
|
versioning_class
|
||||||
)
|
)
|
||||||
from rest_framework.parsers import JSONParser
|
from rest_framework.parsers import JSONParser
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
@ -16,6 +17,7 @@ from rest_framework.response import Response
|
||||||
from rest_framework.schemas import AutoSchema
|
from rest_framework.schemas import AutoSchema
|
||||||
from rest_framework.test import APIRequestFactory
|
from rest_framework.test import APIRequestFactory
|
||||||
from rest_framework.throttling import UserRateThrottle
|
from rest_framework.throttling import UserRateThrottle
|
||||||
|
from rest_framework.versioning import QueryParameterVersioning
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,6 +152,16 @@ class DecoratorTestCase(TestCase):
|
||||||
response = view(request)
|
response = view(request)
|
||||||
assert response.status_code == status.HTTP_429_TOO_MANY_REQUESTS
|
assert response.status_code == status.HTTP_429_TOO_MANY_REQUESTS
|
||||||
|
|
||||||
|
def test_versioning_class(self):
|
||||||
|
@api_view(["GET"])
|
||||||
|
@versioning_class(QueryParameterVersioning)
|
||||||
|
def view(request):
|
||||||
|
return Response({"version": request.version})
|
||||||
|
|
||||||
|
request = self.factory.get("/?version=1.2.3")
|
||||||
|
response = view(request)
|
||||||
|
assert response.data == {"version": "1.2.3"}
|
||||||
|
|
||||||
def test_schema(self):
|
def test_schema(self):
|
||||||
"""
|
"""
|
||||||
Checks CustomSchema class is set on view
|
Checks CustomSchema class is set on view
|
||||||
|
|
Loading…
Reference in New Issue
Block a user