Check when list of hosts is empty.

Fixes: https://pagure.io/koji/issue/2497
This commit is contained in:
Jana Cupova 2021-05-12 16:31:39 +02:00
parent 8b07fcf5bb
commit 5e861978c6
2 changed files with 13 additions and 0 deletions

View file

@ -2902,6 +2902,10 @@ def anon_handle_list_hosts(goptions, session, args):
tmp_list = sorted([(x['name'], x) for x in session.listHosts(**opts)])
hosts = [x[1] for x in tmp_list]
if not hosts:
warn("No hosts found.")
return
def yesno(x):
if x:
return 'Y'

View file

@ -66,3 +66,12 @@ class TestListHosts(utils.CliTestCase):
anon_handle_list_hosts(self.options, self.session, ['--channel', channel])
self.assertExitCode(ex, 2)
self.assert_console_message(stderr, expected)
@mock.patch('sys.stderr', new_callable=StringIO)
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_hosts_empty(self, ensure_connection, 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()