This commit is contained in:
Yaser Amiri 2018-09-11 05:29:11 +00:00 committed by GitHub
commit 0d355feba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -173,7 +173,7 @@ class APIView(View):
If request is not permitted, determine what kind of exception to raise.
"""
if request.authenticators and not request.successful_authenticator:
raise exceptions.NotAuthenticated()
raise exceptions.NotAuthenticated(detail=message)
raise exceptions.PermissionDenied(detail=message)
def throttled(self, request, wait):

View File

@ -522,3 +522,10 @@ class CustomPermissionsTests(TestCase):
detail = response.data.get('detail')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(detail, self.custom_message)
def test_permission_denied_for_object_with_custom_detail_by_anonymous_user(self):
anonymous_request = factory.get('/1', format='json')
response = denied_object_view_with_detail(anonymous_request, pk=1)
detail = response.data.get('detail')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(detail, self.custom_message)