From 0cd24b455f5982e898735fda7e9e669c0610e8cd Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Fri, 15 Sep 2017 07:23:12 -0400 Subject: [PATCH] Test 'exclude_from_schema' deprecation warning message (#1) --- rest_framework/schemas/generators.py | 4 ++-- tests/test_schemas.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/rest_framework/schemas/generators.py b/rest_framework/schemas/generators.py index 4d63ad5e9..736d9d419 100644 --- a/rest_framework/schemas/generators.py +++ b/rest_framework/schemas/generators.py @@ -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): diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 0ee6131b6..786db593b 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -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." + )