mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Make 'detail' a required argument of 'action'
This commit is contained in:
parent
2112a58282
commit
40ab128b1a
|
@ -130,7 +130,7 @@ def schema(view_inspector):
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def action(methods=None, detail=True, url_path=None, url_name=None, **kwargs):
|
def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Mark a ViewSet method as a routable action.
|
Mark a ViewSet method as a routable action.
|
||||||
|
|
||||||
|
@ -140,6 +140,10 @@ def action(methods=None, detail=True, url_path=None, url_name=None, **kwargs):
|
||||||
methods = ['get'] if (methods is None) else methods
|
methods = ['get'] if (methods is None) else methods
|
||||||
methods = [method.lower() for method in methods]
|
methods = [method.lower() for method in methods]
|
||||||
|
|
||||||
|
assert detail is not None, (
|
||||||
|
"@action() missing required argument: 'detail'"
|
||||||
|
)
|
||||||
|
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
func.bind_to_methods = methods
|
func.bind_to_methods = methods
|
||||||
func.detail = detail
|
func.detail = detail
|
||||||
|
|
|
@ -173,7 +173,7 @@ class DecoratorTestCase(TestCase):
|
||||||
class ActionDecoratorTestCase(TestCase):
|
class ActionDecoratorTestCase(TestCase):
|
||||||
|
|
||||||
def test_defaults(self):
|
def test_defaults(self):
|
||||||
@action()
|
@action(detail=True)
|
||||||
def test_action(request):
|
def test_action(request):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -182,6 +182,14 @@ class ActionDecoratorTestCase(TestCase):
|
||||||
assert test_action.url_path == 'test_action'
|
assert test_action.url_path == 'test_action'
|
||||||
assert test_action.url_name == 'test-action'
|
assert test_action.url_name == 'test-action'
|
||||||
|
|
||||||
|
def test_detail_required(self):
|
||||||
|
with pytest.raises(AssertionError) as excinfo:
|
||||||
|
@action()
|
||||||
|
def test_action(request):
|
||||||
|
pass
|
||||||
|
|
||||||
|
assert str(excinfo.value) == "@action() missing required argument: 'detail'"
|
||||||
|
|
||||||
def test_detail_route_deprecation(self):
|
def test_detail_route_deprecation(self):
|
||||||
with pytest.warns(PendingDeprecationWarning) as record:
|
with pytest.warns(PendingDeprecationWarning) as record:
|
||||||
@detail_route()
|
@detail_route()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user