mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
revert changes to unittest
This commit is contained in:
parent
3126af7661
commit
fbb4e712e7
@ -38,6 +38,7 @@ from salt.exceptions import LoaderError
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
@skipIf(NO_PYTEST, False)
|
||||
class AnsiblegateTestCase(TestCase, LoaderModuleMockMixin):
|
||||
def setUp(self):
|
||||
self.resolver = ansible.AnsibleModuleResolver({})
|
||||
@ -56,6 +57,7 @@ class AnsiblegateTestCase(TestCase, LoaderModuleMockMixin):
|
||||
def test_ansible_module_help(self):
|
||||
'''
|
||||
Test help extraction from the module
|
||||
:return:
|
||||
'''
|
||||
class Module(object):
|
||||
'''
|
||||
@ -77,68 +79,66 @@ description:
|
||||
patch.object(ansible._resolver, 'load_module',
|
||||
MagicMock(return_value=Module())):
|
||||
ret = ansible.help('dummy')
|
||||
self.assertEqual(sorted(ret.get('Available sections on module "{0}"'
|
||||
''.format(Module().__name__))),
|
||||
['one', 'two'])
|
||||
self.assertEqual(ret.get('Description'), 'describe the second part')
|
||||
assert sorted(ret.get('Available sections on module "{0}"'.format(
|
||||
Module().__name__))) == ['one', 'two']
|
||||
assert ret.get('Description') == 'describe the second part'
|
||||
|
||||
|
||||
def test_module_resolver_modlist(self):
|
||||
'''
|
||||
Test Ansible resolver modules list.
|
||||
:return:
|
||||
'''
|
||||
self.assertEqual(self.resolver.get_modules_list(),
|
||||
['four.five.six', 'one.two.three', 'three.six.one'])
|
||||
assert self.resolver.get_modules_list() == ['four.five.six', 'one.two.three', 'three.six.one']
|
||||
for ptr in ['five', 'fi', 've']:
|
||||
self.assertEqual(self.resolver.get_modules_list(ptr),
|
||||
['four.five.six'])
|
||||
assert self.resolver.get_modules_list(ptr) == ['four.five.six']
|
||||
for ptr in ['si', 'ix', 'six']:
|
||||
self.assertEqual(self.resolver.get_modules_list(ptr),
|
||||
['four.five.six', 'three.six.one'])
|
||||
self.assertEqual(self.resolver.get_modules_list('one'),
|
||||
['one.two.three', 'three.six.one'])
|
||||
self.assertEqual(self.resolver.get_modules_list('one.two'),
|
||||
['one.two.three'])
|
||||
self.assertEqual(self.resolver.get_modules_list('four'),
|
||||
['four.five.six'])
|
||||
assert self.resolver.get_modules_list(ptr) == ['four.five.six', 'three.six.one']
|
||||
assert self.resolver.get_modules_list('one') == ['one.two.three', 'three.six.one']
|
||||
assert self.resolver.get_modules_list('one.two') == ['one.two.three']
|
||||
assert self.resolver.get_modules_list('four') == ['four.five.six']
|
||||
|
||||
def test_resolver_module_loader_failure(self):
|
||||
'''
|
||||
Test Ansible module loader.
|
||||
:return:
|
||||
'''
|
||||
mod = 'four.five.six'
|
||||
self.assertRaises(ImportError, self.resolver.load_module, mod)
|
||||
with pytest.raises(ImportError) as import_error:
|
||||
self.resolver.load_module(mod)
|
||||
|
||||
mod = 'i.even.do.not.exist.at.all'
|
||||
self.assertRaises(LoaderError, self.resolver.load_module, mod)
|
||||
with pytest.raises(LoaderError) as loader_error:
|
||||
self.resolver.load_module(mod)
|
||||
|
||||
def test_resolver_module_loader(self):
|
||||
'''
|
||||
Test Ansible module loader.
|
||||
:return:
|
||||
'''
|
||||
with patch('salt.modules.ansiblegate.importlib', MagicMock()),\
|
||||
patch('salt.modules.ansiblegate.importlib.import_module',
|
||||
lambda x: x):
|
||||
self.assertEqual(self.resolver.load_module('four.five.six'),
|
||||
'ansible.modules.four.five.six')
|
||||
assert self.resolver.load_module('four.five.six') == 'ansible.modules.four.five.six'
|
||||
|
||||
def test_resolver_module_loader_import_failure(self):
|
||||
'''
|
||||
Test Ansible module loader failure.
|
||||
:return:
|
||||
'''
|
||||
with patch('salt.modules.ansiblegate.importlib', MagicMock()),\
|
||||
patch('salt.modules.ansiblegate.importlib.import_module',
|
||||
lambda x: x):
|
||||
self.assertRaises(LoaderError,
|
||||
self.resolver.load_module,
|
||||
'something.strange')
|
||||
with pytest.raises(LoaderError) as loader_error:
|
||||
self.resolver.load_module('something.strange')
|
||||
|
||||
def test_virtual_function_no_ansible_installed(self):
|
||||
'''
|
||||
Test Ansible module __virtual__ when ansible is not installed on the minion.
|
||||
:return:
|
||||
'''
|
||||
with patch('salt.modules.ansiblegate.ansible', None):
|
||||
self.assertEqual(ansible.__virtual__(),
|
||||
(False, 'Ansible is not installed on this system'))
|
||||
assert ansible.__virtual__() == (False, 'Ansible is not installed on this system')
|
||||
|
||||
@patch('salt.modules.ansiblegate.ansible', MagicMock())
|
||||
@patch('salt.modules.ansiblegate.list', MagicMock())
|
||||
@ -147,9 +147,10 @@ description:
|
||||
def test_virtual_function_ansible_is_installed(self):
|
||||
'''
|
||||
Test Ansible module __virtual__ when ansible is installed on the minion.
|
||||
:return:
|
||||
'''
|
||||
resolver = MagicMock()
|
||||
resolver.resolve = MagicMock()
|
||||
resolver.resolve.install = MagicMock()
|
||||
with patch('salt.modules.ansiblegate.AnsibleModuleResolver', resolver):
|
||||
self.assertEqual(ansible.__virtual__(), (True, None))
|
||||
assert ansible.__virtual__() == (True, None)
|
||||
|
Loading…
Reference in New Issue
Block a user