Browse Source

Refactor: Update tests with new Owner role

merge-requests/1/head
Drew Short 5 years ago
parent
commit
ef75182c73
  1. 8
      server/corvus/service/role_service.py
  2. 3
      server/manage.py
  3. 6
      server/tests/service/test_role_service.py

8
server/corvus/service/role_service.py

@ -15,7 +15,8 @@ class Role(Enum):
ANONYMOUS = 'ANONYMOUS'
NONE = 'NONE'
def __str__(self):
def __str__(self) -> str:
"""Return the value of the enum."""
return self.value
@ -104,8 +105,9 @@ class RoleTree(defaultdict):
roles.extend(role_tree.get_children_roles())
return set(roles)
def __str__(self):
return str(self.data)
def __str__(self) -> str:
"""Represent the tree with the value of the node."""
return 'RoleTree.%s(%d)' % (self.data, self.power)
ROLES = RoleTree(None, Role.OWNER, 0)

3
server/manage.py

@ -57,7 +57,8 @@ def delete_user(name: str):
envvar='ROLE',
help='Role to assign to the user. '
+ 'default=[USER] acceptable values = ['
+ ','.join(sorted(set(map(lambda rt: str(rt), ROLE_LIST))))
+ ','.join(
sorted(set(map(lambda rt: str(rt.data), ROLE_LIST))))
+ ']')
def register_user(
name: str,

6
server/tests/service/test_role_service.py

@ -3,16 +3,18 @@ from corvus.service.role_service import ROLES, Role
def test_role_tree_find_roles_in_hierarchy():
roles = ROLES.find_roles_in_hierarchy(Role.USER)
assert len(roles) == 4
assert len(roles) == 5
assert Role.USER in roles
assert Role.MODERATOR in roles
assert Role.AUDITOR in roles
assert Role.ADMIN in roles
assert Role.OWNER in roles
roles = ROLES.find_roles_in_hierarchy(Role.AUDITOR)
assert len(roles) == 2
assert len(roles) == 3
assert Role.AUDITOR in roles
assert Role.ADMIN in roles
assert Role.OWNER in roles
def test_role_tree_find_children_roles():

Loading…
Cancel
Save