mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix action test (#21102)
* update _parse_returned_data for no _ansible_parsed _parse_returned_data no longer adds _ansible_parsed * pep8 cleanups
This commit is contained in:
parent
764e1cc630
commit
174961b945
1 changed files with 12 additions and 11 deletions
|
@ -27,7 +27,6 @@ try:
|
|||
except ImportError:
|
||||
import __builtin__ as builtins
|
||||
|
||||
from nose.tools import eq_, raises
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.compat.six import text_type
|
||||
|
@ -38,13 +37,11 @@ from ansible.compat.tests.mock import patch, MagicMock, mock_open
|
|||
from ansible.errors import AnsibleError
|
||||
from ansible.playbook.play_context import PlayContext
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.vars.unsafe_proxy import AnsibleUnsafe
|
||||
from ansible.template import Templar
|
||||
|
||||
from units.mock.loader import DictDataLoader
|
||||
from ansible.module_utils._text import to_bytes
|
||||
|
||||
|
||||
python_module_replacers = b"""
|
||||
#!/usr/bin/python
|
||||
|
||||
|
@ -131,8 +128,8 @@ class TestActionBase(unittest.TestCase):
|
|||
)
|
||||
|
||||
# test python module formatting
|
||||
with patch.object(builtins, 'open', mock_open(read_data=to_bytes(python_module_replacers.strip(), encoding='utf-8'))) as m:
|
||||
with patch.object(os, 'rename') as m:
|
||||
with patch.object(builtins, 'open', mock_open(read_data=to_bytes(python_module_replacers.strip(), encoding='utf-8'))):
|
||||
with patch.object(os, 'rename'):
|
||||
mock_task.args = dict(a=1, foo='fö〩')
|
||||
mock_connection.module_implementation_preferences = ('',)
|
||||
(style, shebang, data, path) = action_base._configure_module(mock_task.action, mock_task.args)
|
||||
|
@ -165,7 +162,7 @@ class TestActionBase(unittest.TestCase):
|
|||
|
||||
# create a mock connection, so we don't actually try and connect to things
|
||||
def env_prefix(**args):
|
||||
return ' '.join(['%s=%s' % (k, shlex_quote(text_type(v))) for k,v in args.items()])
|
||||
return ' '.join(['%s=%s' % (k, shlex_quote(text_type(v))) for k, v in args.items()])
|
||||
mock_connection = MagicMock()
|
||||
mock_connection._shell.env_prefix.side_effect = env_prefix
|
||||
|
||||
|
@ -548,7 +545,7 @@ class TestActionBaseCleanReturnedData(unittest.TestCase):
|
|||
'ansible_ssh_some_var': 'whatever',
|
||||
'ansible_ssh_host_key_somehost': 'some key here',
|
||||
'some_other_var': 'foo bar'}
|
||||
res = action_base._clean_returned_data(data)
|
||||
action_base._clean_returned_data(data)
|
||||
self.assertNotIn('ansible_playbook_python', data)
|
||||
self.assertNotIn('ansible_python_interpreter', data)
|
||||
self.assertIn('ansible_ssh_host_key_somehost', data)
|
||||
|
@ -588,7 +585,7 @@ class TestActionBaseParseReturnedData(unittest.TestCase):
|
|||
res = action_base._parse_returned_data(returned_data)
|
||||
self.assertFalse(res['_ansible_parsed'])
|
||||
self.assertTrue(res['failed'])
|
||||
self.assertEquals(res['module_stderr'], err)
|
||||
self.assertEqual(res['module_stderr'], err)
|
||||
|
||||
def test_json_empty(self):
|
||||
action_base = self._action_base()
|
||||
|
@ -600,7 +597,8 @@ class TestActionBaseParseReturnedData(unittest.TestCase):
|
|||
'stdout_lines': stdout.splitlines(),
|
||||
'stderr': err}
|
||||
res = action_base._parse_returned_data(returned_data)
|
||||
self.assertTrue(res['_ansible_parsed'])
|
||||
self.assertEqual(len(res), 0)
|
||||
self.assertFalse(res)
|
||||
|
||||
def test_json_facts(self):
|
||||
action_base = self._action_base()
|
||||
|
@ -613,7 +611,8 @@ class TestActionBaseParseReturnedData(unittest.TestCase):
|
|||
'stdout_lines': stdout.splitlines(),
|
||||
'stderr': err}
|
||||
res = action_base._parse_returned_data(returned_data)
|
||||
self.assertTrue(res['_ansible_parsed'])
|
||||
self.assertTrue(res['ansible_facts'])
|
||||
self.assertIn('ansible_blip', res['ansible_facts'])
|
||||
# TODO: Should this be an AnsibleUnsafe?
|
||||
#self.assertIsInstance(res['ansible_facts'], AnsibleUnsafe)
|
||||
|
||||
|
@ -631,6 +630,8 @@ class TestActionBaseParseReturnedData(unittest.TestCase):
|
|||
'stdout_lines': stdout.splitlines(),
|
||||
'stderr': err}
|
||||
res = action_base._parse_returned_data(returned_data)
|
||||
self.assertTrue(res['_ansible_parsed'])
|
||||
self.assertTrue(res['ansible_facts'])
|
||||
self.assertIn('ansible_blip', res['ansible_facts'])
|
||||
self.assertIn('add_host', res)
|
||||
# TODO: Should this be an AnsibleUnsafe?
|
||||
#self.assertIsInstance(res['ansible_facts'], AnsibleUnsafe)
|
||||
|
|
Loading…
Reference in a new issue