Ejemplo n.º 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'))
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 7
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))
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
 def testSubtractWithSelf(self):
     target = self.orig - self.orig
     new = Manifest(None)
     self.assertEquals(new, target)
Ejemplo n.º 12
0
class MergerTest(unittest.TestCase):
    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)

    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)

    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)

    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))

    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)

    def testSubtractWithSelf(self):
        target = self.orig - self.orig
        new = Manifest(None)
        self.assertEquals(new, target)

    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)

    def testSubtractAllExceptOne(self):
        new = copy(self.orig)
        self.assertEquals(new, self.orig)

        testdir = new.root.children_as_dict['testdir']
        another_dir = testdir.children_as_dict['another_dir']
        another_dir._children = list()

        #check if only the file removed from new remains in target
        target = new - self.orig
        self.assertTrue(1, len(target.root._children))
        testdir = target.root.children_as_dict['testdir']
        self.assertTrue(1, len(testdir._children))
        another_dir = testdir.children_as_dict['another_dir']
        self.assertTrue(1, len(another_dir._children))
        self.assertTrue(
            isinstance(another_dir.children_as_dict['deep_file'], RMNode))

    def testAddAndSub(self):
        new = copy(self.orig)
        new.root.name = "test"  #prevent removal of root
        test = (new - self.orig) + self.orig
        test.root.name = "orig"  #reset name
        self.assertEquals(test, self.orig)

    def testHistory(self):
        new = copy(self.orig)
        target = self.orig + new
        self.assertTrue(target.is_child_off(self.orig))
        self.assertTrue(target.is_child_off(new))
        self.assertTrue(self.orig.is_parent_off(target))
        self.assertTrue(new.is_parent_off(target))