From fe4c83a229824c1396c8a961961626a1082aa87b Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 27 2017 21:20:40 +0000 Subject: typo fix + tests --- diff --git a/hub/kojihub.py b/hub/kojihub.py index cb0b59a..69927c7 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5323,7 +5323,7 @@ class CG_Importer(object): if os.path.lexists(path): if delete: logger.warning("Deleting build directory: %s", path) - koji.util.rmtree(olddir) + koji.util.rmtree(path) else: raise koji.GenericError("Destination directory already exists: %s" % path) diff --git a/tests/test_hub/test_cg_importer.py b/tests/test_hub/test_cg_importer.py index 5207f6f..ac0e528 100644 --- a/tests/test_hub/test_cg_importer.py +++ b/tests/test_hub/test_cg_importer.py @@ -82,6 +82,32 @@ class TestCGImporter(unittest.TestCase): assert x.buildinfo assert isinstance(x.buildinfo, dict) + @mock.patch('koji.pathinfo.build') + @mock.patch('os.path.lexists') + @mock.patch('koji.util.rmtree') + def test_check_build_dir(self, rmtree, lexists, build): + path = '/random_path/random_dir' + build.return_value = path + + x = kojihub.CG_Importer() + + # directory exists + lexists.return_value = True + with self.assertRaises(koji.GenericError): + x.check_build_dir(delete=False) + rmtree.assert_not_called() + + # directory exists + delete + lexists.return_value = True + x.check_build_dir(delete=True) + rmtree.assert_called_once_with(path) + + # directory doesn't exist + rmtree.reset_mock() + lexists.return_value = False + x.check_build_dir() + rmtree.assert_not_called() + @mock.patch('kojihub.get_build') @mock.patch("koji.pathinfo.work") def test_prep_build_exists(self, work, get_build):