Beispiel #1
0
    def testGetNodeByPath(self):
        root = Directory("")
        
        node = File("file_a")
        node.hash = "asdf1234"
        node.addTo(root)

        node = File("file_b")
        node.hash = "asdf5678"
        node.addTo(root)

        dirnode = Directory("dir")
        dirnode.addTo(root)

        node = File('subfile_a')
        node.hash = "fda1234"
        node.addTo(dirnode)

        node = File('subfile_b')
        node.hash = "fda1234"
        node.addTo(dirnode)

        manifest = Manifest(root)

        self.assertEquals('subfile_a', manifest.node_by_path('/dir/subfile_a').name)
        self.assertEquals('subfile_a', manifest.node_by_path('dir/subfile_a').name)
        self.assertEquals(None, manifest.node_by_path('nonedir/nonefile'))
Beispiel #2
0
    def testIterate(self):
        root = Directory("root")
        
        node = File("file_a")
        node.hash = "asdf1234"
        node.addTo(root)

        node = File("file_b")
        node.hash = "asdf5678"
        node.addTo(root)

        dirnode = Directory("dir")
        dirnode.addTo(root)

        node = File('subfile_a')
        node.hash = "fda1234"
        node.addTo(dirnode)

        node = File('subfile_b')
        node.hash = "fda1234"
        node.addTo(dirnode)

        manifest = Manifest(root)

        files = []

        for file in manifest:
            files.append(file)
        
        self.assertEquals(6,len(files))
Beispiel #3
0
    def testListOfHashes(self):
        root = Directory("")
        
        node = File("file_a")
        node.hash = "asdf1234"
        node.addTo(root)

        node = File("file_b")
        node.hash = "asdf5678"
        node.addTo(root)

        dirnode = Directory("dir")
        dirnode.addTo(root)

        node = File('subfile_a')
        node.hash = "fda1234"
        node.addTo(dirnode)

        node = File('subfile_b')
        node.hash = "fda1234"
        node.addTo(dirnode)

        manifest = Manifest(root)

        hashes = manifest.get_hashes()

        self.assertEquals(4, len(hashes))

        for node in manifest:
            if isinstance(node, File):
                self.assertTrue((node.hash, node.stats.st_size) in hashes)
Beispiel #4
0
    def setUp(self):
        root = Directory("orig")
        File('testfile_a').addTo(root)
        File('testfile_b').addTo(root)

        testdir = Directory('testdir')
        testdir.addTo(root)
        another_dir = Directory('another_dir')
        another_dir.addTo(testdir)
        File('deep_file').addTo(another_dir)
        Directory('second_testdir').addTo(root)

        self.orig = Manifest(root)
Beispiel #5
0
    def testSubtractEmptyDir(self):
        newroot = Directory("orig")
        new = Manifest(newroot)
        target = new - self.orig

        self.assertFalse(target == self.orig)

        for node in target.root:
            self.assertTrue(isinstance(node, RMNode) or node == target.root)
Beispiel #6
0
 def setUp(self):
     root = Directory("")
     File("testfile-1").addTo(root)
     File("testfile-2").addTo(root)
     self.manifest = Manifest(root)
     self.patcher = Autopatcher('tmp/autopatcher')
     self.server = MisServer(MemRepository(), self.patcher, None)
     self.server.repository.addXML("debian-1.xml")
     self.server.repository.addXML("debian-1.1.xml", self.manifest)
Beispiel #7
0
    def testRecursive(self):
        """test merge with subfolders"""
        newroot = Directory("orig")
        testdir = Directory('testdir')

        testdir.addTo(newroot)
        File('new_file').addTo(testdir)
        deep_testdir = Directory('deep_testdir')
        deep_testdir.addTo(testdir)
        File('deep_testfile').addTo(deep_testdir)
        new = Manifest(newroot)
        target = self.orig + new
        self.assertTrue(
            newroot.children_as_dict['testdir'].children_as_dict['new_file'] ==
            target.root.children_as_dict['testdir'].
            children_as_dict['new_file'])

        self.assertFalse(
            newroot.children_as_dict['testdir'].children_as_dict['new_file'] is
            target.root.children_as_dict['testdir'].
            children_as_dict['new_file'])

        self.assertTrue(
            newroot.children_as_dict['testdir'].
            children_as_dict['deep_testdir'].children_as_dict['deep_testfile']
            == target.root.children_as_dict['testdir'].
            children_as_dict['deep_testdir'].children_as_dict['deep_testfile'])

        self.assertFalse(
            newroot.children_as_dict['testdir'].children_as_dict['new_file'] is
            target.root.children_as_dict['testdir'].
            children_as_dict['new_file'])

        newroot.children_as_dict['testdir'].children_as_dict[
            'new_file'].stats.st_gid = 1234
        self.assertNotEquals(
            newroot.children_as_dict['testdir'].children_as_dict['new_file'],
            target.root.children_as_dict['testdir'].
            children_as_dict['new_file'])

        self.assertTrue('another_dir' in target.root.
                        children_as_dict['testdir'].children_as_dict)
Beispiel #8
0
    def testWhiteouts(self):
        """test merge of manifests containing whiteouts"""
        newroot = Directory('testdir')
        WhiteoutNode("testfile_a").addTo(newroot)
        WhiteoutNode("testfile_b").addTo(newroot)
        WhiteoutNode("testfile_a").addTo(self.orig.root)

        target = self.orig + Manifest(newroot)

        self.assertTrue("testfile_b" in target.root.children_as_dict)
        self.assertTrue("testfile_a" in target.root.children_as_dict)
        self.assertTrue(
            isinstance(target.root.children_as_dict["testfile_a"],
                       WhiteoutNode))
        self.assertTrue(
            isinstance(target.root.children_as_dict["testfile_b"],
                       WhiteoutNode))
Beispiel #9
0
    def testSubtractSingleFile(self):
        newroot = Directory("orig")
        testdir = Directory("testdir")
        another_dir = Directory("another_dir")
        deep_file = File("deep_file")

        another_dir.addTo(testdir)
        testdir.addTo(newroot)
        new = Manifest(newroot)

        self.assertFalse(
            self.orig.node_by_path('orig/testdir/another_dir/deep_file') is
            None)
        target = new - self.orig

        self.assertFalse(target.node_by_path('/testdir') is None)
        self.assertFalse(
            target.node_by_path('/testdir/another_dir/deep_file') is None)

        deep_file.addTo(another_dir)
        target = new - self.orig

        self.assertTrue(target.node_by_path('/testdir') is None)
Beispiel #10
0
    def testBasics(self):
        """test merge on self"""

        #merge with self equals
        target = self.orig + self.orig
        self.assertEquals(target.root, self.orig.root)
        self.assertEquals(target, self.orig)

        #merge doesnt modify sources
        target = self.orig + self.orig
        self.assertEquals(target, self.orig)
        target.root.stats.st_gid = 1234
        self.assertNotEquals(target, self.orig)

        #merge with empty
        newroot = Directory("orig")
        new = Manifest(newroot)
        target = self.orig + new
        self.assertEquals(target, self.orig)