예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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)
예제 #4
0
    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))
예제 #5
0
    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))
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
 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
예제 #9
0
    def testRepr(self):
        """
        Getting string representation
        """
        sut = delta.DeleteOp('dc=example,dc=com')

        self.assertEqual(repr(sut), "DeleteOp('dc=example,dc=com')")
예제 #10
0
    def testSimple(self):
        op=delta.DeleteOp('dc=example,dc=com')
        self.assertEquals(op.asLDIF(),
                          """\
dn: dc=example,dc=com
changetype: delete

""")
예제 #11
0
    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')
예제 #12
0
    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)
예제 #13
0
    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')])
예제 #14
0
    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)
예제 #15
0
    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)
예제 #16
0
    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')])
예제 #17
0
 def _gotSubtree(l, result):
     l.reverse()  # remove children before their parent
     for c in l:
         o = delta.DeleteOp(c)
         result.append(o)
     return result
예제 #18
0
 def cb3(got):
     self.assertEqual(got, [delta.DeleteOp(self.empty)])