mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-12-03 16:24:01 +03:00
Address PR review feedback: update error message wording and example
- Change 'must be applied before' to 'must come after (below) the' to match DRF docs language - Fix decorator order in example to show @api_view first, then policy decorator below - Remove unnecessary f-string prefixes from non-interpolated lines - Update all test assertions to match new error message wording Addresses feedback from @browniebroke in PR #9821
This commit is contained in:
parent
17a2d44abc
commit
b8685f28b2
|
|
@ -94,13 +94,13 @@ def _check_decorator_order(func, decorator_name):
|
|||
# Check if func is actually a view function (result of APIView.as_view())
|
||||
if hasattr(func, 'cls') and issubclass(func.cls, APIView):
|
||||
raise TypeError(
|
||||
f"@{decorator_name} must be applied before @api_view. "
|
||||
f"The correct order is:\n\n"
|
||||
f" @api_view(['GET'])\n"
|
||||
f"@{decorator_name} must come after (below) the @api_view decorator. "
|
||||
"The correct order is:\n\n"
|
||||
" @api_view(['GET'])\n"
|
||||
f" @{decorator_name}(...)\n"
|
||||
f" def my_view(request):\n"
|
||||
f" ...\n\n"
|
||||
f"See https://www.django-rest-framework.org/api-guide/views/#api-policy-decorators"
|
||||
" def my_view(request):\n"
|
||||
" ...\n\n"
|
||||
"See https://www.django-rest-framework.org/api-guide/views/#api-policy-decorators"
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ class DecoratorTestCase(TestCase):
|
|||
def view(request):
|
||||
return Response({})
|
||||
|
||||
assert '@permission_classes must be applied before @api_view' in str(cm.exception)
|
||||
assert '@permission_classes must come after (below) the @api_view decorator' in str(cm.exception)
|
||||
|
||||
def test_incorrect_decorator_order_renderer_classes(self):
|
||||
"""
|
||||
|
|
@ -226,7 +226,7 @@ class DecoratorTestCase(TestCase):
|
|||
def view(request):
|
||||
return Response({})
|
||||
|
||||
assert '@renderer_classes must be applied before @api_view' in str(cm.exception)
|
||||
assert '@renderer_classes must come after (below) the @api_view decorator' in str(cm.exception)
|
||||
|
||||
def test_incorrect_decorator_order_parser_classes(self):
|
||||
"""
|
||||
|
|
@ -238,7 +238,7 @@ class DecoratorTestCase(TestCase):
|
|||
def view(request):
|
||||
return Response({})
|
||||
|
||||
assert '@parser_classes must be applied before @api_view' in str(cm.exception)
|
||||
assert '@parser_classes must come after (below) the @api_view decorator' in str(cm.exception)
|
||||
|
||||
def test_incorrect_decorator_order_authentication_classes(self):
|
||||
"""
|
||||
|
|
@ -250,7 +250,7 @@ class DecoratorTestCase(TestCase):
|
|||
def view(request):
|
||||
return Response({})
|
||||
|
||||
assert '@authentication_classes must be applied before @api_view' in str(cm.exception)
|
||||
assert '@authentication_classes must come after (below) the @api_view decorator' in str(cm.exception)
|
||||
|
||||
def test_incorrect_decorator_order_throttle_classes(self):
|
||||
"""
|
||||
|
|
@ -265,7 +265,7 @@ class DecoratorTestCase(TestCase):
|
|||
def view(request):
|
||||
return Response({})
|
||||
|
||||
assert '@throttle_classes must be applied before @api_view' in str(cm.exception)
|
||||
assert '@throttle_classes must come after (below) the @api_view decorator' in str(cm.exception)
|
||||
|
||||
def test_incorrect_decorator_order_versioning_class(self):
|
||||
"""
|
||||
|
|
@ -277,7 +277,7 @@ class DecoratorTestCase(TestCase):
|
|||
def view(request):
|
||||
return Response({})
|
||||
|
||||
assert '@versioning_class must be applied before @api_view' in str(cm.exception)
|
||||
assert '@versioning_class must come after (below) the @api_view decorator' in str(cm.exception)
|
||||
|
||||
def test_incorrect_decorator_order_metadata_class(self):
|
||||
"""
|
||||
|
|
@ -289,7 +289,7 @@ class DecoratorTestCase(TestCase):
|
|||
def view(request):
|
||||
return Response({})
|
||||
|
||||
assert '@metadata_class must be applied before @api_view' in str(cm.exception)
|
||||
assert '@metadata_class must come after (below) the @api_view decorator' in str(cm.exception)
|
||||
|
||||
def test_incorrect_decorator_order_content_negotiation_class(self):
|
||||
"""
|
||||
|
|
@ -305,7 +305,7 @@ class DecoratorTestCase(TestCase):
|
|||
def view(request):
|
||||
return Response({})
|
||||
|
||||
assert '@content_negotiation_class must be applied before @api_view' in str(cm.exception)
|
||||
assert '@content_negotiation_class must come after (below) the @api_view decorator' in str(cm.exception)
|
||||
|
||||
def test_incorrect_decorator_order_schema(self):
|
||||
"""
|
||||
|
|
@ -320,7 +320,7 @@ class DecoratorTestCase(TestCase):
|
|||
def view(request):
|
||||
return Response({})
|
||||
|
||||
assert '@schema must be applied before @api_view' in str(cm.exception)
|
||||
assert '@schema must come after (below) the @api_view decorator' in str(cm.exception)
|
||||
|
||||
|
||||
class ActionDecoratorTestCase(TestCase):
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user