group info test mocks and asserts

Test previously relied only on the inherited assertions.
Additionally, almost all calls were actually performed,
introducing unnecessary code into test.

Additional mocks now cover majority of calls to
functions and methods not directly related to the test.

Further assertions have been placed on output of the
tested method and the calls made to the newly mocked methods.

Validation path was moved to fakes module.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I9518f2d31227e0bed46c586a00ee025177969eec
This commit is contained in:
Jiri Podivin 2021-04-23 16:49:47 +02:00
parent 132d2801db
commit c21117799f
2 changed files with 18 additions and 2 deletions

View File

@ -44,13 +44,27 @@ class TestShowGroup(BaseCommand):
super(TestShowGroup, self).setUp() super(TestShowGroup, self).setUp()
self.cmd = show.ShowGroup(self.app, None) self.cmd = show.ShowGroup(self.app, None)
@mock.patch('validations_libs.cli.show.ValidationActions', autospec=True)
@mock.patch('yaml.safe_load', return_value=fakes.GROUP) @mock.patch('yaml.safe_load', return_value=fakes.GROUP)
@mock.patch('six.moves.builtins.open') @mock.patch('six.moves.builtins.open')
def test_show_validations_group_info(self, mock_open, mock_yaml): def test_show_validations_group_info(self, mock_open, mock_yaml, mock_actions):
arglist = ['--group', 'group.yaml'] arglist = ['--group', 'group.yaml']
verifylist = [('group', 'group.yaml')] verifylist = [('group', 'group.yaml')]
mock_info = mock.MagicMock()
mock_info.group_information = mock.MagicMock(return_value='foo')
mock_actions.return_value = mock_info
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
group_info = self.cmd.take_action(parsed_args)
mock_actions.assert_called_once_with(
validation_path=fakes.FAKE_VALIDATIONS_PATH)
mock_info.group_information.assert_called_once_with('group.yaml')
self.assertEqual('foo', group_info)
class TestShowParameter(BaseCommand): class TestShowParameter(BaseCommand):

View File

@ -295,6 +295,8 @@ FAKE_FAILED_RUN = [{'Duration': '0:00:01.761',
'Unreachable_Hosts': '', 'Unreachable_Hosts': '',
'Validations': 'foo'}] 'Validations': 'foo'}]
FAKE_VALIDATIONS_PATH = '/usr/share/ansible/validation-playbooks'
def fake_ansible_runner_run_return(status='successful', rc=0): def fake_ansible_runner_run_return(status='successful', rc=0):
return status, rc return status, rc