Updated list_route() and detail_route() deprecations.

This commit is contained in:
Carlton Gibson 2018-10-02 11:59:10 +02:00
parent 7fb11bf2f5
commit cfd73825a8
4 changed files with 13 additions and 14 deletions

View File

@ -223,9 +223,9 @@ def detail_route(methods=None, **kwargs):
Used to mark a method on a ViewSet that should be routed for detail requests. Used to mark a method on a ViewSet that should be routed for detail requests.
""" """
warnings.warn( warnings.warn(
"`detail_route` is pending deprecation and will be removed in 3.10 in favor of " "`detail_route` is deprecated and will be removed in 3.10 in favor of "
"`action`, which accepts a `detail` bool. Use `@action(detail=True)` instead.", "`action`, which accepts a `detail` bool. Use `@action(detail=True)` instead.",
PendingDeprecationWarning, stacklevel=2 DeprecationWarning, stacklevel=2
) )
def decorator(func): def decorator(func):
@ -241,9 +241,9 @@ def list_route(methods=None, **kwargs):
Used to mark a method on a ViewSet that should be routed for list requests. Used to mark a method on a ViewSet that should be routed for list requests.
""" """
warnings.warn( warnings.warn(
"`list_route` is pending deprecation and will be removed in 3.10 in favor of " "`list_route` is deprecated and will be removed in 3.10 in favor of "
"`action`, which accepts a `detail` bool. Use `@action(detail=False)` instead.", "`action`, which accepts a `detail` bool. Use `@action(detail=False)` instead.",
PendingDeprecationWarning, stacklevel=2 DeprecationWarning, stacklevel=2
) )
def decorator(func): def decorator(func):

View File

@ -40,10 +40,10 @@ DynamicRoute = namedtuple('DynamicRoute', ['url', 'name', 'detail', 'initkwargs'
class DynamicDetailRoute(object): class DynamicDetailRoute(object):
def __new__(cls, url, name, initkwargs): def __new__(cls, url, name, initkwargs):
warnings.warn( warnings.warn(
"`DynamicDetailRoute` is pending deprecation and will be removed in 3.10 " "`DynamicDetailRoute` is deprecated and will be removed in 3.10 "
"in favor of `DynamicRoute`, which accepts a `detail` boolean. Use " "in favor of `DynamicRoute`, which accepts a `detail` boolean. Use "
"`DynamicRoute(url, name, True, initkwargs)` instead.", "`DynamicRoute(url, name, True, initkwargs)` instead.",
PendingDeprecationWarning, stacklevel=2 DeprecationWarning, stacklevel=2
) )
return DynamicRoute(url, name, True, initkwargs) return DynamicRoute(url, name, True, initkwargs)
@ -51,10 +51,10 @@ class DynamicDetailRoute(object):
class DynamicListRoute(object): class DynamicListRoute(object):
def __new__(cls, url, name, initkwargs): def __new__(cls, url, name, initkwargs):
warnings.warn( warnings.warn(
"`DynamicListRoute` is pending deprecation and will be removed in 3.10 in " "`DynamicListRoute` is deprecated and will be removed in 3.10 in "
"favor of `DynamicRoute`, which accepts a `detail` boolean. Use " "favor of `DynamicRoute`, which accepts a `detail` boolean. Use "
"`DynamicRoute(url, name, False, initkwargs)` instead.", "`DynamicRoute(url, name, False, initkwargs)` instead.",
PendingDeprecationWarning, stacklevel=2 DeprecationWarning, stacklevel=2
) )
return DynamicRoute(url, name, False, initkwargs) return DynamicRoute(url, name, False, initkwargs)

View File

@ -4,7 +4,6 @@ generators.py # Top-down schema generation
See schemas.__init__.py for package overview. See schemas.__init__.py for package overview.
""" """
import re import re
import warnings
from collections import Counter, OrderedDict from collections import Counter, OrderedDict
from importlib import import_module from importlib import import_module

View File

@ -290,34 +290,34 @@ class ActionDecoratorTestCase(TestCase):
raise NotImplementedError raise NotImplementedError
def test_detail_route_deprecation(self): def test_detail_route_deprecation(self):
with pytest.warns(PendingDeprecationWarning) as record: with pytest.warns(DeprecationWarning) as record:
@detail_route() @detail_route()
def view(request): def view(request):
raise NotImplementedError raise NotImplementedError
assert len(record) == 1 assert len(record) == 1
assert str(record[0].message) == ( assert str(record[0].message) == (
"`detail_route` is pending deprecation and will be removed in " "`detail_route` is deprecated and will be removed in "
"3.10 in favor of `action`, which accepts a `detail` bool. Use " "3.10 in favor of `action`, which accepts a `detail` bool. Use "
"`@action(detail=True)` instead." "`@action(detail=True)` instead."
) )
def test_list_route_deprecation(self): def test_list_route_deprecation(self):
with pytest.warns(PendingDeprecationWarning) as record: with pytest.warns(DeprecationWarning) as record:
@list_route() @list_route()
def view(request): def view(request):
raise NotImplementedError raise NotImplementedError
assert len(record) == 1 assert len(record) == 1
assert str(record[0].message) == ( assert str(record[0].message) == (
"`list_route` is pending deprecation and will be removed in " "`list_route` is deprecated and will be removed in "
"3.10 in favor of `action`, which accepts a `detail` bool. Use " "3.10 in favor of `action`, which accepts a `detail` bool. Use "
"`@action(detail=False)` instead." "`@action(detail=False)` instead."
) )
def test_route_url_name_from_path(self): def test_route_url_name_from_path(self):
# pre-3.8 behavior was to base the `url_name` off of the `url_path` # pre-3.8 behavior was to base the `url_name` off of the `url_path`
with pytest.warns(PendingDeprecationWarning): with pytest.warns(DeprecationWarning):
@list_route(url_path='foo_bar') @list_route(url_path='foo_bar')
def view(request): def view(request):
raise NotImplementedError raise NotImplementedError