mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 08:14:16 +03:00
fixed permissions examples + sanity test
This commit is contained in:
parent
afd490238a
commit
023c008939
27
examples/permissionsexample/tests.py
Normal file
27
examples/permissionsexample/tests.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.client import Client
|
||||
|
||||
|
||||
class NaviguatePermissionsExamples(TestCase):
|
||||
"""
|
||||
Sanity checks for permissions examples
|
||||
"""
|
||||
|
||||
def test_throttled_resource(self):
|
||||
url = reverse('throttled-resource')
|
||||
for i in range(0, 10):
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 503)
|
||||
|
||||
|
||||
def test_loggedin_resource(self):
|
||||
url = reverse('loggedin-resource')
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 403)
|
||||
loggedin_client = Client()
|
||||
loggedin_client.login(username='test', password='test')
|
||||
response = loggedin_client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
|
@ -30,7 +30,7 @@ class ThrottlingExampleView(View):
|
|||
throttle will be applied until 60 seconds have passed since the first request.
|
||||
"""
|
||||
|
||||
permissions = (PerUserThrottling,)
|
||||
permissions_classes = (PerUserThrottling,)
|
||||
throttle = '10/min'
|
||||
|
||||
def get(self, request):
|
||||
|
@ -47,7 +47,7 @@ class LoggedInExampleView(View):
|
|||
`curl -X GET -H 'Accept: application/json' -u test:test http://localhost:8000/permissions-example`
|
||||
"""
|
||||
|
||||
permissions = (IsAuthenticated, )
|
||||
permissions_classes = (IsAuthenticated, )
|
||||
|
||||
def get(self, request):
|
||||
return Response('You have permission to view this resource')
|
||||
|
|
|
@ -54,7 +54,7 @@ class Sandbox(View):
|
|||
'url': reverse('model-resource-root', request)},
|
||||
{'name': 'Simple Mixin-only example',
|
||||
'url': reverse('mixin-view', request)},
|
||||
{'name': 'Object store API'
|
||||
{'name': 'Object store API',
|
||||
'url': reverse('object-store-root', request)},
|
||||
{'name': 'Code highlighting API',
|
||||
'url': reverse('pygments-root', request)},
|
||||
|
|
Loading…
Reference in New Issue
Block a user