2015-05-17 12:24:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from __future__ import with_statement
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import sys
|
|
|
|
from sets import Set
|
|
|
|
from ldapcherry.attributes import Attributes
|
2015-05-22 09:49:50 +02:00
|
|
|
from ldapcherry.exceptions import MissingAttributesFile, MissingKey, WrongAttributeType, WrongBackend
|
2015-05-17 12:24:29 +02:00
|
|
|
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
|
|
|
|
|
|
|
|
class TestError(object):
|
|
|
|
|
|
|
|
def testNominal(self):
|
|
|
|
inv = Attributes('./tests/cfg/attributes.yml')
|
2015-05-18 15:04:36 +02:00
|
|
|
inv.get_attributes()
|
2015-05-17 12:24:29 +02:00
|
|
|
return True
|
|
|
|
|
2015-05-18 12:30:51 +02:00
|
|
|
def testGetSelfAttributes(self):
|
|
|
|
inv = Attributes('./tests/cfg/attributes.yml')
|
|
|
|
ret = inv.get_selfattributes()
|
|
|
|
expected = Set(['password', 'shell'])
|
|
|
|
assert ret == expected
|
|
|
|
|
|
|
|
def testGetSelfAttributes(self):
|
|
|
|
inv = Attributes('./tests/cfg/attributes.yml')
|
|
|
|
ret = inv.get_backends()
|
|
|
|
expected = Set(['ldap', 'ad'])
|
|
|
|
assert ret == expected
|
|
|
|
|
2015-05-31 19:38:31 +02:00
|
|
|
def testGetSearchAttributes(self):
|
|
|
|
inv = Attributes('./tests/cfg/attributes.yml')
|
|
|
|
ret = inv.get_search_attributes()
|
|
|
|
expected = {'first-name': 'First Name', 'cn': 'Display Name', 'name': 'Name', 'uid': 'UID', 'email': 'Name'}
|
|
|
|
assert ret == expected
|
|
|
|
|
2015-05-22 09:49:50 +02:00
|
|
|
def testGetBackendAttributes(self):
|
|
|
|
inv = Attributes('./tests/cfg/attributes.yml')
|
|
|
|
ret = inv.get_backend_attributes('ldap')
|
|
|
|
expected = ['shell', 'cn', 'uid', 'uidNumber', 'gidNumber', 'home', 'userPassword', 'givenName', 'email', 'sn']
|
|
|
|
assert ret == expected
|
|
|
|
|
2015-05-31 19:38:31 +02:00
|
|
|
def testGetKey(self):
|
|
|
|
inv = Attributes('./tests/cfg/attributes.yml')
|
|
|
|
ret = inv.get_key()
|
|
|
|
expected = 'uid'
|
|
|
|
assert ret == expected
|
|
|
|
|
2015-05-22 09:49:50 +02:00
|
|
|
def testWrongGetBackendAttributes(self):
|
|
|
|
inv = Attributes('./tests/cfg/attributes.yml')
|
|
|
|
try:
|
|
|
|
ret = inv.get_backend_attributes('notabackend')
|
|
|
|
except WrongBackend:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
raise AssertionError("expected an exception")
|
|
|
|
|
2015-05-17 12:24:29 +02:00
|
|
|
def testNoFile(self):
|
|
|
|
try:
|
|
|
|
inv = Attributes('./tests/cfg/dontexist')
|
|
|
|
except MissingAttributesFile:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
raise AssertionError("expected an exception")
|
|
|
|
|
2015-05-17 19:22:11 +02:00
|
|
|
def testMissingMandatory(self):
|
|
|
|
try:
|
|
|
|
inv = Attributes('./tests/cfg/attributes_missing_mandatory.yml')
|
|
|
|
except MissingKey:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
raise AssertionError("expected an exception")
|
|
|
|
|
2015-05-17 19:49:13 +02:00
|
|
|
def testWrongType(self):
|
|
|
|
try:
|
|
|
|
inv = Attributes('./tests/cfg/attributes_wrong_type.yml')
|
|
|
|
except WrongAttributeType:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
raise AssertionError("expected an exception")
|
2015-05-17 12:24:29 +02:00
|
|
|
|
|
|
|
# def testGetDisplayName(self):
|
|
|
|
# inv = Attributes('./tests/cfg/attributes.yml')
|
|
|
|
# res = inv.get_display_name('users')
|
|
|
|
# expected = 'Simple Users'
|
|
|
|
# assert res == expected
|