Merge "Improved test coverage for library/warn.py"
This commit is contained in:
commit
de5ffe4a79
@ -26,4 +26,39 @@ from validations_common.library import warn
|
||||
class TestWarn(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestWarn, self).setUp()
|
||||
self.warn = warn.main
|
||||
self.warn = warn
|
||||
self.module = mock.MagicMock()
|
||||
self.module.params = {'msg': 'foo'}
|
||||
|
||||
@mock.patch(
|
||||
'validations_common.library.warn.AnsibleModule')
|
||||
@mock.patch(
|
||||
'validations_common.library.warn.yaml_safe_load',
|
||||
return_value={'options': mock.MagicMock()})
|
||||
def test_warn_run(self, mock_safe_load, mock_ansible_module):
|
||||
"""Verify that warn correctly works with provided YAML.
|
||||
"""
|
||||
mock_module = mock.MagicMock()
|
||||
mock_module.params = {'msg': 'foo'}
|
||||
mock_ansible_module.return_value = mock_module
|
||||
|
||||
self.warn.main()
|
||||
|
||||
mock_safe_load.assert_called_once_with(self.warn.DOCUMENTATION)
|
||||
mock_module.exit_json.assert_called_once_with(
|
||||
changed=False,
|
||||
warnings=['foo'])
|
||||
|
||||
def test_warn_attributes(self):
|
||||
"""Verify that module contains required attributes.
|
||||
"""
|
||||
|
||||
required_names = set(
|
||||
[
|
||||
'DOCUMENTATION',
|
||||
'EXAMPLES',
|
||||
'AnsibleModule'
|
||||
])
|
||||
|
||||
warn_names = set(dir(self.warn))
|
||||
self.assertTrue(warn_names.issuperset(required_names))
|
||||
|
Loading…
Reference in New Issue
Block a user