Ejemplo n.º 1
0
class FunctionalTests(BaseCase):
    def setUp(self):
        super(FunctionalTests, self).setUp()
        self.linker = Linker(self.indir, self.outdir)

    def test_move_first(self):
        test_file = '/tmp/test_file'
        self.touch(self.outdir, test_file)
        self.linker = Linker(self.indir, test_file)
        test_link = path.join(self.indir, gethostname(),
                              self.linker.generate_target(test_file))
        try:
            self.linker.move_to_target()
            self.assertTrue(path.exists(test_file))
            self.assertTrue(path.islink(test_file))
            self.assertTrue(path.exists(test_link))
            self.assertFalse(path.islink(test_link))
            self.assertEqual(path.realpath(test_file), test_link)
        finally:
            remove(test_file)

    def test_move_first_common(self):
        test_file = '/tmp/test_file'
        self.touch(self.outdir, test_file)
        self.linker = Linker(self.indir, test_file)
        test_link = path.join(self.indir, 'common',
                              self.linker.generate_target(test_file))
        try:
            self.linker.move_to_target(common=True)
            self.assertTrue(path.exists(test_file))
            self.assertTrue(path.islink(test_file))
            self.assertTrue(path.exists(test_link))
            self.assertFalse(path.islink(test_link))
            self.assertEqual(path.realpath(test_file), test_link)
        finally:
            remove(test_file)
            remove(test_link)

    def test_fetch_targets(self):
        want_output = [path.join(self.indir, 'common', f) for f in \
                       ['commonfile1', '.commonfile3', '_tmp_commonfile4',
                        'common__file5']]
        have_output = self.linker.fetch_targets(path.join(self.indir, 'common'))

        want_output.sort()
        have_output.sort()
        self.assertListEqual(want_output, have_output)

    def test_find_targets(self):
        want_output = [path.join(self.indir, 'common', f) for f in \
                       ['commonfile1', '.commonfile3', '_tmp_commonfile4',
                        'common__file5']]
        want_output.append(path.join(self.indir, gethostname(),
                           'hostnamefile1'))
        have_output = self.linker.find_targets(self.indir)

        want_output.sort()
        have_output.sort()
        self.assertEqual(want_output, have_output)

    def test_mkdir_p(self):
        want_dir = path.join(self.outdir, 'mkdirp', 'test')
        self.linker.mkdir_p(want_dir)
        self.assertTrue(path.exists(want_dir))
        self.assertTrue(path.isdir(want_dir))