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:
Samiul Sk 2025-11-07 11:58:20 +05:30
parent 17a2d44abc
commit b8685f28b2
2 changed files with 15 additions and 15 deletions

View File

@ -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"
)

View File

@ -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):