Ejemplo n.º 1
0
 def test_diffTree_copy(self):
     otherDir = self.mktemp()
     shutil.copytree(self.tree, otherDir)
     other = ldiftree.LDIFTreeEntry(otherDir)
     d = self.root.diffTree(other)
     d.addCallback(self.assertEqual, [])
     return d
Ejemplo n.º 2
0
    def test_diffTree_edit(self):
        otherDir = self.mktemp()
        shutil.copytree(self.tree, otherDir)
        other = ldiftree.LDIFTreeEntry(otherDir)

        d = other.lookup("ou=empty,dc=example,dc=com")

        def cb1(otherEmpty):
            otherEmpty["foo"] = ["bar"]
            return otherEmpty.commit()

        d.addCallback(cb1)

        def cb2(dummy):
            return self.root.diffTree(other)

        d.addCallback(cb2)

        def cb3(got):
            self.assertEqual(
                got,
                [
                    delta.ModifyOp(
                        self.empty.dn,
                        [delta.Add(b"foo", [b"bar"])],
                    ),
                ],
            )

        d.addCallback(cb3)
        return d
Ejemplo n.º 3
0
    async def test_diffTree_edit_failure(self):
        otherDir = self.mktemp()
        shutil.copytree(self.tree, otherDir)
        other = ldiftree.LDIFTreeEntry(otherDir)

        otherEmpty = await other.lookup("ou=empty,dc=example,dc=com")
        otherEmpty["foo"] = ["bar"]
        shutil.rmtree(otherDir)
        observer = testing.EventLoggingObserver.createWithCleanup(self, log)
        self.assertFalse(await otherEmpty.commit())
        self.assertEqual(
            observer[0]["log_text"],
            "[ERROR] Could not commit entry: ou=empty,dc=example,dc=com.",
        )
Ejemplo n.º 4
0
    def test_diffTree_delChild(self):
        otherDir = self.mktemp()
        shutil.copytree(self.tree, otherDir)
        other = ldiftree.LDIFTreeEntry(otherDir)

        d = other.lookup('ou=empty,dc=example,dc=com')
        def cb1(otherEmpty):
            return otherEmpty.delete()
        d.addCallback(cb1)
        def cb2(dummy):
            return self.root.diffTree(other)
        d.addCallback(cb2)
        def cb3(got):
            self.assertEqual(got, [delta.DeleteOp(self.empty)])
        d.addCallback(cb3)
        return d
Ejemplo n.º 5
0
    def test_diffTree_addChild(self):
        otherDir = self.mktemp()
        shutil.copytree(self.tree, otherDir)
        other = ldiftree.LDIFTreeEntry(otherDir)
        e = entry.BaseLDAPEntry(dn='cn=foo,dc=example,dc=com')
        d = ldiftree.put(otherDir, e)

        def cb1(dummy):
            return other.lookup('cn=foo,dc=example,dc=com')
        d.addCallback(cb1)

        def cb2(r):
            d = self.root.diffTree(other)
            d.addCallback(self.assertEqual, [delta.AddOp(r)])
            return d
        d.addCallback(cb2)
        return d
Ejemplo n.º 6
0
    def setUp(self):
        super().setUp()
        self.tree = self.mktemp()
        os.mkdir(self.tree)
        com = os.path.join(self.tree, "dc=com.dir")
        os.mkdir(com)
        example = os.path.join(com, "dc=example.dir")
        os.mkdir(example)
        meta = os.path.join(example, "ou=metasyntactic.dir")
        os.mkdir(meta)
        writeFile(
            os.path.join(example, "ou=metasyntactic.ldif"),
            b"""\
dn: ou=metasyntactic,dc=example,dc=com
objectClass: a
objectClass: b
ou: metasyntactic

""",
        )
        foo = os.path.join(meta, "cn=foo.dir")
        writeFile(
            os.path.join(meta, "cn=foo.ldif"),
            b"""\
dn: cn=foo,ou=metasyntactic,dc=example,dc=com
objectClass: a
objectClass: b
cn: foo

""",
        )
        bar = os.path.join(meta, "cn=bar.dir")
        writeFile(
            os.path.join(meta, "cn=bar.ldif"),
            b"""\
dn: cn=bar,ou=metasyntactic,dc=example,dc=com
objectClass: a
objectClass: b
cn: bar

""",
        )
        empty = os.path.join(example, "ou=empty.dir")
        writeFile(
            os.path.join(example, "ou=empty.ldif"),
            b"""\
dn: ou=empty,dc=example,dc=com
objectClass: a
objectClass: b
ou: empty

""",
        )
        oneChild = os.path.join(example, "ou=oneChild.dir")
        os.mkdir(oneChild)
        writeFile(
            os.path.join(example, "ou=oneChild.ldif"),
            b"""\
dn: ou=oneChild,dc=example,dc=com
objectClass: a
objectClass: b
ou: oneChild

""",
        )
        theChild = os.path.join(oneChild, "cn=theChild.dir")
        writeFile(
            os.path.join(oneChild, "cn=theChild.ldif"),
            b"""\
dn: cn=theChild,ou=oneChild,dc=example,dc=com
objectClass: a
objectClass: b
cn: theChild

""",
        )
        # Invalid file
        writeFile(os.path.join(oneChild, "cn=invalidChild.lddd"), b"invalid data")

        self.root = ldiftree.LDIFTreeEntry(self.tree)
        self.example = ldiftree.LDIFTreeEntry(example, "dc=example,dc=com")
        self.empty = ldiftree.LDIFTreeEntry(empty, "ou=empty,dc=example,dc=com")
        self.meta = ldiftree.LDIFTreeEntry(meta, "ou=metasyntactic,dc=example,dc=com")
        self.foo = ldiftree.LDIFTreeEntry(
            foo, "cn=foo,ou=metasyntactic,dc=example,dc=com"
        )
        self.bar = ldiftree.LDIFTreeEntry(
            bar, "cn=bar,ou=metasyntactic,dc=example,dc=com"
        )
        self.oneChild = ldiftree.LDIFTreeEntry(
            oneChild, "ou=oneChild,dc=example,dc=com"
        )
        self.theChild = ldiftree.LDIFTreeEntry(
            theChild, "cn=theChild,ou=oneChild,dc=example,dc=com"
        )
Ejemplo n.º 7
0
    def setUp(self):
        self.tree = self.mktemp()
        os.mkdir(self.tree)
        com = os.path.join(self.tree, 'dc=com.dir')
        os.mkdir(com)
        example = os.path.join(com, 'dc=example.dir')
        os.mkdir(example)
        meta = os.path.join(example, 'ou=metasyntactic.dir')
        os.mkdir(meta)
        writeFile(
            os.path.join(example, 'ou=metasyntactic.ldif'), """\
dn: ou=metasyntactic,dc=example,dc=com
objectClass: a
objectClass: b
ou: metasyntactic

""")
        foo = os.path.join(meta, 'cn=foo.dir')
        writeFile(
            os.path.join(meta, 'cn=foo.ldif'), """\
dn: cn=foo,ou=metasyntactic,dc=example,dc=com
objectClass: a
objectClass: b
cn: foo

""")
        bar = os.path.join(meta, 'cn=bar.dir')
        writeFile(
            os.path.join(meta, 'cn=bar.ldif'), """\
dn: cn=bar,ou=metasyntactic,dc=example,dc=com
objectClass: a
objectClass: b
cn: bar

""")
        empty = os.path.join(example, 'ou=empty.dir')
        writeFile(
            os.path.join(example, 'ou=empty.ldif'), """\
dn: ou=empty,dc=example,dc=com
objectClass: a
objectClass: b
ou: empty

""")
        oneChild = os.path.join(example, 'ou=oneChild.dir')
        os.mkdir(oneChild)
        writeFile(
            os.path.join(example, 'ou=oneChild.ldif'), """\
dn: ou=oneChild,dc=example,dc=com
objectClass: a
objectClass: b
ou: oneChild

""")
        theChild = os.path.join(oneChild, 'cn=theChild.dir')
        writeFile(
            os.path.join(oneChild, 'cn=theChild.ldif'), """\
dn: cn=theChild,ou=oneChild,dc=example,dc=com
objectClass: a
objectClass: b
cn: theChild

""")
        self.root = ldiftree.LDIFTreeEntry(self.tree)
        self.example = ldiftree.LDIFTreeEntry(example, 'dc=example,dc=com')
        self.empty = ldiftree.LDIFTreeEntry(empty,
                                            'ou=empty,dc=example,dc=com')
        self.meta = ldiftree.LDIFTreeEntry(
            meta, 'ou=metasyntactic,dc=example,dc=com')
        self.foo = ldiftree.LDIFTreeEntry(
            foo, 'cn=foo,ou=metasyntactic,dc=example,dc=com')
        self.bar = ldiftree.LDIFTreeEntry(
            bar, 'cn=bar,ou=metasyntactic,dc=example,dc=com')
        self.oneChild = ldiftree.LDIFTreeEntry(
            oneChild, 'ou=oneChild,dc=example,dc=com')
        self.theChild = ldiftree.LDIFTreeEntry(
            theChild, 'cn=theChild,ou=oneChild,dc=example,dc=com')