From 60ae0ef3e3e0da146fdd4cd6a786afc99251f95d Mon Sep 17 00:00:00 2001 From: stroeder Date: Tue, 14 Feb 2017 11:12:03 +0000 Subject: [PATCH] Tests/Lib/ldap/test_modlist.py is now Tests/t_ldap_modlist.py based on module unittest --- Tests/Lib/ldap/test_modlist.py | 137 ------------------------------ Tests/t_ldap_modlist.py | 151 +++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 137 deletions(-) delete mode 100644 Tests/Lib/ldap/test_modlist.py create mode 100644 Tests/t_ldap_modlist.py diff --git a/Tests/Lib/ldap/test_modlist.py b/Tests/Lib/ldap/test_modlist.py deleted file mode 100644 index fef0f65..0000000 --- a/Tests/Lib/ldap/test_modlist.py +++ /dev/null @@ -1,137 +0,0 @@ -""" -Tests for module ldap.modlist -""" - -import ldap - -from ldap.modlist import addModlist,modifyModlist - -print '\nTesting function addModlist():' -addModlist_tests = [ - ( - { - 'objectClass':['person','pilotPerson'], - 'cn':['Michael Str\303\266der','Michael Stroeder'], - 'sn':['Str\303\266der'], - 'dummy1':[], - 'dummy2':['2'], - 'dummy3':[''], - }, - [ - ('objectClass',['person','pilotPerson']), - ('cn',['Michael Str\303\266der','Michael Stroeder']), - ('sn',['Str\303\266der']), - ('dummy2',['2']), - ('dummy3',['']), - ] - ), -] -for entry,test_modlist in addModlist_tests: - test_modlist.sort() - result_modlist = addModlist(entry) - result_modlist.sort() - if test_modlist!=result_modlist: - print 'addModlist(%s) returns\n%s\ninstead of\n%s.' % ( - repr(entry),repr(result_modlist),repr(test_modlist) - ) - -print '\nTesting function modifyModlist():' -modifyModlist_tests = [ - - ( - { - 'objectClass':['person','pilotPerson'], - 'cn':['Michael Str\303\266der','Michael Stroeder'], - 'sn':['Str\303\266der'], - 'enum':['a','b','c'], - 'c':['DE'], - }, - { - 'objectClass':['person','inetOrgPerson'], - 'cn':['Michael Str\303\266der','Michael Stroeder'], - 'sn':[], - 'enum':['a','b','d'], - 'mail':['michael@stroeder.com'], - }, - [], - [ - (ldap.MOD_DELETE,'objectClass',None), - (ldap.MOD_ADD,'objectClass',['person','inetOrgPerson']), - (ldap.MOD_DELETE,'c',None), - (ldap.MOD_DELETE,'sn',None), - (ldap.MOD_ADD,'mail',['michael@stroeder.com']), - (ldap.MOD_DELETE,'enum',None), - (ldap.MOD_ADD,'enum',['a','b','d']), - ] - ), - - ( - { - 'c':['DE'], - }, - { - 'c':['FR'], - }, - [], - [ - (ldap.MOD_DELETE,'c',None), - (ldap.MOD_ADD,'c',['FR']), - ] - ), - - # Now a weird test-case for catching all possibilities - # of removing an attribute with MOD_DELETE,attr_type,None - ( - { - 'objectClass':['person'], - 'cn':[None], - 'sn':[''], - 'c':['DE'], - }, - { - 'objectClass':[], - 'cn':[], - 'sn':[None], - }, - [], - [ - (ldap.MOD_DELETE,'c',None), - (ldap.MOD_DELETE,'objectClass',None), - (ldap.MOD_DELETE,'sn',None), - ] - ), - - ( - { - 'objectClass':['person'], - 'cn':['Michael Str\303\266der','Michael Stroeder'], - 'sn':['Str\303\266der'], - 'enum':['a','b','C'], - }, - { - 'objectClass':['Person'], - 'cn':['Michael Str\303\266der','Michael Stroeder'], - 'sn':[], - 'enum':['a','b','c'], - }, - ['objectClass'], - [ - (ldap.MOD_DELETE,'sn',None), - (ldap.MOD_DELETE,'enum',None), - (ldap.MOD_ADD,'enum',['a','b','c']), - ] - ), - -] -for old_entry,new_entry,case_ignore_attr_types,test_modlist in modifyModlist_tests: - test_modlist.sort() - result_modlist = modifyModlist(old_entry,new_entry,case_ignore_attr_types=case_ignore_attr_types) - result_modlist.sort() - - if test_modlist!=result_modlist: - print 'modifyModlist(%s,%s) returns\n%s\ninstead of\n%s.' % ( - repr(old_entry), - repr(new_entry), - repr(result_modlist), - repr(test_modlist) - ) diff --git a/Tests/t_ldap_modlist.py b/Tests/t_ldap_modlist.py new file mode 100644 index 0000000..3d24a70 --- /dev/null +++ b/Tests/t_ldap_modlist.py @@ -0,0 +1,151 @@ +""" +Tests for module ldap.modlist +""" +import unittest + +import ldap + +from ldap.modlist import addModlist,modifyModlist + +class TestModlist(unittest.TestCase): + + addModlist_tests = [ + ( + { + 'objectClass':['person','pilotPerson'], + 'cn':['Michael Str\303\266der','Michael Stroeder'], + 'sn':['Str\303\266der'], + 'dummy1':[], + 'dummy2':['2'], + 'dummy3':[''], + }, + [ + ('objectClass',['person','pilotPerson']), + ('cn',['Michael Str\303\266der','Michael Stroeder']), + ('sn',['Str\303\266der']), + ('dummy2',['2']), + ('dummy3',['']), + ] + ), + ] + + def test_addModlist(self): + for entry,test_modlist in self.addModlist_tests: + test_modlist.sort() + result_modlist = addModlist(entry) + result_modlist.sort() + self.assertEqual( + test_modlist, result_modlist, + 'addModlist(%s) returns\n%s\ninstead of\n%s.' % ( + repr(entry),repr(result_modlist),repr(test_modlist) + ) + ) + + modifyModlist_tests = [ + ( + { + 'objectClass':['person','pilotPerson'], + 'cn':['Michael Str\303\266der','Michael Stroeder'], + 'sn':['Str\303\266der'], + 'enum':['a','b','c'], + 'c':['DE'], + }, + { + 'objectClass':['person','inetOrgPerson'], + 'cn':['Michael Str\303\266der','Michael Stroeder'], + 'sn':[], + 'enum':['a','b','d'], + 'mail':['michael@stroeder.com'], + }, + [], + [ + (ldap.MOD_DELETE,'objectClass',None), + (ldap.MOD_ADD,'objectClass',['person','inetOrgPerson']), + (ldap.MOD_DELETE,'c',None), + (ldap.MOD_DELETE,'sn',None), + (ldap.MOD_ADD,'mail',['michael@stroeder.com']), + (ldap.MOD_DELETE,'enum',None), + (ldap.MOD_ADD,'enum',['a','b','d']), + ] + ), + + ( + { + 'c':['DE'], + }, + { + 'c':['FR'], + }, + [], + [ + (ldap.MOD_DELETE,'c',None), + (ldap.MOD_ADD,'c',['FR']), + ] + ), + + # Now a weird test-case for catching all possibilities + # of removing an attribute with MOD_DELETE,attr_type,None + ( + { + 'objectClass':['person'], + 'cn':[None], + 'sn':[''], + 'c':['DE'], + }, + { + 'objectClass':[], + 'cn':[], + 'sn':[None], + }, + [], + [ + (ldap.MOD_DELETE,'c',None), + (ldap.MOD_DELETE,'objectClass',None), + (ldap.MOD_DELETE,'sn',None), + ] + ), + + ( + { + 'objectClass':['person'], + 'cn':['Michael Str\303\266der','Michael Stroeder'], + 'sn':['Str\303\266der'], + 'enum':['a','b','C'], + }, + { + 'objectClass':['Person'], + 'cn':['Michael Str\303\266der','Michael Stroeder'], + 'sn':[], + 'enum':['a','b','c'], + }, + ['objectClass'], + [ + (ldap.MOD_DELETE,'sn',None), + (ldap.MOD_DELETE,'enum',None), + (ldap.MOD_ADD,'enum',['a','b','c']), + ] + ), + + ] + + def test_modifyModlist(self): + for old_entry, new_entry, case_ignore_attr_types, test_modlist in self.modifyModlist_tests: + test_modlist.sort() + result_modlist = modifyModlist( + old_entry, new_entry, + case_ignore_attr_types=case_ignore_attr_types) + result_modlist.sort() + + self.assertEqual( + test_modlist, result_modlist, + 'modifyModlist(%s,%s) returns\n%s\ninstead of\n%s.' % ( + repr(old_entry), + repr(new_entry), + repr(result_modlist), + repr(test_modlist), + ) + ) + + +if __name__ == '__main__': + unittest.main()