forked from python-ldap/python-ldap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht_ldap_modlist.py
More file actions
155 lines (139 loc) · 4.46 KB
/
t_ldap_modlist.py
File metadata and controls
155 lines (139 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- coding: utf-8 -*-
"""
Automatic tests for python-ldap's module ldap.modlist
See https://www.python-ldap.org/ for details.
"""
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()