mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Test 'exclude_from_schema' deprecation warning message (#1)
This commit is contained in:
parent
f349d35442
commit
0cd24b455f
|
@ -150,8 +150,8 @@ class EndpointEnumerator(object):
|
|||
return False # Ignore anything except REST framework views.
|
||||
|
||||
if hasattr(callback.cls, 'exclude_from_schema'):
|
||||
fmt = ("{}. The `APIView.exclude_from_schema` is pending deprecation. "
|
||||
"Set `schema = None` instead")
|
||||
fmt = ("The `{}.exclude_from_schema` is pending deprecation. "
|
||||
"Set `schema = None` instead.")
|
||||
msg = fmt.format(callback.cls.__name__)
|
||||
warnings.warn(msg, PendingDeprecationWarning)
|
||||
if getattr(callback.cls, 'exclude_from_schema', False):
|
||||
|
|
|
@ -690,11 +690,17 @@ class SchemaGenerationExclusionTests(TestCase):
|
|||
assert should_include == expected
|
||||
|
||||
def test_deprecations(self):
|
||||
with pytest.warns(PendingDeprecationWarning):
|
||||
with pytest.warns(PendingDeprecationWarning) as record:
|
||||
@api_view(["GET"], exclude_from_schema=True)
|
||||
def view(request):
|
||||
pass
|
||||
|
||||
assert len(record) == 1
|
||||
assert str(record[0].message) == (
|
||||
"The `exclude_from_schema` argument to `api_view` is pending "
|
||||
"deprecation. Use the `schema` decorator instead, passing `None`."
|
||||
)
|
||||
|
||||
class OldFashionedExcludedView(APIView):
|
||||
exclude_from_schema = True
|
||||
|
||||
|
@ -706,5 +712,11 @@ class SchemaGenerationExclusionTests(TestCase):
|
|||
]
|
||||
|
||||
inspector = EndpointEnumerator(patterns)
|
||||
with pytest.warns(PendingDeprecationWarning):
|
||||
with pytest.warns(PendingDeprecationWarning) as record:
|
||||
inspector.get_api_endpoints()
|
||||
|
||||
assert len(record) == 1
|
||||
assert str(record[0].message) == (
|
||||
"The `OldFashionedExcludedView.exclude_from_schema` is "
|
||||
"pending deprecation. Set `schema = None` instead."
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user