Skip to content

Commit

Permalink
Merge pull request #58 from ropable/master
Browse files Browse the repository at this point in the history
Remove DjangoAuthorization from all API Resource classes, add tests.
  • Loading branch information
ropable committed Jul 18, 2016
2 parents f2d6053 + 418c168 commit 197e2b4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 0 additions & 4 deletions prs2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from tastypie import fields
from tastypie.api import Api
from tastypie.authentication import SessionAuthentication
from tastypie.authorization import DjangoAuthorization
from tastypie.cache import SimpleCache
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
from django.contrib.auth.models import User, Group
Expand Down Expand Up @@ -39,7 +38,6 @@ class Meta:
cache = SimpleCache()
filtering = {'id': ALL, 'name': ALL}
authentication = SessionAuthentication()
authorization = DjangoAuthorization()

v1_api.register(GroupResource())

Expand Down Expand Up @@ -69,7 +67,6 @@ class Meta:
}
cache = SimpleCache()
authentication = SessionAuthentication()
authorization = DjangoAuthorization()

v1_api.register(UserResource())

Expand All @@ -81,6 +78,5 @@ class Meta:
filtering = {'id': ALL, 'name': ALL, 'slug': ALL}
cache = SimpleCache()
authentication = SessionAuthentication()
authorization = DjangoAuthorization()

v1_api.register(TagResource())
2 changes: 0 additions & 2 deletions prs2/referral/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from tastypie import fields
from tastypie.authentication import SessionAuthentication
from tastypie.authorization import DjangoAuthorization
from tastypie.cache import SimpleCache
from tastypie.resources import ModelResource, ALL_WITH_RELATIONS

Expand All @@ -24,7 +23,6 @@ def generate_meta(klass, overrides={}):
"""
metaitems = {
'authentication': SessionAuthentication(),
'authorization': DjangoAuthorization(),
'queryset': klass.objects.all(),
'resource_name': klass._meta.model_name,
'filtering': generate_filtering(klass),
Expand Down
9 changes: 7 additions & 2 deletions prs2/referral/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ def test_permission_resource_list(self):
self.client.login(username='normaluser', password='pass')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.client.login(username='readonlyuser', password='pass')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

'''
def test_permission_resource_detail(self):
"""Test auth and anon access permission to resource details
"""
Expand All @@ -43,6 +45,9 @@ def test_permission_resource_detail(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.client.logout()
self.client.login(username='readonlyuser', password='pass')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.client.logout()
response = self.client.get(url)
self.assertEqual(response.status_code, 401)
'''

0 comments on commit 197e2b4

Please sign in to comment.