Skip to content

Add missing decorator: @versioning_class() #9719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rest_framework/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def handler(self, *args, **kwargs):
WrappedAPIView.permission_classes = getattr(func, 'permission_classes',
APIView.permission_classes)

WrappedAPIView.versioning_class = getattr(func, "versioning_class",
APIView.versioning_class)

WrappedAPIView.schema = getattr(func, 'schema',
APIView.schema)

Expand Down Expand Up @@ -113,6 +116,13 @@ def decorator(func):
return decorator


def versioning_class(versioning_class):
def decorator(func):
func.versioning_class = versioning_class
return func
return decorator


def schema(view_inspector):
def decorator(func):
func.schema = view_inspector
Expand Down
14 changes: 13 additions & 1 deletion tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from rest_framework.authentication import BasicAuthentication
from rest_framework.decorators import (
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.permissions import IsAuthenticated
Expand All @@ -16,6 +17,7 @@
from rest_framework.schemas import AutoSchema
from rest_framework.test import APIRequestFactory
from rest_framework.throttling import UserRateThrottle
from rest_framework.versioning import QueryParameterVersioning
from rest_framework.views import APIView


Expand Down Expand Up @@ -150,6 +152,16 @@ def view(request):
response = view(request)
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):
"""
Checks CustomSchema class is set on view
Expand Down
Loading