feat: add permission checks for menus, view routes
This commit is contained in:
parent
675b51cac2
commit
e3942ce65e
11 changed files with 537 additions and 40 deletions
|
@ -3,20 +3,15 @@
|
|||
from unittest import TestCase
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from wuttjamaican.conf import WuttaConfig
|
||||
|
||||
from pyramid import testing
|
||||
|
||||
from wuttaweb import menus as mod
|
||||
from tests.util import WebTestCase
|
||||
|
||||
|
||||
class TestMenuHandler(TestCase):
|
||||
class TestMenuHandler(WebTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.config = WuttaConfig()
|
||||
self.app = self.config.get_app()
|
||||
self.setup_web()
|
||||
self.handler = mod.MenuHandler(self.config)
|
||||
self.request = testing.DummyRequest()
|
||||
|
||||
def test_make_admin_menu(self):
|
||||
menus = self.handler.make_admin_menu(self.request)
|
||||
|
@ -27,7 +22,27 @@ class TestMenuHandler(TestCase):
|
|||
self.assertIsInstance(menus, list)
|
||||
|
||||
def test_is_allowed(self):
|
||||
# TODO: this should test auth/perm handling
|
||||
model = self.app.model
|
||||
auth = self.app.get_auth_handler()
|
||||
|
||||
# user with perms
|
||||
barney = model.User(username='barney')
|
||||
self.session.add(barney)
|
||||
blokes = model.Role(name="Blokes")
|
||||
self.session.add(blokes)
|
||||
barney.roles.append(blokes)
|
||||
auth.grant_permission(blokes, 'appinfo.list')
|
||||
self.request.user = barney
|
||||
|
||||
# perm not granted to user
|
||||
item = {'perm': 'appinfo.configure'}
|
||||
self.assertFalse(self.handler._is_allowed(self.request, item))
|
||||
|
||||
# perm *is* granted to user
|
||||
item = {'perm': 'appinfo.list'}
|
||||
self.assertTrue(self.handler._is_allowed(self.request, item))
|
||||
|
||||
# perm not required
|
||||
item = {}
|
||||
self.assertTrue(self.handler._is_allowed(self.request, item))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue