1 """
2 Test cases for ldaptor.protocols.ldap.ldifdelta
3 """
4
5 from twisted.trial import unittest
6 from ldaptor.protocols.ldap import ldifdelta
7 from ldaptor import delta, entry
8
11 self.listOfCompleted = []
12 - def gotEntry(self, obj):
13 self.listOfCompleted.append(obj)
14
15
16 """
17 changerecord = "changetype:" FILL
18 (change-add / change-delete /
19 change-modify / change-moddn)
20
21 change-add = "add" SEP 1*attrval-spec
22
23 change-delete = "delete" SEP
24
25 change-moddn = ("modrdn" / "moddn") SEP
26 "newrdn:" ( FILL rdn /
27 ":" FILL base64-rdn) SEP
28 "deleteoldrdn:" FILL ("0" / "1") SEP
29 0*1("newsuperior:"
30 ( FILL distinguishedName /
31 ":" FILL base64-distinguishedName) SEP)
32
33 change-modify = "modify" SEP *mod-spec
34
35 mod-spec = ("add:" / "delete:" / "replace:")
36 FILL AttributeDescription SEP
37 *attrval-spec
38 "-" SEP
39 """
40
41
42 """
43 version: 1
44 dn: cn=foo,dc=example,dc=com
45 changetype: delete
46
47 """
48
49 """
50 version: 1
51 dn: cn=foo,dc=example,dc=com
52 changetype: modrdn #OR moddn
53 newrdn: rdn
54 deleteoldrdn: 0 #OR 1
55 #0..1 newsuperior: distinguishedName
56
57 """
58
59
74
76 proto = LDIFDeltaDriver()
77 proto.dataReceived("""\
78 version: 1
79 dn: cn=foo,dc=example,dc=com
80 changetype: modify
81 add: foo
82 foo: bar
83 -
84
85 """)
86 proto.connectionLost()
87 self.assertEqual(
88 proto.listOfCompleted,
89 [delta.ModifyOp(dn='cn=foo,dc=example,dc=com',
90 modifications=[delta.Add('foo', ['bar']),
91 ]),
92 ])
93
95 proto = LDIFDeltaDriver()
96 proto.dataReceived("""\
97 version: 1
98 dn: cn=foo,dc=example,dc=com
99 changetype: modify
100 add: foo
101 foo: bar
102 -
103 add: thud
104 thud: quux
105 thud: baz
106 -
107
108 """)
109 proto.connectionLost()
110 self.assertEqual(
111 proto.listOfCompleted,
112 [delta.ModifyOp(dn='cn=foo,dc=example,dc=com',
113 modifications=[delta.Add('foo', ['bar']),
114 delta.Add('thud', ['quux', 'baz']),
115 ]),
116 ])
117
119 proto = LDIFDeltaDriver()
120 proto.dataReceived("""\
121 version: 1
122 dn: cn=foo,dc=example,dc=com
123 changetype: modify
124 delete: foo
125 foo: bar
126 -
127 delete: garply
128 -
129 add: thud
130 thud: quux
131 thud: baz
132 -
133 replace: waldo
134 -
135 add: foo
136 foo: baz
137 -
138 replace: thud
139 thud: xyzzy
140 -
141 add: silly
142 -
143
144 """)
145 proto.connectionLost()
146 self.assertEqual(
147 proto.listOfCompleted,
148 [delta.ModifyOp(dn='cn=foo,dc=example,dc=com',
149 modifications=[delta.Delete('foo', ['bar']),
150 delta.Delete('garply'),
151 delta.Add('thud', ['quux', 'baz']),
152 delta.Replace('waldo'),
153 delta.Add('foo', ['baz']),
154 delta.Replace('thud', ['xyzzy']),
155 delta.Add('silly'),
156 ]),
157 ])
158
171
183
197
211
224
244
254
266