Skip to content

Commit

Permalink
Get all extensions (whether you're a regular user, or a superuser)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius O committed Apr 25, 2016
1 parent 8b7f795 commit 5d94783
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 46 deletions.
43 changes: 2 additions & 41 deletions geokey/core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from geokey.version import get_version
from geokey.core.views import InfoAPIView
from geokey.users.tests.model_factories import UserFactory
from geokey.extensions.base import register, deregister


Expand Down Expand Up @@ -45,8 +44,8 @@ def contains_extension(self, ext_id, installed_extensions):

return False

def test_get_with_anonymous(self):
"""Test GET with anonymous user."""
def test_get(self):
"""Test GET."""
self.request.user = AnonymousUser()
response = self.view(self.request).render()

Expand All @@ -59,44 +58,6 @@ def test_get_with_anonymous(self):
self.assertEqual(geokey.get('version'), get_version())
self.assertIn('installed_extensions', geokey)

installed_extensions = geokey.get('installed_extensions')
self.assertTrue(self.contains_extension('A', installed_extensions))
self.assertTrue(self.contains_extension('B', installed_extensions))
self.assertFalse(self.contains_extension('S', installed_extensions))

def test_get_with_user(self):
"""Test GET with user."""
self.request.user = UserFactory.create(**{'is_superuser': False})
response = self.view(self.request).render()

self.assertEqual(response.status_code, 200)

response = json.loads(response.content)
self.assertIn('geokey', response)

geokey = response.get('geokey')
self.assertEqual(geokey.get('version'), get_version())
self.assertIn('installed_extensions', geokey)

installed_extensions = geokey.get('installed_extensions')
self.assertTrue(self.contains_extension('A', installed_extensions))
self.assertTrue(self.contains_extension('B', installed_extensions))
self.assertFalse(self.contains_extension('S', installed_extensions))

def test_get_with_superuser(self):
"""Test GET with superuser."""
self.request.user = UserFactory.create(**{'is_superuser': True})
response = self.view(self.request).render()

self.assertEqual(response.status_code, 200)

response = json.loads(response.content)
self.assertIn('geokey', response)

geokey = response.get('geokey')
self.assertEqual(geokey.get('version'), get_version())
self.assertIn('installed_extensions', geokey)

installed_extensions = geokey.get('installed_extensions')
self.assertTrue(self.contains_extension('A', installed_extensions))
self.assertTrue(self.contains_extension('B', installed_extensions))
Expand Down
6 changes: 1 addition & 5 deletions geokey/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ def get(self, request):
'name': ext_id,
'version': ext['version'] if 'version' in ext else None
},
filter(
lambda (ext_id, ext):
request.user.is_superuser or not ext['superuser'],
extensions.iteritems()
)
extensions.iteritems()
)

return Response(info)

0 comments on commit 5d94783

Please sign in to comment.