From ef75182c739d5b8925f1b7a0d468c3d901d6d3e7 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Mon, 7 Oct 2019 21:41:37 -0500 Subject: [PATCH] Refactor: Update tests with new Owner role --- server/corvus/service/role_service.py | 8 +++++--- server/manage.py | 3 ++- server/tests/service/test_role_service.py | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/server/corvus/service/role_service.py b/server/corvus/service/role_service.py index 5b2c740..7a66d87 100644 --- a/server/corvus/service/role_service.py +++ b/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) diff --git a/server/manage.py b/server/manage.py index 28c8db3..19a282c 100644 --- a/server/manage.py +++ b/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, diff --git a/server/tests/service/test_role_service.py b/server/tests/service/test_role_service.py index 6982dcf..1d49c05 100644 --- a/server/tests/service/test_role_service.py +++ b/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():