-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests/Lib/ldap/test_modlist.py is now Tests/t_ldap_modlist.py based o…
…n module unittest
- Loading branch information
stroeder
committed
Feb 14, 2017
1 parent
8e18435
commit 60ae0ef
Showing
2 changed files
with
151 additions
and
137 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |