mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-10-31 07:57:55 +03:00 
			
		
		
		
	Updated list_route() and detail_route() deprecations.
This commit is contained in:
		
							parent
							
								
									7fb11bf2f5
								
							
						
					
					
						commit
						cfd73825a8
					
				|  | @ -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. | ||||
|     """ | ||||
|     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.", | ||||
|         PendingDeprecationWarning, stacklevel=2 | ||||
|         DeprecationWarning, stacklevel=2 | ||||
|     ) | ||||
| 
 | ||||
|     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. | ||||
|     """ | ||||
|     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.", | ||||
|         PendingDeprecationWarning, stacklevel=2 | ||||
|         DeprecationWarning, stacklevel=2 | ||||
|     ) | ||||
| 
 | ||||
|     def decorator(func): | ||||
|  |  | |||
|  | @ -40,10 +40,10 @@ DynamicRoute = namedtuple('DynamicRoute', ['url', 'name', 'detail', 'initkwargs' | |||
| class DynamicDetailRoute(object): | ||||
|     def __new__(cls, url, name, initkwargs): | ||||
|         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 " | ||||
|             "`DynamicRoute(url, name, True, initkwargs)` instead.", | ||||
|             PendingDeprecationWarning, stacklevel=2 | ||||
|             DeprecationWarning, stacklevel=2 | ||||
|         ) | ||||
|         return DynamicRoute(url, name, True, initkwargs) | ||||
| 
 | ||||
|  | @ -51,10 +51,10 @@ class DynamicDetailRoute(object): | |||
| class DynamicListRoute(object): | ||||
|     def __new__(cls, url, name, initkwargs): | ||||
|         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 " | ||||
|             "`DynamicRoute(url, name, False, initkwargs)` instead.", | ||||
|             PendingDeprecationWarning, stacklevel=2 | ||||
|             DeprecationWarning, stacklevel=2 | ||||
|         ) | ||||
|         return DynamicRoute(url, name, False, initkwargs) | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,7 +4,6 @@ generators.py   # Top-down schema generation | |||
| See schemas.__init__.py for package overview. | ||||
| """ | ||||
| import re | ||||
| import warnings | ||||
| from collections import Counter, OrderedDict | ||||
| from importlib import import_module | ||||
| 
 | ||||
|  |  | |||
|  | @ -290,34 +290,34 @@ class ActionDecoratorTestCase(TestCase): | |||
|                 raise NotImplementedError | ||||
| 
 | ||||
|     def test_detail_route_deprecation(self): | ||||
|         with pytest.warns(PendingDeprecationWarning) as record: | ||||
|         with pytest.warns(DeprecationWarning) as record: | ||||
|             @detail_route() | ||||
|             def view(request): | ||||
|                 raise NotImplementedError | ||||
| 
 | ||||
|         assert len(record) == 1 | ||||
|         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 " | ||||
|             "`@action(detail=True)` instead." | ||||
|         ) | ||||
| 
 | ||||
|     def test_list_route_deprecation(self): | ||||
|         with pytest.warns(PendingDeprecationWarning) as record: | ||||
|         with pytest.warns(DeprecationWarning) as record: | ||||
|             @list_route() | ||||
|             def view(request): | ||||
|                 raise NotImplementedError | ||||
| 
 | ||||
|         assert len(record) == 1 | ||||
|         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 " | ||||
|             "`@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(PendingDeprecationWarning): | ||||
|         with pytest.warns(DeprecationWarning): | ||||
|             @list_route(url_path='foo_bar') | ||||
|             def view(request): | ||||
|                 raise NotImplementedError | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user