aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/auth/test_privileges.py
blob: e6c86d827caea5e5247f86da5f58e63594421095 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
"""Test the privileges module"""
import pytest

from gn3.auth import db
from gn3.auth.authorisation.privileges import Privilege, user_privileges

from tests.unit.auth import conftest

SORT_KEY = lambda x: x.privilege_id

PRIVILEGES = sorted(
    (Privilege("system:group:create-group", "Create a group"),
     Privilege("system:group:view-group", "View the details of a group"),
     Privilege("system:group:edit-group", "Edit the details of a group"),
     Privilege("system:group:delete-group", "Delete a group"),
     Privilege("group:user:add-group-member", "Add a user to a group"),
     Privilege("group:user:remove-group-member", "Remove a user from a group"),
     Privilege("system:group:transfer-group-leader",
               "Transfer leadership of the group to some other member"),

     Privilege("group:resource:create-resource", "Create a resource object"),
     Privilege("group:resource:view-resource",
               "view a resource and use it in computations"),
     Privilege("group:resource:edit-resource", "edit/update a resource"),
     Privilege("group:resource:delete-resource", "Delete a resource"),

     Privilege("group:role:create-role", "Create a new role"),
     Privilege("group:role:edit-role", "edit/update an existing role"),
     Privilege("group:user:assign-role", "Assign a role to an existing user"),
     Privilege("group:role:delete-role", "Delete an existing role")),
    key=SORT_KEY)

@pytest.mark.unit_test
@pytest.mark.parametrize(
    "user,expected", tuple(zip(
        conftest.TEST_USERS, (PRIVILEGES, [], [], [], []))))
def test_user_privileges(auth_testdb_path, fxtr_users, user, expected):# pylint: disable=[unused-argument]
    """
    GIVEN: A user
    WHEN: An attempt is made to fetch the user's privileges
    THEN: Ensure only
    """
    with db.connection(auth_testdb_path) as conn:
        assert sorted(
            user_privileges(conn, user), key=SORT_KEY) == expected