mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Test PendingDeprecationWarnings
This commit is contained in:
parent
9d84e0c290
commit
1c2c4f43ae
|
@ -9,6 +9,7 @@ used to annotate methods on viewsets that should be included by routers.
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import types
|
||||
import warnings
|
||||
|
||||
from django.utils import six
|
||||
|
||||
|
@ -76,9 +77,11 @@ def api_view(http_method_names=None, exclude_from_schema=False):
|
|||
APIView.schema)
|
||||
|
||||
if exclude_from_schema:
|
||||
# This won't catch an explicit `exclude_from_schema=False`
|
||||
# but it should be good enough.
|
||||
# TODO: DeprecationWarning
|
||||
warnings.warn(
|
||||
"The `exclude_from_schema` argument to `api_view` is deprecated. "
|
||||
"Use the `schema` decorator instead, passing `None`.",
|
||||
PendingDeprecationWarning
|
||||
)
|
||||
WrappedAPIView.exclude_from_schema = exclude_from_schema
|
||||
|
||||
return WrappedAPIView.as_view()
|
||||
|
|
|
@ -3,6 +3,7 @@ generators.py # Top-down schema generation
|
|||
|
||||
See schemas.__init__.py for package overview.
|
||||
"""
|
||||
import warnings
|
||||
from collections import OrderedDict
|
||||
from importlib import import_module
|
||||
|
||||
|
@ -149,7 +150,10 @@ class EndpointEnumerator(object):
|
|||
return False # Ignore anything except REST framework views.
|
||||
|
||||
if hasattr(callback.cls, 'exclude_from_schema'):
|
||||
# TODO: deprecation warning
|
||||
fmt = ("{}. The `APIView.exclude_from_schema` is deprecated. "
|
||||
"Set `schema = None` instead")
|
||||
msg = fmt.format(callback.cls.__name__)
|
||||
warnings.warn(msg, PendingDeprecationWarning)
|
||||
if getattr(callback.cls, 'exclude_from_schema', False):
|
||||
return False
|
||||
|
||||
|
|
|
@ -641,9 +641,9 @@ def included_fbv(request):
|
|||
class SchemaGenerationExclusionTests(TestCase):
|
||||
def setUp(self):
|
||||
self.patterns = [
|
||||
url('^excluded-cbv/?$', ExcludedAPIView.as_view()),
|
||||
url('^excluded-fbv/?$', excluded_fbv),
|
||||
url('^included-fbv/?$', included_fbv),
|
||||
url('^excluded-cbv/$', ExcludedAPIView.as_view()),
|
||||
url('^excluded-fbv/$', excluded_fbv),
|
||||
url('^included-fbv/$', included_fbv),
|
||||
]
|
||||
|
||||
def test_schema_generator_excludes_correctly(self):
|
||||
|
@ -690,4 +690,21 @@ class SchemaGenerationExclusionTests(TestCase):
|
|||
assert should_include == expected
|
||||
|
||||
def test_deprecations(self):
|
||||
with pytest.warns(PendingDeprecationWarning):
|
||||
@api_view(["GET"], exclude_from_schema=True)
|
||||
def view(request):
|
||||
pass
|
||||
|
||||
class OldFashjonedExcludedView(APIView):
|
||||
exclude_from_schema = True
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
pass
|
||||
|
||||
patterns = [
|
||||
url('^excluded-old-fashioned/$', OldFashjonedExcludedView.as_view()),
|
||||
]
|
||||
|
||||
inspector = EndpointEnumerator(patterns)
|
||||
with pytest.warns(PendingDeprecationWarning):
|
||||
inspector.get_api_endpoints()
|
||||
|
|
Loading…
Reference in New Issue
Block a user