Package ldaptor :: Package test :: Module test_ldifdelta
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.test.test_ldifdelta

  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   
9 -class LDIFDeltaDriver(ldifdelta.LDIFDelta):
10 - def __init__(self):
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
60 -class TestLDIFDeltaParsing(unittest.TestCase):
61 - def testModification_empty(self):
62 proto = LDIFDeltaDriver() 63 proto.dataReceived("""\ 64 version: 1 65 dn: cn=foo,dc=example,dc=com 66 changetype: modify 67 68 """) 69 proto.connectionLost() 70 self.assertEqual(proto.listOfCompleted, 71 [ 72 delta.ModifyOp(dn='cn=foo,dc=example,dc=com'), 73 ])
74
75 - def testModification_oneAdd(self):
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
94 - def testModification_twoAdds(self):
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
118 - def testModification_complex(self):
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
160 proto = LDIFDeltaDriver() 161 self.assertRaises(ldifdelta.LDIFDeltaModificationMissingEndDashError, 162 proto.dataReceived, 163 """\ 164 version: 1 165 dn: cn=foo,dc=example,dc=com 166 changetype: modify 167 add: foo 168 foo: bar 169 170 """)
171
173 proto = LDIFDeltaDriver() 174 self.assertRaises(ldifdelta.LDIFDeltaModificationMissingEndDashError, 175 proto.dataReceived, 176 """\ 177 version: 1 178 dn: cn=foo,dc=example,dc=com 179 changetype: modify 180 add: foo 181 182 """)
183
185 proto = LDIFDeltaDriver() 186 self.assertRaises(ldifdelta.LDIFDeltaModificationDifferentAttributeTypeError, 187 proto.dataReceived, 188 """\ 189 version: 1 190 dn: cn=foo,dc=example,dc=com 191 changetype: modify 192 add: foo 193 bar: quux 194 - 195 196 """)
197
199 proto = LDIFDeltaDriver() 200 self.assertRaises(ldifdelta.LDIFDeltaUnknownModificationError, 201 proto.dataReceived, 202 """\ 203 version: 1 204 dn: cn=foo,dc=example,dc=com 205 changetype: modify 206 fiddle: foo 207 foo: bar 208 - 209 210 """)
211
212 - def testNoChangeType(self):
213 proto = LDIFDeltaDriver() 214 self.assertRaises(ldifdelta.LDIFDeltaMissingChangeTypeError, 215 proto.dataReceived, 216 """\ 217 version: 1 218 dn: cn=foo,dc=example,dc=com 219 add: foo 220 foo: bar 221 - 222 223 """)
224
225 - def testAdd(self):
226 proto = LDIFDeltaDriver() 227 proto.dataReceived("""\ 228 version: 1 229 dn: cn=foo,dc=example,dc=com 230 changetype: add 231 foo: bar 232 thud: quux 233 thud: baz 234 235 """) 236 proto.connectionLost() 237 self.assertEqual(proto.listOfCompleted, 238 [delta.AddOp(entry.BaseLDAPEntry( 239 dn='cn=foo,dc=example,dc=com', 240 attributes={ 241 'foo': ['bar'], 242 'thud': ['quux', 'baz'], 243 }))])
244
245 - def testAdd_fail_noAttrvals(self):
246 proto = LDIFDeltaDriver() 247 self.assertRaises(ldifdelta.LDIFDeltaAddMissingAttributesError, 248 proto.dataReceived, """\ 249 version: 1 250 dn: cn=foo,dc=example,dc=com 251 changetype: add 252 253 """)
254
255 - def testDelete(self):
256 proto = LDIFDeltaDriver() 257 proto.dataReceived("""\ 258 version: 1 259 dn: cn=foo,dc=example,dc=com 260 changetype: delete 261 262 """) 263 proto.connectionLost() 264 self.assertEqual(proto.listOfCompleted, 265 [delta.DeleteOp(dn='cn=foo,dc=example,dc=com')])
266