Skip to content

Commit

Permalink
update unittest deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobCallahan committed Feb 2, 2024
1 parent b7f8222 commit f9a0c45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions tests/robottelo/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_handle_response_logging_when_stderr_not_empty(self, warning):
response.status = 0
response.stderr = ['not empty']
assert response.stdout == base._handle_response(response)
warning.assert_assert_called_once_with(f'stderr contains following message:\n{response.stderr}')
warning.assert_called_once_with(f'stderr contains following message:\n{response.stderr}')
warning.reset_mock()
assert response.stdout == base._handle_response(response, True)
assert not warning.called, 'Should not be called when ignore_stderr is True'
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_add_create_with_empty_result(self, construct, execute):
assert execute.return_value == Base.create()
assert 'create' == Base.command_sub
construct.assert_called_once_with({})
execute.assert_called_once_with(construct.return_value, output_format='csv')
execute.assert_called_once_with(construct.return_value, output_format='csv', timeout=None)

@mock.patch('robottelo.cli.base.Base.info')
@mock.patch('robottelo.cli.base.Base.execute')
Expand All @@ -171,7 +171,7 @@ def test_add_create_with_result_dct_without_id(self, construct, execute, info):
assert execute.return_value == Base.create()
assert 'create' == Base.command_sub
construct.assert_called_once_with({})
execute.assert_called_once_with(construct.return_value, output_format='csv')
execute.assert_called_once_with(construct.return_value, output_format='csv', timeout=None)
assert not info.called

@mock.patch('robottelo.cli.base.Base.info')
Expand All @@ -186,7 +186,7 @@ def test_add_create_with_result_dct_with_id_not_required_org(self, construct, ex
assert execute.return_value == Base.create()
assert 'create' == Base.command_sub
construct.assert_called_once_with({})
execute.assert_called_once_with(construct.return_value, output_format='csv')
execute.assert_called_once_with(construct.return_value, output_format='csv', timeout=None)
info.assert_called_once_with({'id': 'foo'})

@mock.patch('robottelo.cli.base.Base.info')
Expand All @@ -201,7 +201,7 @@ def test_add_create_with_result_dct_with_id_required_org(self, construct, execut
assert execute.return_value == Base.create({'organization-id': 'org-id'})
assert 'create' == Base.command_sub
construct.assert_called_once_with({})
execute.assert_called_once_with(construct.return_value, output_format='csv')
execute.assert_called_once_with(construct.return_value, output_format='csv', timeout=None)
info.assert_called_once_with({'id': 'foo', 'organization-id': 'org-id'})

@mock.patch('robottelo.cli.base.Base.execute')
Expand All @@ -216,16 +216,16 @@ def test_add_create_with_result_dct_id_required_org_error(self, construct, execu
Base.create()
assert 'create' == Base.command_sub
construct.assert_called_once_with({})
execute.assert_called_once_with(construct.return_value, output_format='csv')
execute.assert_called_once_with(construct.return_value, output_format='csv', timeout=None)

def assert_cmd_execution(
self, construct, execute, base_method, cmd_sub, ignore_stderr=False, **base_method_kwargs
):
"""Asssert Base class method successfully executed"""
assert execute.return_value == base_method(**base_method_kwargs)
assert cmd_sub == Base.command_sub
construct.assert_called_once_with({})
execute.assert_called_once_with(construct.return_value, ignore_stderr=ignore_stderr)
construct.assert_called_once_with(None)
execute.assert_called_once_with(construct.return_value, ignore_stderr=ignore_stderr, timeout=None)

@mock.patch('robottelo.cli.base.Base.execute')
@mock.patch('robottelo.cli.base.Base._construct_command')
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_execute_with_raw_response(self, settings, command):
settings.server.admin_password = 'password'
response = Base.execute('some_cmd', return_raw_response=True)
ssh_cmd = 'LANG=en_US hammer -v -u admin -p password some_cmd'
command.assert_assert_called_once_with(
command.assert_called_once_with(
ssh_cmd.encode('utf-8'),
hostname=mock.ANY,
output_format=None,
Expand All @@ -274,21 +274,21 @@ def test_execute_with_performance(self, settings, command, handle_resp):
settings.server.admin_password = 'password'
response = Base.execute('some_cmd', hostname=None, output_format='json')
ssh_cmd = 'LANG=en_US time -p hammer -v -u admin -p password --output=json some_cmd'
command.assert_assert_called_once_with(
command.assert_called_once_with(
ssh_cmd.encode('utf-8'),
hostname=mock.ANY,
output_format='json',
timeout=None,
)
handle_resp.assert_assert_called_once_with(command.return_value, ignore_stderr=None)
handle_resp.assert_called_once_with(command.return_value, ignore_stderr=None)
assert response is handle_resp.return_value

@mock.patch('robottelo.cli.base.Base.list')
def test_exists_without_option_and_empty_return(self, lst_method):
"""Check exists method without options and empty return"""
lst_method.return_value = []
response = Base.exists(search=['id', 1])
lst_method.assert_assert_called_once_with({'search': 'id=\\"1\\"'})
lst_method.assert_called_once_with({'search': 'id=\\"1\\"'})
assert [] == response

@mock.patch('robottelo.cli.base.Base.list')
Expand All @@ -297,7 +297,7 @@ def test_exists_with_option_and_no_empty_return(self, lst_method):
lst_method.return_value = [1, 2]
my_options = {'search': 'foo=bar'}
response = Base.exists(my_options, search=['id', 1])
lst_method.assert_assert_called_once_with(my_options)
lst_method.assert_called_once_with(my_options)
assert 1 == response

@mock.patch('robottelo.cli.base.Base.command_requires_org')
Expand Down
2 changes: 1 addition & 1 deletion tests/robottelo/test_cli_method_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_cli_repository_method_called(mocker, command_sub):
assert execute.return_value == getattr(Repository, command_sub.replace('-', '_'))(options)
assert command_sub == Repository.command_sub
construct.assert_called_once_with(options)
execute.assert_called_once_with(construct.return_value)
execute.assert_called_once_with(construct.return_value, output_format='csv', ignore_stderr=True)


@pytest.mark.parametrize('command_sub', ['info', 'create'])
Expand Down

0 comments on commit f9a0c45

Please sign in to comment.