Test 'exclude_from_schema' deprecation warning message (#1)

This commit is contained in:
Ryan P Kilby 2017-09-15 07:23:12 -04:00 committed by Carlton Gibson
parent f349d35442
commit 0cd24b455f
2 changed files with 16 additions and 4 deletions

View File

@ -150,8 +150,8 @@ class EndpointEnumerator(object):
return False # Ignore anything except REST framework views. return False # Ignore anything except REST framework views.
if hasattr(callback.cls, 'exclude_from_schema'): if hasattr(callback.cls, 'exclude_from_schema'):
fmt = ("{}. The `APIView.exclude_from_schema` is pending deprecation. " fmt = ("The `{}.exclude_from_schema` is pending deprecation. "
"Set `schema = None` instead") "Set `schema = None` instead.")
msg = fmt.format(callback.cls.__name__) msg = fmt.format(callback.cls.__name__)
warnings.warn(msg, PendingDeprecationWarning) warnings.warn(msg, PendingDeprecationWarning)
if getattr(callback.cls, 'exclude_from_schema', False): if getattr(callback.cls, 'exclude_from_schema', False):

View File

@ -690,11 +690,17 @@ class SchemaGenerationExclusionTests(TestCase):
assert should_include == expected assert should_include == expected
def test_deprecations(self): def test_deprecations(self):
with pytest.warns(PendingDeprecationWarning): with pytest.warns(PendingDeprecationWarning) as record:
@api_view(["GET"], exclude_from_schema=True) @api_view(["GET"], exclude_from_schema=True)
def view(request): def view(request):
pass 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): class OldFashionedExcludedView(APIView):
exclude_from_schema = True exclude_from_schema = True
@ -706,5 +712,11 @@ class SchemaGenerationExclusionTests(TestCase):
] ]
inspector = EndpointEnumerator(patterns) inspector = EndpointEnumerator(patterns)
with pytest.warns(PendingDeprecationWarning): with pytest.warns(PendingDeprecationWarning) as record:
inspector.get_api_endpoints() 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."
)