1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-24 18:24:31 +01:00

porting the tests over to python3

This commit is contained in:
kakwa 2019-02-07 20:55:50 +01:00
parent c3feafdb2c
commit 2a2864a306
7 changed files with 28 additions and 20 deletions

View File

@ -1,7 +1,7 @@
import os import os
def travis_disabled(f): def travis_disabled(f):
def _decorator(f): def _decorator(f):
print 'test has been disabled on travis' print('test has been disabled on travis')
if 'TRAVIS' in os.environ and os.environ['TRAVIS'] == 'yes': if 'TRAVIS' in os.environ and os.environ['TRAVIS'] == 'yes':
return _decorator return _decorator
else: else:
@ -9,7 +9,7 @@ def travis_disabled(f):
def slow_disabled(f): def slow_disabled(f):
def _decorator(f): def _decorator(f):
print 'test has been disabled by env var LCNOSLOW' print('test has been disabled by env var LCNOSLOW')
if 'LCNOSLOW' in os.environ and os.environ['LCNOSLOW'] == 'yes': if 'LCNOSLOW' in os.environ and os.environ['LCNOSLOW'] == 'yes':
return _decorator return _decorator
else: else:

View File

@ -6,10 +6,12 @@ from __future__ import unicode_literals
import pytest import pytest
import sys import sys
from sets import Set
from ldapcherry.attributes import Attributes from ldapcherry.attributes import Attributes
from ldapcherry.exceptions import * from ldapcherry.exceptions import *
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
if sys.version < '3':
from sets import Set as set
class TestError(object): class TestError(object):
@ -27,7 +29,7 @@ class TestError(object):
def testGetSelfAttributes(self): def testGetSelfAttributes(self):
inv = Attributes('./tests/cfg/attributes.yml') inv = Attributes('./tests/cfg/attributes.yml')
ret = inv.get_backends() ret = inv.get_backends()
expected = Set(['ldap', 'ad']) expected = set(['ldap', 'ad'])
assert ret == expected assert ret == expected
def testGetSearchAttributes(self): def testGetSearchAttributes(self):

View File

@ -6,12 +6,14 @@ from __future__ import unicode_literals
import pytest import pytest
import sys import sys
from sets import Set
from ldapcherry.backend.backendAD import Backend from ldapcherry.backend.backendAD import Backend
from ldapcherry.exceptions import * from ldapcherry.exceptions import *
from disable import travis_disabled from disable import travis_disabled
import cherrypy import cherrypy
import logging import logging
if sys.version < '3':
from sets import Set as set
cfg = { cfg = {
'display_name': u'test☭', 'display_name': u'test☭',
@ -74,14 +76,14 @@ class TestError(object):
assert res == False assert res == False
@travis_disabled @travis_disabled
def testSetPassword(self): def testsetPassword(self):
inv = Backend(cfg, cherrypy.log, u'test☭', attr, 'sAMAccountName') inv = Backend(cfg, cherrypy.log, u'test☭', attr, 'sAMAccountName')
try: try:
inv.add_user(default_user.copy()) inv.add_user(default_user.copy())
inv.add_to_groups(u'☭default_user', default_groups) inv.add_to_groups(u'☭default_user', default_groups)
except: except:
pass pass
inv.set_attrs(u'☭default_user', {'unicodePwd': u'test☭P66642$'}) inv.set_attrs(u'☭default_user', {'unicodePwd': u'test☭P66642$'})
ret = inv.auth(u'☭default_user', u'test☭P66642$') ret = inv.auth(u'☭default_user', u'test☭P66642$')
inv.del_user(u'☭default_user') inv.del_user(u'☭default_user')
assert ret == True assert ret == True
@ -126,7 +128,7 @@ class TestError(object):
expected = [u'☭default_user', u'☭default_user2'] expected = [u'☭default_user', u'☭default_user2']
inv.del_user(u'☭default_user') inv.del_user(u'☭default_user')
inv.del_user(u'☭default_user2') inv.del_user(u'☭default_user2')
assert Set(ret.keys()) == Set(expected) assert set(ret.keys()) == set(expected)
@travis_disabled @travis_disabled
def testAddUser(self): def testAddUser(self):

View File

@ -6,12 +6,14 @@ from __future__ import unicode_literals
import pytest import pytest
import sys import sys
from sets import Set
from ldapcherry.backend.backendDemo import Backend from ldapcherry.backend.backendDemo import Backend
from ldapcherry.exceptions import * from ldapcherry.exceptions import *
from disable import travis_disabled from disable import travis_disabled
import cherrypy import cherrypy
import logging import logging
if sys.version < '3':
from sets import Set as set
cfg = { cfg = {
'display_name': 'test', 'display_name': 'test',
@ -82,7 +84,7 @@ class TestError(object):
inv.add_user(default_user) inv.add_user(default_user)
inv.add_to_groups('default_user', default_groups) inv.add_to_groups('default_user', default_groups)
ret = inv.get_groups('default_user') ret = inv.get_groups('default_user')
expected = Set(default_groups) expected = set(default_groups)
assert ret == expected assert ret == expected
def testSearchUser(self): def testSearchUser(self):
@ -91,7 +93,7 @@ class TestError(object):
inv.add_user(default_user2) inv.add_user(default_user2)
ret = inv.search('default') ret = inv.search('default')
expected = ['default_user', 'default_user2'] expected = ['default_user', 'default_user2']
assert Set(ret.keys()) == Set(expected) assert set(ret.keys()) == set(expected)
def testAddUser(self): def testAddUser(self):
try: try:

View File

@ -6,13 +6,14 @@ from __future__ import unicode_literals
import pytest import pytest
import sys import sys
from sets import Set
from ldapcherry.backend.backendLdap import Backend, CaFileDontExist from ldapcherry.backend.backendLdap import Backend, CaFileDontExist
from ldapcherry.exceptions import * from ldapcherry.exceptions import *
from disable import travis_disabled from disable import travis_disabled
import cherrypy import cherrypy
import logging import logging
import ldap import ldap
if sys.version < '3':
from sets import Set as set
cfg = { cfg = {
'module' : 'ldapcherry.backend.ldap', 'module' : 'ldapcherry.backend.ldap',
@ -148,7 +149,6 @@ class TestError(object):
] ]
inv.add_to_groups(u'jwatsoné', groups) inv.add_to_groups(u'jwatsoné', groups)
ret = inv.get_groups(u'jwatsoné') ret = inv.get_groups(u'jwatsoné')
print ret
inv.del_from_groups(u'jwatsoné', ['cn=hrpeople,ou=Groups,dc=example,dc=org']) inv.del_from_groups(u'jwatsoné', ['cn=hrpeople,ou=Groups,dc=example,dc=org'])
inv.del_from_groups(u'jwatsoné', ['cn=hrpeople,ou=Groups,dc=example,dc=org']) inv.del_from_groups(u'jwatsoné', ['cn=hrpeople,ou=Groups,dc=example,dc=org'])
assert ret == ['cn=itpeople,ou=Groups,dc=example,dc=org', 'cn=hrpeople,ou=Groups,dc=example,dc=org'] assert ret == ['cn=itpeople,ou=Groups,dc=example,dc=org', 'cn=hrpeople,ou=Groups,dc=example,dc=org']

View File

@ -9,7 +9,6 @@ import subprocess
from tempfile import NamedTemporaryFile as tempfile from tempfile import NamedTemporaryFile as tempfile
import re import re
from sets import Set
from ldapcherry import LdapCherry from ldapcherry import LdapCherry
from ldapcherry.exceptions import * from ldapcherry.exceptions import *
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
@ -21,6 +20,8 @@ import logging
from ldapcherry.lclogging import * from ldapcherry.lclogging import *
from disable import * from disable import *
import json import json
if sys.version < '3':
from sets import Set as set
cherrypy.session = {} cherrypy.session = {}
@ -337,7 +338,7 @@ class TestError(object):
app = LdapCherry() app = LdapCherry()
loadconf('./tests/cfg/ldapcherry_adldap.cfg', app) loadconf('./tests/cfg/ldapcherry_adldap.cfg', app)
inv = ldapcherry.backend.backendAD.Backend(adcfg, cherrypy.log, u'test☭', adattr, 'sAMAccountName') inv = ldapcherry.backend.backendAD.Backend(adcfg, cherrypy.log, u'test☭', adattr, 'sAMAccountName')
try: try:
app._deleteuser(u'☭default_user') app._deleteuser(u'☭default_user')
except: except:
pass pass

View File

@ -6,16 +6,17 @@ from __future__ import unicode_literals
import pytest import pytest
import sys import sys
from sets import Set
from ldapcherry.roles import Roles from ldapcherry.roles import Roles
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile, MissingRole from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile, MissingRole
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
if sys.version < '3':
from sets import Set as set
class TestError(object): class TestError(object):
def testNominal(self): def testNominal(self):
inv = Roles('./tests/cfg/roles.yml') inv = Roles('./tests/cfg/roles.yml')
print inv.roles print(inv.roles)
return True return True
def testMissingDisplayName(self): def testMissingDisplayName(self):
@ -64,7 +65,7 @@ class TestError(object):
['admin-lv2', 'admin-lv3', 'users'], ['admin-lv2', 'admin-lv3', 'users'],
['admin-lv2'] ['admin-lv2']
) )
expected = {'ad': Set(['Administrators', 'Domain Controllers']), 'ldap': Set(['cn=nagios admins,ou=group,dc=example,dc=com', 'cn=puppet admins,ou=group,dc=example,dc=com', 'cn=dns admins,ou=group,dc=example,dc=com'])} expected = {'ad': set(['Administrators', 'Domain Controllers']), 'ldap': set(['cn=nagios admins,ou=group,dc=example,dc=com', 'cn=puppet admins,ou=group,dc=example,dc=com', 'cn=dns admins,ou=group,dc=example,dc=com'])}
assert groups == expected assert groups == expected
def testGetGroup(self): def testGetGroup(self):
@ -114,7 +115,7 @@ class TestError(object):
def testGetAllRoles(self): def testGetAllRoles(self):
inv = Roles('./tests/cfg/roles.yml') inv = Roles('./tests/cfg/roles.yml')
res = inv.get_backends() res = inv.get_backends()
expected = Set(['ad', 'ldap']) expected = set(['ad', 'ldap'])
assert res == expected assert res == expected
def testDumpNested(self): def testDumpNested(self):
@ -147,5 +148,5 @@ class TestError(object):
], ],
'toto': ['not a group'], 'toto': ['not a group'],
} }
expected = {'unusedgroups': {'toto': Set(['not a group']), 'ad': Set(['Domain Users 2'])}, 'roles': Set(['developpers', 'admin-lv2', 'users'])} expected = {'unusedgroups': {'toto': set(['not a group']), 'ad': set(['Domain Users 2'])}, 'roles': set(['developpers', 'admin-lv2', 'users'])}
assert inv.get_roles(groups) == expected assert inv.get_roles(groups) == expected