mirror of
https://github.com/kakwa/ldapcherry
synced 2024-12-22 04:40:03 +01:00
add methods for class Roles + unit tests
* adding get_allroles (list all available roles) * adding get_display_name (get display name of a role) * add various unit tests
This commit is contained in:
parent
6949cc71e4
commit
1211ab431b
@ -198,6 +198,16 @@ class Roles:
|
||||
ret['unusedgroups'] = unusedgroups
|
||||
return ret
|
||||
|
||||
def get_allroles(self):
|
||||
"""get the list of roles"""
|
||||
return self.roles_raw.keys()
|
||||
|
||||
def get_display_name(self, role):
|
||||
"""get the display name of a role"""
|
||||
if not role in self.roles_raw:
|
||||
raise MissingRole(role)
|
||||
return self.roles_raw[role]['display_name']
|
||||
|
||||
def get_groups(self, role):
|
||||
"""get the list of groups from role"""
|
||||
if not role in self.roles_raw:
|
||||
|
@ -37,3 +37,7 @@ groups = {
|
||||
|
||||
|
||||
print inv.get_roles(groups)
|
||||
|
||||
print inv.get_allroles()
|
||||
|
||||
print inv.get_backends()
|
||||
|
@ -76,6 +76,37 @@ class TestError(object):
|
||||
else:
|
||||
raise AssertionError("expected an exception")
|
||||
|
||||
def testGetDisplayNameMissingRole(self):
|
||||
inv = Roles('./tests/cfg/roles.yml')
|
||||
try:
|
||||
res = inv.get_display_name('notarole')
|
||||
except MissingRole:
|
||||
return
|
||||
else:
|
||||
raise AssertionError("expected an exception")
|
||||
|
||||
def testGetDisplayName(self):
|
||||
inv = Roles('./tests/cfg/roles.yml')
|
||||
res = inv.get_display_name('users')
|
||||
expected = 'Simple Users'
|
||||
assert res == expected
|
||||
|
||||
def testGetAllRoles(self):
|
||||
inv = Roles('./tests/cfg/roles.yml')
|
||||
res = inv.get_allroles()
|
||||
expected = ['developpers', 'admin-lv3', 'admin-lv2', 'users']
|
||||
assert res == expected
|
||||
|
||||
def testGetAllRoles(self):
|
||||
inv = Roles('./tests/cfg/roles.yml')
|
||||
res = inv.get_backends()
|
||||
expected = Set(['ad', 'ldap'])
|
||||
assert res == expected
|
||||
|
||||
def testDumpNested(self):
|
||||
inv = Roles('./tests/cfg/roles.yml')
|
||||
inv.dump_nest()
|
||||
|
||||
def testAdminRoles(self):
|
||||
inv = Roles('./tests/cfg/roles.yml')
|
||||
res = inv.get_admin_roles()
|
||||
|
Loading…
x
Reference in New Issue
Block a user