Adding a test for GalaxyCLI. Tests exit_without_ignore method.

This commit is contained in:
s-hertel 2016-07-07 14:25:08 -04:00 committed by Ryan S. Brown
parent 372018dfce
commit aae5e50299

View file

@ -19,17 +19,19 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.compat.six import PY3
from ansible.compat.tests import unittest
from nose.plugins.skip import SkipTest
import ansible
import os
import shutil
import tarfile
import tempfile
from mock import patch
from nose.plugins.skip import SkipTest
from ansible.compat.six import PY3
from ansible.compat.tests import unittest
import ansible
from ansible.errors import AnsibleError
if PY3:
raise SkipTest('galaxy is not ported to be py3 compatible yet')
@ -137,3 +139,23 @@ class TestGalaxy(unittest.TestCase):
# testing role was removed
self.assertTrue(completed_task == 0)
self.assertTrue(not os.path.exists(role_file))
def test_exit_without_ignore(self):
''' tests that GalaxyCLI exits with the error specified unless the --ignore-errors flag is used '''
gc = GalaxyCLI(args=["install"])
# testing without --ignore-errors flag
with patch('sys.argv', ["-c", "fake_role_name"]):
galaxy_parser = gc.parse()
with patch.object(ansible.utils.display.Display, "display", return_value=None) as mocked_display:
# testing that error expected is raised
self.assertRaises(AnsibleError, gc.run)
self.assertTrue(mocked_display.called_once_with("- downloading role 'fake_role_name', owned by "))
# testing with --ignore-errors flag
with patch('sys.argv', ["-c", "fake_role_name", "--ignore-errors"]):
galalxy_parser = gc.parse()
with patch.object(ansible.utils.display.Display, "display", return_value=None) as mocked_display:
# testing that error expected is not raised with --ignore-errors flag in use
gc.run()
self.assertTrue(mocked_display.called_once_with("- downloading role 'fake_role_name', owned by "))