From e84ab95733104650a272a2c1944b43992b13f0ae Mon Sep 17 00:00:00 2001 From: s-hertel Date: Tue, 12 Jul 2016 16:01:47 -0400 Subject: [PATCH] =?UTF-8?q?Fixing=20bug=20in=20GalaxyCLI=20test;=20creates?= =?UTF-8?q?=20temp=20dir=20for=20role=5Fpath=20instead=20=E2=80=A6=20(#166?= =?UTF-8?q?89)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixing bug in GalaxyCLI test; creates temp dir for role_path instead of installing to /etc/ansible/roles * Update test_galaxy.py --- test/units/cli/test_galaxy.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/units/cli/test_galaxy.py b/test/units/cli/test_galaxy.py index a7a44a766f..9cffd1c5c3 100644 --- a/test/units/cli/test_galaxy.py +++ b/test/units/cli/test_galaxy.py @@ -27,6 +27,7 @@ import ansible import os import shutil import tarfile +import tempfile from mock import patch @@ -46,12 +47,16 @@ class TestGalaxy(unittest.TestCase): # creating framework for a role gc = GalaxyCLI(args=["init"]) - with patch('sys.argv', ["-c", "delete_me"]): + with patch('sys.argv', ["-c", "--offline", "delete_me"]): gc.parse() gc.run() cls.role_dir = "./delete_me" cls.role_name = "delete_me" - cls.role_path = "/etc/ansible/roles" + + # making a temp dir for role installation + cls.role_path = os.path.join(tempfile.mkdtemp(), "roles") + if not os.path.isdir(cls.role_path): + os.makedirs(cls.role_path) # creating a tar file name for class data cls.role_tar = './delete_me.tar.gz' @@ -85,6 +90,8 @@ class TestGalaxy(unittest.TestCase): os.remove(cls.role_req) if os.path.exists(cls.role_tar): os.remove(cls.role_tar) + if os.path.isdir(cls.role_path): + shutil.rmtree(cls.role_path) def setUp(self): self.default_args = [] @@ -111,7 +118,7 @@ class TestGalaxy(unittest.TestCase): def test_execute_remove(self): # installing role gc = GalaxyCLI(args=["install"]) - with patch('sys.argv', ["--offline", "-r", self.role_req]): + with patch('sys.argv', ["--offline", "-p", self.role_path, "-r", self.role_req]): galaxy_parser = gc.parse() gc.run() @@ -120,8 +127,8 @@ class TestGalaxy(unittest.TestCase): self.assertTrue(os.path.exists(role_file)) # removing role - gc.args = ["remove"] - with patch('sys.argv', ["-c", self.role_name]): + gc = GalaxyCLI(args=["remove"]) + with patch('sys.argv', ["-c", "-p", self.role_path, self.role_name]): galaxy_parser = gc.parse() super(GalaxyCLI, gc).run() gc.api = ansible.galaxy.api.GalaxyAPI(gc.galaxy)