mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Merge 4ca09514da
into 7f77340b33
This commit is contained in:
commit
0d355feba5
|
@ -173,7 +173,7 @@ class APIView(View):
|
||||||
If request is not permitted, determine what kind of exception to raise.
|
If request is not permitted, determine what kind of exception to raise.
|
||||||
"""
|
"""
|
||||||
if request.authenticators and not request.successful_authenticator:
|
if request.authenticators and not request.successful_authenticator:
|
||||||
raise exceptions.NotAuthenticated()
|
raise exceptions.NotAuthenticated(detail=message)
|
||||||
raise exceptions.PermissionDenied(detail=message)
|
raise exceptions.PermissionDenied(detail=message)
|
||||||
|
|
||||||
def throttled(self, request, wait):
|
def throttled(self, request, wait):
|
||||||
|
|
|
@ -522,3 +522,10 @@ class CustomPermissionsTests(TestCase):
|
||||||
detail = response.data.get('detail')
|
detail = response.data.get('detail')
|
||||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||||
self.assertEqual(detail, self.custom_message)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user