def testDeleteSubtree(self): a = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName('dc=example,dc=com')) b = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName('dc=example,dc=com')) foo = a.addChild(rdn='ou=foo', attributes={ 'objectClass': ['a', 'b'], 'ou': ['foo'], }) baz = foo.addChild(rdn='cn=baz', attributes={ 'objectClass': ['a', 'b'], 'cn': ['baz'], }) bar = a.addChild(rdn='cn=bar', attributes={ 'objectClass': ['a', 'b'], 'cn': ['bar'], }) d = a.diffTree(b) d.addCallback(self.assertEquals, [ delta.DeleteOp(bar), delta.DeleteOp(baz), delta.DeleteOp(foo), ]) return d
def testDeleteChild(self): a = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName("dc=example,dc=com")) b = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName("dc=example,dc=com")) foo = a.addChild( rdn="cn=foo", attributes={ "objectClass": ["a", "b"], "cn": ["foo"], }, ) bar = a.addChild( rdn="cn=bar", attributes={ "objectClass": ["a", "b"], "cn": ["bar"], }, ) d = a.diffTree(b) d.addCallback( self.assertEqual, [ delta.DeleteOp(bar), delta.DeleteOp(foo), ], ) return d
def testDeleteOpEqualitySameDN(self): """ Objects are equal when the have the same DN. """ first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') second_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') first = delta.DeleteOp(first_entry) second = delta.DeleteOp(second_entry) self.assertEqual(first, second)
def testDeleteOpHashSimilar(self): """ Objects which are equal have the same hash. """ first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') second_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') first = delta.DeleteOp(first_entry) second = delta.DeleteOp(second_entry) self.assertEqual(hash(first), hash(second))
def testDeleteOpHashDifferent(self): """ Objects which are not equal have different hash. """ first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') second_entry = entry.BaseLDAPEntry(dn='ou=Cowboys, dc=example,dc=com') first = delta.DeleteOp(first_entry) second = delta.DeleteOp(second_entry) self.assertNotEqual(hash(first), hash(second))
def testDeleteOpInequalityDifferentEntry(self): """ DeleteOp objects are not equal when the have different LDAP entries. """ first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') second_entry = entry.BaseLDAPEntry(dn='ou=Cowboys, dc=example,dc=com') first = delta.DeleteOp(first_entry) second = delta.DeleteOp(second_entry) self.assertNotEqual(first, second)
def testDeleteOpEqualityEqualDN(self): """ DeleteOp objects are equal if their DNs are equal. """ first_dn = distinguishedname.DistinguishedName( stringValue="ou=Team,dc=example,dc=com") first = delta.DeleteOp(first_dn) second_entry = entry.BaseLDAPEntry(dn="ou=Team, dc=example, dc=com") second = delta.DeleteOp(second_entry) third = delta.DeleteOp("ou=Team, dc=example,dc=com") self.assertEqual(first, second) self.assertEqual(first, third)
def testDeleteOp_DNNotFound(self): op = delta.DeleteOp('cn=nope,dc=example,dc=com') d = op.patch(self.root) def eb(fail): fail.trap(ldaperrors.LDAPNoSuchObject) d.addCallbacks(testutil.mustRaise, eb) return d
def testRepr(self): """ Getting string representation """ sut = delta.DeleteOp('dc=example,dc=com') self.assertEqual(repr(sut), "DeleteOp('dc=example,dc=com')")
def testSimple(self): op=delta.DeleteOp('dc=example,dc=com') self.assertEquals(op.asLDIF(), """\ dn: dc=example,dc=com changetype: delete """)
def testDeleteOpInequalityNoEntryObject(self): """ DeleteOp objects is not equal with random objects. """ team_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') sut = delta.DeleteOp(team_entry) self.assertNotEqual(sut, 'ou=Team, dc=example,dc=com')
def testAsLDIF(self): """ It return the LDIF representation of the delete operation. """ sut = delta.DeleteOp('dc=example,dc=com') result = sut.asLDIF() self.assertEqual(b"""dn: dc=example,dc=com changetype: delete """, result)
def testDelete(self): proto = LDIFDeltaDriver() proto.dataReceived("""\ version: 1 dn: cn=foo,dc=example,dc=com changetype: delete """) proto.connectionLost() self.assertEqual(proto.listOfCompleted, [delta.DeleteOp(dn='cn=foo,dc=example,dc=com')])
def testDeleteOp_DNNotFound(self): """ If fail to delete when the RDN does not exists. """ root = self.getRoot() sut = delta.DeleteOp('cn=nope,dc=example,dc=com') deferred = sut.patch(root) failure = self.failureResultOf(deferred) self.assertIsInstance(failure.value, ldaperrors.LDAPNoSuchObject)
def state_IN_DELETE(self, line): assert self.dn is not None, "self.dn must be set when in entry" if line == b"": # end of entry self.mode = ldifprotocol.WAIT_FOR_DN o = delta.DeleteOp(dn=self.dn) self.dn = None self.data = None self.gotEntry(o) return raise LDIFDeltaDeleteHasJunkAfterChangeTypeError(self.dn, line)
def testDelete(self): """" Triggers a DeleteOp when the diff action is `delete`. """ proto = LDIFDeltaDriver() proto.dataReceived(b"""\ version: 1 dn: cn=foo,dc=example,dc=com changetype: delete """) proto.connectionLost() self.assertEqual(proto.listOfCompleted, [delta.DeleteOp(dn=b'cn=foo,dc=example,dc=com')])
def _gotSubtree(l, result): l.reverse() # remove children before their parent for c in l: o = delta.DeleteOp(c) result.append(o) return result
def cb3(got): self.assertEqual(got, [delta.DeleteOp(self.empty)])