Increase CLI test cases
This commit is contained in:
parent
ba407086fb
commit
a8f11fbf9c
39 changed files with 2899 additions and 1869 deletions
|
|
@ -12,6 +12,7 @@ from . import utils
|
|||
|
||||
class TestListHosts(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.maxDiff = None
|
||||
# force locale to compare 'expect' value
|
||||
locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8'))
|
||||
self.options = mock.MagicMock()
|
||||
|
|
@ -21,6 +22,22 @@ class TestListHosts(utils.CliTestCase):
|
|||
self.original_timezone = os.environ.get('TZ')
|
||||
os.environ['TZ'] = 'UTC'
|
||||
time.tzset()
|
||||
self.ensure_connection_mock = mock.patch('koji_cli.commands.ensure_connection').start()
|
||||
self.error_format = """Usage: %s list-hosts [options]
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: {message}
|
||||
""" % (self.progname, self.progname)
|
||||
self.list_hosts = [{'arches': 'x86_64',
|
||||
'capacity': 2.0,
|
||||
'comment': 'test-comment',
|
||||
'description': 'test-description',
|
||||
'enabled': False,
|
||||
'id': 1,
|
||||
'name': 'kojibuilder',
|
||||
'ready': True,
|
||||
'task_load': 0.0,
|
||||
'user_id': 2}]
|
||||
|
||||
def tearDown(self):
|
||||
locale.resetlocale()
|
||||
|
|
@ -31,47 +48,175 @@ class TestListHosts(utils.CliTestCase):
|
|||
time.tzset()
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
@mock.patch('koji_cli.commands.ensure_connection')
|
||||
def test_list_hosts_valid(self, ensure_connection, stdout):
|
||||
def test_list_hosts_valid_without_quiet(self, stdout):
|
||||
self.options.quiet = False
|
||||
host_update = 1615875554.862938
|
||||
expected = "kojibuilder Y Y 0.0/2.0 x86_64 " \
|
||||
"Tue, 16 Mar 2021 06:19:14 UTC \n"
|
||||
list_hosts = [{'arches': 'x86_64',
|
||||
'capacity': 2.0,
|
||||
'comment': None,
|
||||
'description': None,
|
||||
'enabled': True,
|
||||
'id': 1,
|
||||
'name': 'kojibuilder',
|
||||
'ready': True,
|
||||
'task_load': 0.0,
|
||||
'user_id': 2}]
|
||||
expected = """Hostname Enb Rdy Load/Cap Arches Last Update
|
||||
kojibuilder N Y 0.0/2.0 x86_64 Tue, 16 Mar 2021 06:19:14 UTC
|
||||
"""
|
||||
|
||||
self.session.getLastHostUpdate.return_value = host_update
|
||||
self.session.multiCall.return_value = [[host_update]]
|
||||
self.session.listHosts.return_value = list_hosts
|
||||
self.session.listHosts.return_value = self.list_hosts
|
||||
rv = anon_handle_list_hosts(self.options, self.session, [])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with()
|
||||
self.session.getLastHostUpdate.assert_called_once_with(list_hosts[0]['id'], ts=True)
|
||||
self.session.getLastHostUpdate.assert_called_once_with(self.list_hosts[0]['id'], ts=True)
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_hosts_non_exist_channel(self, stderr):
|
||||
def test_list_hosts_non_exist_channel(self):
|
||||
channel = 'test-channel'
|
||||
expected = "Usage: %s list-hosts [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such channel: %s\n" % (self.progname, self.progname, channel)
|
||||
self.session.getChannel.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_hosts(self.options, self.session, ['--channel', channel])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
self.assert_system_exit(
|
||||
anon_handle_list_hosts,
|
||||
self.options, self.session, ['--channel', channel],
|
||||
stderr=self.format_error_message('No such channel: %s' % channel),
|
||||
exit_code=2,
|
||||
activate_session=None)
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
@mock.patch('koji_cli.commands.ensure_connection')
|
||||
def test_list_hosts_empty(self, ensure_connection, stderr):
|
||||
def test_list_hosts_empty(self, stderr):
|
||||
expected = "No hosts found.\n"
|
||||
self.session.listHosts.return_value = []
|
||||
anon_handle_list_hosts(self.options, self.session, [])
|
||||
self.assert_console_message(stderr, expected)
|
||||
self.session.listHosts.assert_called_once_with()
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_hosts_with_arch(self, stdout):
|
||||
host_update = 1615875554.862938
|
||||
expected = "kojibuilder N Y 0.0/2.0 x86_64 " \
|
||||
"Tue, 16 Mar 2021 06:19:14 UTC \n"
|
||||
|
||||
self.session.getLastHostUpdate.return_value = host_update
|
||||
self.session.multiCall.return_value = [[host_update]]
|
||||
self.session.listHosts.return_value = self.list_hosts
|
||||
rv = anon_handle_list_hosts(self.options, self.session, ['--arch', 'x86_64'])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with(arches=['x86_64'])
|
||||
self.session.getLastHostUpdate.assert_called_once_with(self.list_hosts[0]['id'], ts=True)
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_hosts_with_arch_not_used(self, stdout):
|
||||
expected = ""
|
||||
|
||||
self.session.listHosts.return_value = []
|
||||
rv = anon_handle_list_hosts(self.options, self.session, ['--arch', 'ppc'])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with(arches=['ppc'])
|
||||
self.session.getLastHostUpdate.assert_not_called()
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_hosts_with_ready(self, stdout):
|
||||
host_update = None
|
||||
expected = "kojibuilder N Y 0.0/2.0 x86_64 " \
|
||||
"- \n"
|
||||
|
||||
self.session.getLastHostUpdate.return_value = host_update
|
||||
self.session.multiCall.return_value = [[host_update]]
|
||||
self.session.listHosts.return_value = self.list_hosts
|
||||
rv = anon_handle_list_hosts(self.options, self.session, ['--ready'])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with(ready=True)
|
||||
self.session.getLastHostUpdate.assert_called_once_with(self.list_hosts[0]['id'], ts=True)
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_hosts_with_not_ready(self, stdout):
|
||||
expected = ""
|
||||
self.session.listHosts.return_value = []
|
||||
rv = anon_handle_list_hosts(self.options, self.session, ['--not-ready'])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with(ready=False)
|
||||
self.session.getLastHostUpdate.assert_not_called()
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_hosts_with_enabled(self, stdout):
|
||||
expected = ""
|
||||
|
||||
self.session.listHosts.return_value = []
|
||||
rv = anon_handle_list_hosts(self.options, self.session, ['--enabled'])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with(enabled=True)
|
||||
self.session.getLastHostUpdate.assert_not_called()
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_hosts_with_not_enabled(self, stdout):
|
||||
host_update = 1615875554.862938
|
||||
expected = "kojibuilder N Y 0.0/2.0 x86_64 " \
|
||||
"Tue, 16 Mar 2021 06:19:14 UTC \n"
|
||||
|
||||
self.session.getLastHostUpdate.return_value = host_update
|
||||
self.session.multiCall.return_value = [[host_update]]
|
||||
self.session.listHosts.return_value = self.list_hosts
|
||||
rv = anon_handle_list_hosts(self.options, self.session, ['--not-enabled'])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with(enabled=False)
|
||||
self.session.getLastHostUpdate.assert_called_once_with(self.list_hosts[0]['id'], ts=True)
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_hosts_param_error_get_last_host_update(self, stdout):
|
||||
host_update = 1615875554.862938
|
||||
expected = "kojibuilder N Y 0.0/2.0 x86_64 " \
|
||||
"Tue, 16 Mar 2021 06:19:14 UTC \n"
|
||||
|
||||
self.session.getLastHostUpdate.side_effect = [koji.ParameterError, host_update]
|
||||
self.session.multiCall.return_value = [[host_update]]
|
||||
self.session.listHosts.return_value = self.list_hosts
|
||||
rv = anon_handle_list_hosts(self.options, self.session, ['--ready'])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with(ready=True)
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_hosts_valid_without_quiet_description_and_comment(self, stdout):
|
||||
self.options.quiet = False
|
||||
host_update = 1615875554.862938
|
||||
expected = "Hostname Enb Rdy Load/Cap Arches Last Update" \
|
||||
" Description " \
|
||||
"Comment \n" \
|
||||
"kojibuilder N Y 0.0/2.0 x86_64 Tue, 16 Mar 2021 06:19:14 UTC" \
|
||||
" test-description test-comment" \
|
||||
" \n"
|
||||
|
||||
self.session.getLastHostUpdate.return_value = host_update
|
||||
self.session.multiCall.return_value = [[host_update]]
|
||||
self.session.listHosts.return_value = self.list_hosts
|
||||
rv = anon_handle_list_hosts(self.options, self.session, ['--description', '--comment'])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with()
|
||||
self.session.getLastHostUpdate.assert_called_once_with(self.list_hosts[0]['id'], ts=True)
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_hosts_valid_description_and_comment(self, stdout):
|
||||
host_update = 1615875554.862938
|
||||
expected = "kojibuilder N Y 0.0/2.0 x86_64 Tue, 16 Mar 2021 06:19:14 UTC" \
|
||||
" test-description test-comment" \
|
||||
" \n"
|
||||
|
||||
self.session.getLastHostUpdate.return_value = host_update
|
||||
self.session.multiCall.return_value = [[host_update]]
|
||||
self.session.listHosts.return_value = self.list_hosts
|
||||
rv = anon_handle_list_hosts(self.options, self.session, ['--description', '--comment'])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with()
|
||||
self.session.getLastHostUpdate.assert_called_once_with(self.list_hosts[0]['id'], ts=True)
|
||||
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue