Beispiel #1
0
    def setUp(self):
        if os.path.exists(TESTROOT):
            print_error("The testing dir \'%s\' exists. Please clean up." % (TESTROOT, ))

        os.makedirs(SRC)
        os.makedirs(DST)

        from Discosetfile_unittest import discoset as ds

        files = ds["hosts"]["unittest"]["unittest"]
        relocations = ds["relocations"]
        permissions = ds["permissions"]

        def to_abs(path, absolute):
            if os.path.isabs(path):
                return path
            else:
                return os.path.join(absolute, path)

        f = [to_abs(f, SRC) for f in files]
        self._create_files(f)

        self.s = LnChmodWorker(files, relocations, permissions, DST, src=SRC)
Beispiel #2
0
class TestDiscoset(unittest.TestCase):

    def _create_files(self, files):
        for file in files:
            self._create_file(file)


    def _create_file(self, path):
        d = os.path.dirname(path)
        if not os.path.exists(d):
            os.makedirs(d)
        f = open(path, 'w')
        f.write("TEST")
        f.close()

    
    def setUp(self):
        if os.path.exists(TESTROOT):
            print_error("The testing dir \'%s\' exists. Please clean up." % (TESTROOT, ))

        os.makedirs(SRC)
        os.makedirs(DST)

        from Discosetfile_unittest import discoset as ds

        files = ds["hosts"]["unittest"]["unittest"]
        relocations = ds["relocations"]
        permissions = ds["permissions"]

        def to_abs(path, absolute):
            if os.path.isabs(path):
                return path
            else:
                return os.path.join(absolute, path)

        f = [to_abs(f, SRC) for f in files]
        self._create_files(f)

        self.s = LnChmodWorker(files, relocations, permissions, DST, src=SRC)



    def tearDown(self):
        shutil.rmtree(TESTROOT)


    def test_ActionSetup(self):
        self.s.ln()
        
        # Check if all links are created and
        # point to the right source files
        for link in self.s.link_struct:
            self.assertTrue(os.path.islink(link[1]))
            self.assertEqual(os.path.realpath(link[1]), link[0])


    def test_ActionSetupSrcFileMissing(self):
        os.unlink(self.s.link_struct[0][0])
        self.assertRaises(LnException, self.s.ln)


    def test_ActionSetupDstFileExists(self):
        self._create_file(self.s.link_struct[1][1])
        self.assertRaises(LnException, self.s.ln)


    def test_ActionSetupPermissions(self):
        self.s.ln()

        path = self.s.link_struct[0][1]
        self.assertEqual(self.s.permissions[path], stat.S_IMODE(os.stat(path).st_mode))

        path = self.s.link_struct[2][1]
        self.assertEqual(self.s.permissions[path], stat.S_IMODE(os.stat(path).st_mode))
    

    def test_ActionRemove(self):
        self.s.ln()

        for file in self.s.dst_files:
            self.assertTrue(os.path.exists(file))


        self.s.remove()
        
        for file in self.s.dst_files:
            self.assertFalse(os.path.exists(file))

    
    def test_ActionRemoveAlien(self):
        self.s.ln()

        path = self.s.link_struct[2][1]
        os.remove(path)
        
        self._create_file(path)
        self.assertRaises(LnException, self.s.remove)