1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixing bug in GalaxyCLI test; creates temp dir for role_path instead … (#16689)

* Fixing bug in GalaxyCLI test; creates temp dir for role_path instead of installing to /etc/ansible/roles

* Update test_galaxy.py
This commit is contained in:
s-hertel 2016-07-12 16:01:47 -04:00 committed by jctanner
parent c4cff768d9
commit e84ab95733

View file

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