def testAddSubtree(self): a = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName('dc=example,dc=com')) b = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName('dc=example,dc=com')) foo=b.addChild( rdn='ou=foo', attributes={ 'objectClass': ['a', 'b'], 'ou': ['foo'], }) baz=foo.addChild( rdn='cn=baz', attributes={ 'objectClass': ['a', 'b'], 'cn': ['baz'], }) bar=b.addChild( rdn='cn=bar', attributes={ 'objectClass': ['a', 'b'], 'cn': ['bar'], }) d = a.diffTree(b) d.addCallback(self.assertEquals, [ delta.AddOp(bar), delta.AddOp(foo), delta.AddOp(baz), ]) return d
def testAddOp_DNExists(self): foo2 = entry.BaseLDAPEntry( dn='cn=foo,ou=metasyntactic,dc=example,dc=com', attributes={'foo': ['bar', 'baz'], 'quux': ['thud']}) op = delta.AddOp(foo2) d = op.patch(self.root) def eb(fail): fail.trap(ldaperrors.LDAPEntryAlreadyExists) d.addCallbacks(testutil.mustRaise, eb) return d
def testSimple(self): op=delta.AddOp(entry.BaseLDAPEntry( dn='dc=example,dc=com', attributes={'foo': ['bar', 'baz'], 'quux': ['thud']})) self.assertEquals(op.asLDIF(), """\ dn: dc=example,dc=com changetype: add foo: bar foo: baz quux: thud """)
def testAdd(self): proto = LDIFDeltaDriver() proto.dataReceived("""\ version: 1 dn: cn=foo,dc=example,dc=com changetype: add foo: bar thud: quux thud: baz """) proto.connectionLost() self.assertEqual(proto.listOfCompleted, [delta.AddOp(entry.BaseLDAPEntry( dn='cn=foo,dc=example,dc=com', attributes={ 'foo': ['bar'], 'thud': ['quux', 'baz'], }))])
def state_IN_ADD_ENTRY(self, line): assert self.dn is not None, 'self.dn must be set when in entry' assert self.data is not None, 'self.data must be set when in entry' if line == '': # end of entry if not self.data: raise LDIFDeltaAddMissingAttributesError, \ self.dn self.mode = ldifprotocol.WAIT_FOR_DN o = delta.AddOp( entry.BaseLDAPEntry(dn=self.dn, attributes=self.data)) self.dn = None self.data = None self.gotEntry(o) return key, val = self._parseLine(line) if not key in self.data: self.data[key] = [] self.data[key].append(val)
def _gotSubtree(l, result): for c in l: o = delta.AddOp(c) result.append(o) return result
def cb2(r): d = self.root.diffTree(other) d.addCallback(self.assertEquals, [delta.AddOp(r)]) return d