mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 11:04:02 +03:00
parent
f54a220d8f
commit
bd9a799e16
|
@ -31,3 +31,11 @@ class SchemaView(APIView):
|
|||
if schema is None:
|
||||
raise exceptions.PermissionDenied()
|
||||
return Response(schema)
|
||||
|
||||
def handle_exception(self, exc):
|
||||
# Schema renderers do not render exceptions, so re-perform content
|
||||
# negotiation with default renderers.
|
||||
self.renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES
|
||||
neg = self.perform_content_negotiation(self.request, force=True)
|
||||
self.request.accepted_renderer, self.request.accepted_media_type = neg
|
||||
return super(SchemaView, self).handle_exception(exc)
|
||||
|
|
|
@ -1304,3 +1304,13 @@ class TestAutoSchemaAllowsFilters(object):
|
|||
|
||||
def test_FOO(self):
|
||||
assert not self._test('FOO')
|
||||
|
||||
|
||||
@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
|
||||
def test_schema_handles_exception():
|
||||
schema_view = get_schema_view(permission_classes=[DenyAllUsingPermissionDenied])
|
||||
request = factory.get('/')
|
||||
response = schema_view(request)
|
||||
response.render()
|
||||
assert response.status_code == 403
|
||||
assert "You do not have permission to perform this action." in str(response.content)
|
||||
|
|
Loading…
Reference in New Issue
Block a user