From 2a2864a3065eaddf15a1a6a23e4b3b8a670db11c Mon Sep 17 00:00:00 2001 From: kakwa Date: Thu, 7 Feb 2019 20:55:50 +0100 Subject: [PATCH] porting the tests over to python3 --- tests/disable.py | 4 ++-- tests/test_Attributes.py | 6 ++++-- tests/test_BackendAD.py | 10 ++++++---- tests/test_BackendDemo.py | 8 +++++--- tests/test_BackendLdap.py | 4 ++-- tests/test_LdapCherry.py | 5 +++-- tests/test_Roles.py | 11 ++++++----- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/tests/disable.py b/tests/disable.py index e42f3dc..19d48f1 100644 --- a/tests/disable.py +++ b/tests/disable.py @@ -1,7 +1,7 @@ import os def travis_disabled(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': return _decorator else: @@ -9,7 +9,7 @@ def travis_disabled(f): def slow_disabled(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': return _decorator else: diff --git a/tests/test_Attributes.py b/tests/test_Attributes.py index 7220946..f7f42b2 100644 --- a/tests/test_Attributes.py +++ b/tests/test_Attributes.py @@ -6,10 +6,12 @@ from __future__ import unicode_literals import pytest import sys -from sets import Set from ldapcherry.attributes import Attributes from ldapcherry.exceptions import * from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError +if sys.version < '3': + from sets import Set as set + class TestError(object): @@ -27,7 +29,7 @@ class TestError(object): def testGetSelfAttributes(self): inv = Attributes('./tests/cfg/attributes.yml') ret = inv.get_backends() - expected = Set(['ldap', 'ad']) + expected = set(['ldap', 'ad']) assert ret == expected def testGetSearchAttributes(self): diff --git a/tests/test_BackendAD.py b/tests/test_BackendAD.py index 0d7b870..416dde6 100644 --- a/tests/test_BackendAD.py +++ b/tests/test_BackendAD.py @@ -6,12 +6,14 @@ from __future__ import unicode_literals import pytest import sys -from sets import Set from ldapcherry.backend.backendAD import Backend from ldapcherry.exceptions import * from disable import travis_disabled import cherrypy import logging +if sys.version < '3': + from sets import Set as set + cfg = { 'display_name': u'test☭', @@ -74,14 +76,14 @@ class TestError(object): assert res == False @travis_disabled - def testSetPassword(self): + def testsetPassword(self): inv = Backend(cfg, cherrypy.log, u'test☭', attr, 'sAMAccountName') try: inv.add_user(default_user.copy()) inv.add_to_groups(u'☭default_user', default_groups) except: 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$') inv.del_user(u'☭default_user') assert ret == True @@ -126,7 +128,7 @@ class TestError(object): expected = [u'☭default_user', u'☭default_user2'] inv.del_user(u'☭default_user') inv.del_user(u'☭default_user2') - assert Set(ret.keys()) == Set(expected) + assert set(ret.keys()) == set(expected) @travis_disabled def testAddUser(self): diff --git a/tests/test_BackendDemo.py b/tests/test_BackendDemo.py index e7d94a8..7c2ac4e 100644 --- a/tests/test_BackendDemo.py +++ b/tests/test_BackendDemo.py @@ -6,12 +6,14 @@ from __future__ import unicode_literals import pytest import sys -from sets import Set from ldapcherry.backend.backendDemo import Backend from ldapcherry.exceptions import * from disable import travis_disabled import cherrypy import logging +if sys.version < '3': + from sets import Set as set + cfg = { 'display_name': 'test', @@ -82,7 +84,7 @@ class TestError(object): inv.add_user(default_user) inv.add_to_groups('default_user', default_groups) ret = inv.get_groups('default_user') - expected = Set(default_groups) + expected = set(default_groups) assert ret == expected def testSearchUser(self): @@ -91,7 +93,7 @@ class TestError(object): inv.add_user(default_user2) ret = inv.search('default') expected = ['default_user', 'default_user2'] - assert Set(ret.keys()) == Set(expected) + assert set(ret.keys()) == set(expected) def testAddUser(self): try: diff --git a/tests/test_BackendLdap.py b/tests/test_BackendLdap.py index f969324..b9e874f 100644 --- a/tests/test_BackendLdap.py +++ b/tests/test_BackendLdap.py @@ -6,13 +6,14 @@ from __future__ import unicode_literals import pytest import sys -from sets import Set from ldapcherry.backend.backendLdap import Backend, CaFileDontExist from ldapcherry.exceptions import * from disable import travis_disabled import cherrypy import logging import ldap +if sys.version < '3': + from sets import Set as set cfg = { 'module' : 'ldapcherry.backend.ldap', @@ -148,7 +149,6 @@ class TestError(object): ] inv.add_to_groups(u'jwatsoné', groups) 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']) assert ret == ['cn=itpeople,ou=Groups,dc=example,dc=org', 'cn=hrpeople,ou=Groups,dc=example,dc=org'] diff --git a/tests/test_LdapCherry.py b/tests/test_LdapCherry.py index 9c5667b..54611f2 100644 --- a/tests/test_LdapCherry.py +++ b/tests/test_LdapCherry.py @@ -9,7 +9,6 @@ import subprocess from tempfile import NamedTemporaryFile as tempfile import re -from sets import Set from ldapcherry import LdapCherry from ldapcherry.exceptions import * from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError @@ -21,6 +20,8 @@ import logging from ldapcherry.lclogging import * from disable import * import json +if sys.version < '3': + from sets import Set as set cherrypy.session = {} @@ -337,7 +338,7 @@ class TestError(object): app = LdapCherry() loadconf('./tests/cfg/ldapcherry_adldap.cfg', app) inv = ldapcherry.backend.backendAD.Backend(adcfg, cherrypy.log, u'test☭', adattr, 'sAMAccountName') - try: + try: app._deleteuser(u'☭default_user') except: pass diff --git a/tests/test_Roles.py b/tests/test_Roles.py index 5cebc08..72bddc1 100644 --- a/tests/test_Roles.py +++ b/tests/test_Roles.py @@ -6,16 +6,17 @@ from __future__ import unicode_literals import pytest import sys -from sets import Set from ldapcherry.roles import Roles from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile, MissingRole from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError +if sys.version < '3': + from sets import Set as set class TestError(object): def testNominal(self): inv = Roles('./tests/cfg/roles.yml') - print inv.roles + print(inv.roles) return True def testMissingDisplayName(self): @@ -64,7 +65,7 @@ class TestError(object): ['admin-lv2', 'admin-lv3', 'users'], ['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 def testGetGroup(self): @@ -114,7 +115,7 @@ class TestError(object): def testGetAllRoles(self): inv = Roles('./tests/cfg/roles.yml') res = inv.get_backends() - expected = Set(['ad', 'ldap']) + expected = set(['ad', 'ldap']) assert res == expected def testDumpNested(self): @@ -147,5 +148,5 @@ class TestError(object): ], '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