Browse Source

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
changes/68/787768/1
Jiri Podivin 3 months ago
parent
commit
c21117799f
  1. 18
      validations_libs/tests/cli/test_show.py
  2. 2
      validations_libs/tests/fakes.py

18
validations_libs/tests/cli/test_show.py

@ -44,13 +44,27 @@ class TestShowGroup(BaseCommand):
super(TestShowGroup, self).setUp()
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('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']
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)
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):

2
validations_libs/tests/fakes.py

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