fixed permissions examples + sanity test

This commit is contained in:
Sébastien Piquemal 2012-02-23 23:19:51 +02:00
parent afd490238a
commit 023c008939
3 changed files with 30 additions and 3 deletions

View 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)

View File

@ -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')

View File

@ -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)},