forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_permissions.py
33 lines (22 loc) · 1.16 KB
/
test_permissions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from collections import namedtuple
from unittest import TestCase
from redash.permissions import has_access
MockUser = namedtuple('MockUser', ['permissions', 'groups'])
view_only = True
class TestHasAccess(TestCase):
def test_allows_admin_regardless_of_groups(self):
user = MockUser(['admin'], [])
self.assertTrue(has_access({}, user, view_only))
self.assertTrue(has_access({}, user, not view_only))
def test_allows_if_user_member_in_group_with_view_access(self):
user = MockUser([], [1])
self.assertTrue(has_access({1: view_only}, user, view_only))
def test_allows_if_user_member_in_group_with_full_access(self):
user = MockUser([], [1])
self.assertTrue(has_access({1: not view_only}, user, not view_only))
def test_not_allows_if_not_enough_permission(self):
user = MockUser([], [1])
self.assertFalse(has_access({1: view_only}, user, not view_only))
self.assertFalse(has_access({2: view_only}, user, not view_only))
self.assertFalse(has_access({2: view_only}, user, view_only))
self.assertFalse(has_access({2: not view_only, 1: view_only}, user, not view_only))