Passed
Push — main ( cf3570...95bc96 )
by Jochen
04:50
created

tests.integration.services.authorization.test_permission_to_role_assignment   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 4

4 Functions

Rating   Name   Duplication   Size   Complexity  
A role() 0 5 1
A get_permission_ids_for_role() 0 2 1
A test_deassign_permission_from_role() 0 14 1
A test_assign_permission_to_role() 0 13 1
1
"""
2
:Copyright: 2006-2021 Jochen Kupperschmidt
3
:License: Revised BSD (see `LICENSE` file for details)
4
"""
5
6
import pytest
7
8
from byceps.services.authorization import service
9
10
11
def test_assign_permission_to_role(admin_app, permission_tickle_mortals, role):
12
    permission = permission_tickle_mortals
13
14
    role_permission_ids_before = get_permission_ids_for_role(role)
15
    assert permission.id not in role_permission_ids_before
16
17
    service.assign_permission_to_role(permission.id, role.id)
18
19
    role_permission_ids_after = get_permission_ids_for_role(role)
20
    assert permission.id in role_permission_ids_after
21
22
    # Clean up.
23
    service.deassign_permission_from_role(permission.id, role.id)
24
25
26
def test_deassign_permission_from_role(
27
    admin_app, permission_tickle_mortals, role
28
):
29
    permission = permission_tickle_mortals
30
31
    service.assign_permission_to_role(permission.id, role.id)
32
33
    role_permission_ids_before = get_permission_ids_for_role(role)
34
    assert permission.id in role_permission_ids_before
35
36
    service.deassign_permission_from_role(permission.id, role.id)
37
38
    role_permission_ids_after = get_permission_ids_for_role(role)
39
    assert permission.id not in role_permission_ids_after
40
41
42
@pytest.fixture
43
def role():
44
    role = service.create_role('demigod', 'Demigod')
45
    yield role
46
    service.delete_role(role.id)
47
48
49
def get_permission_ids_for_role(role):
50
    return service.get_permission_ids_for_role(role.id)
51