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 testAddChild(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="cn=foo", attributes={ "objectClass": ["a", "b"], "cn": ["foo"], }, ) bar = b.addChild( rdn="cn=bar", attributes={ "objectClass": ["a", "b"], "cn": ["bar"], }, ) d = a.diffTree(b) d.addCallback( self.assertEqual, [ delta.AddOp(bar), delta.AddOp(foo), ], ) return d
def testAddOpInequalityDifferentEntry(self): """ Objects are not equal when the have different LDAP entries. """ first_entry = entry.BaseLDAPEntry( dn='ou=First Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) second_entry = entry.BaseLDAPEntry( dn='ou=First Team, dc=example,dc=com', attributes={'foo': ['other', 'attributes']}) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertNotEqual(first, second)
def testAddOpHashSimilar(self): """ Objects which are equal have the same hash. """ first_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) second_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertEqual(hash(first), hash(second))
def testAddOpHashDifferent(self): """ Objects which are not equal have different hash. """ first_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['one', 'attributes']}) second_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['other', 'attributes']}) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertNotEqual(hash(first), hash(second))
def testAddOpEqualitySameEntry(self): """ Objects are equal when the have the same LDAP entry. """ first_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) second_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertEqual(first, second)
def testAsLDIF(self): """ It will return the LDIF representation of the operation. """ sut = delta.AddOp( entry.BaseLDAPEntry( dn="dc=example,dc=com", attributes={ "foo": ["bar", "baz"], "quux": ["thud"], }, )) result = sut.asLDIF() self.assertEqual( b"""dn: dc=example,dc=com changetype: add foo: bar foo: baz quux: thud """, result, )
def testAdd(self): proto = LDIFDeltaDriver() proto.dataReceived(b"""\ 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=b"cn=foo,dc=example,dc=com", attributes={ b"foo": [b"bar"], b"thud": [b"quux", b"baz"], }, )) ], )
def testAddOpHashSimilar(self): """ Objects which are equal have the same hash. """ first_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) second_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertEqual(hash(first), hash(second))
def testAddOpInequalityDifferentEntry(self): """ Objects are not equal when the have different LDAP entries. """ first_entry = entry.BaseLDAPEntry( dn="ou=First Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) second_entry = entry.BaseLDAPEntry( dn="ou=First Team, dc=example,dc=com", attributes={"foo": ["other", "attributes"]}, ) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertNotEqual(first, second)
def testAddOpEqualitySameEntry(self): """ Objects are equal when the have the same LDAP entry. """ first_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) second_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertEqual(first, second)
def testAddOpHashDifferent(self): """ Objects which are not equal have different hash. """ first_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["one", "attributes"]}, ) second_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["other", "attributes"]}, ) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertNotEqual(hash(first), hash(second))
def testAddOpInequalityNoEntryObject(self): """ Objects is not equal with random objects. """ team_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) sut = delta.AddOp(team_entry) self.assertNotEqual(sut, {'foo': ['same', 'attributes']})
def testAddOpInequalityNoEntryObject(self): """ Objects is not equal with random objects. """ team_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) sut = delta.AddOp(team_entry) self.assertNotEqual(sut, {"foo": ["same", "attributes"]})
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 testRepr(self): """ Getting string representation """ sut = delta.AddOp(entry.BaseLDAPEntry( dn='dc=example,dc=com', attributes={ 'bar': ['foo'], 'foo': ['bar'], }, )) self.assertEqual(repr(sut), "AddOp(BaseLDAPEntry('dc=example,dc=com', " "{'bar': ['foo'], 'foo': ['bar']}))")
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 testAddOp_DNExists(self): """ It fails to perform the `add` operation for an existing entry. """ root = self.getRoot() root.addChild(rdn='ou=Existing Team', attributes={ 'objectClass': ['a', 'b'], 'ou': ['HR'], }) hr_entry = entry.BaseLDAPEntry( dn='ou=Existing Team, dc=example,dc=com', attributes={'foo': ['dont', 'care']}) sut = delta.AddOp(hr_entry) deferred = sut.patch(root) failure = self.failureResultOf(deferred) self.assertIsInstance(failure.value, ldaperrors.LDAPEntryAlreadyExists)
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 == b"": # 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 testAsLDIF(self): """ It will return the LDIF representation of the operation. """ sut =delta.AddOp(entry.BaseLDAPEntry( dn='dc=example,dc=com', attributes={ 'foo': ['bar', 'baz'], 'quux': ['thud'], }, )) result = sut.asLDIF() self.assertEqual(b"""dn: dc=example,dc=com changetype: add foo: bar foo: baz quux: thud """, result)
def testAddOp_DNExists(self): """ It fails to perform the `add` operation for an existing entry. """ root = self.getRoot() root.addChild( rdn="ou=Existing Team", attributes={ "objectClass": ["a", "b"], "ou": ["HR"], }, ) hr_entry = entry.BaseLDAPEntry( dn="ou=Existing Team, dc=example,dc=com", attributes={"foo": ["dont", "care"]}, ) sut = delta.AddOp(hr_entry) deferred = sut.patch(root) failure = self.failureResultOf(deferred) self.assertIsInstance(failure.value, ldaperrors.LDAPEntryAlreadyExists)
def cb2(r): d = self.root.diffTree(other) d.addCallback(self.assertEqual, [delta.AddOp(r)]) return d
def _gotSubtree(l, result): for c in l: o = delta.AddOp(c) result.append(o) return result