1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-05 09:08:53 +01:00
ldapcherry/tests/test_Roles.py

71 lines
2.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
from __future__ import unicode_literals
import pytest
import sys
2015-05-16 19:15:20 +02:00
from sets import Set
from ldapcherry.roles import Roles
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
class TestError(object):
def testNominal(self):
inv = Roles('./tests/cfg/roles.yml')
print inv.roles
return True
def testMissingDisplayName(self):
try:
2015-05-12 01:41:32 +02:00
inv = Roles('./tests/cfg/roles_missing_diplay_name.yml')
except MissingKey:
return
else:
raise AssertionError("expected an exception")
2015-05-15 01:03:31 +02:00
def testMissingBackends(self):
try:
inv = Roles('./tests/cfg/roles_missing_backends.yml')
except MissingKey:
return
else:
raise AssertionError("expected an exception")
def testRoleKeyDuplication(self):
try:
inv = Roles('./tests/cfg/roles_key_dup.yml')
except DumplicateRoleKey:
return
else:
raise AssertionError("expected an exception")
def testNoFile(self):
try:
inv = Roles('./tests/cfg/dontexist')
except MissingRolesFile:
return
else:
raise AssertionError("expected an exception")
def testRoleContentDuplication(self):
try:
2015-05-15 01:03:31 +02:00
inv = Roles('./tests/cfg/roles_content_dup.yml')
except DumplicateRoleContent:
return
else:
raise AssertionError("expected an exception")
2015-05-16 19:15:20 +02:00
def testGetRole(self):
inv = Roles('./tests/cfg/roles.yml')
groups = {
'ad' : ['Domain Users', 'Domain Users 2'],
'ldap': ['cn=users,ou=group,dc=example,dc=com']
}
expected = {'unusedgroups': {'ad': Set(['Domain Users 2'])}, 'roles': Set(['users'])}
assert inv.get_roles(groups) == expected