From 11fe6a199fb4cfa3078a12e62a763d0c3e28b602 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Mon, 20 May 2019 20:11:39 -0700 Subject: [PATCH] Remove detail_route/list_route --- rest_framework/decorators.py | 38 ------------------------------- rest_framework/routers.py | 26 +--------------------- tests/test_decorators.py | 43 +++--------------------------------- 3 files changed, 4 insertions(+), 103 deletions(-) diff --git a/rest_framework/decorators.py b/rest_framework/decorators.py index 5d7bd14a3..671754fa1 100644 --- a/rest_framework/decorators.py +++ b/rest_framework/decorators.py @@ -7,11 +7,9 @@ based views, as well as the `@detail_route` and `@list_route` decorators, which used to annotate methods on viewsets that should be included by routers. """ import types -import warnings from django.forms.utils import pretty_name -from rest_framework import RemovedInDRF310Warning from rest_framework.views import APIView @@ -214,39 +212,3 @@ class MethodMapper(dict): def trace(self, func): return self._map('trace', func) - - -def detail_route(methods=None, **kwargs): - """ - Used to mark a method on a ViewSet that should be routed for detail requests. - """ - warnings.warn( - "`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.", - RemovedInDRF310Warning, stacklevel=2 - ) - - def decorator(func): - func = action(methods, detail=True, **kwargs)(func) - if 'url_name' not in kwargs: - func.url_name = func.url_path.replace('_', '-') - return func - return decorator - - -def list_route(methods=None, **kwargs): - """ - Used to mark a method on a ViewSet that should be routed for list requests. - """ - warnings.warn( - "`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.", - RemovedInDRF310Warning, stacklevel=2 - ) - - def decorator(func): - func = action(methods, detail=False, **kwargs)(func) - if 'url_name' not in kwargs: - func.url_name = func.url_path.replace('_', '-') - return func - return decorator diff --git a/rest_framework/routers.py b/rest_framework/routers.py index 9334706f8..ee5760e81 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -22,9 +22,7 @@ from django.core.exceptions import ImproperlyConfigured from django.urls import NoReverseMatch from django.utils.deprecation import RenameMethodsBase -from rest_framework import ( - RemovedInDRF310Warning, RemovedInDRF311Warning, views -) +from rest_framework import RemovedInDRF311Warning, views from rest_framework.response import Response from rest_framework.reverse import reverse from rest_framework.schemas import SchemaGenerator @@ -36,28 +34,6 @@ Route = namedtuple('Route', ['url', 'mapping', 'name', 'detail', 'initkwargs']) DynamicRoute = namedtuple('DynamicRoute', ['url', 'name', 'detail', 'initkwargs']) -class DynamicDetailRoute: - def __new__(cls, url, name, initkwargs): - warnings.warn( - "`DynamicDetailRoute` is deprecated and will be removed in 3.10 " - "in favor of `DynamicRoute`, which accepts a `detail` boolean. Use " - "`DynamicRoute(url, name, True, initkwargs)` instead.", - RemovedInDRF310Warning, stacklevel=2 - ) - return DynamicRoute(url, name, True, initkwargs) - - -class DynamicListRoute: - def __new__(cls, url, name, initkwargs): - warnings.warn( - "`DynamicListRoute` is deprecated and will be removed in 3.10 in " - "favor of `DynamicRoute`, which accepts a `detail` boolean. Use " - "`DynamicRoute(url, name, False, initkwargs)` instead.", - RemovedInDRF310Warning, stacklevel=2 - ) - return DynamicRoute(url, name, False, initkwargs) - - def escape_curly_brackets(url_path): """ Double brackets in regex of url_path for escape string formatting diff --git a/tests/test_decorators.py b/tests/test_decorators.py index bd30449e5..e10f0e5c5 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -1,12 +1,11 @@ import pytest from django.test import TestCase -from rest_framework import RemovedInDRF310Warning, status +from rest_framework import status from rest_framework.authentication import BasicAuthentication from rest_framework.decorators import ( - action, api_view, authentication_classes, detail_route, list_route, - parser_classes, permission_classes, renderer_classes, schema, - throttle_classes + action, api_view, authentication_classes, parser_classes, + permission_classes, renderer_classes, schema, throttle_classes ) from rest_framework.parsers import JSONParser from rest_framework.permissions import IsAuthenticated @@ -285,39 +284,3 @@ class ActionDecoratorTestCase(TestCase): @test_action.mapping.post def test_action(): raise NotImplementedError - - def test_detail_route_deprecation(self): - with pytest.warns(RemovedInDRF310Warning) as record: - @detail_route() - def view(request): - raise NotImplementedError - - assert len(record) == 1 - assert str(record[0].message) == ( - "`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." - ) - - def test_list_route_deprecation(self): - with pytest.warns(RemovedInDRF310Warning) as record: - @list_route() - def view(request): - raise NotImplementedError - - assert len(record) == 1 - assert str(record[0].message) == ( - "`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." - ) - - def test_route_url_name_from_path(self): - # pre-3.8 behavior was to base the `url_name` off of the `url_path` - with pytest.warns(RemovedInDRF310Warning): - @list_route(url_path='foo_bar') - def view(request): - raise NotImplementedError - - assert view.url_path == 'foo_bar' - assert view.url_name == 'foo-bar'