From 7d3f34b4761b603c061b4cdc2941e1159efef9ca Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 12 2021 14:41:33 +0000 Subject: PR#2857: Check when list of hosts is empty. Merges #2857 https://pagure.io/koji/pull-request/2857 Fixes: #2497 https://pagure.io/koji/issue/2497 getLastHostUpdate returns time only as a string --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index fbf0339..42fc314 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -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' diff --git a/tests/test_cli/test_list_hosts.py b/tests/test_cli/test_list_hosts.py index 40fa5ee..151ffc6 100644 --- a/tests/test_cli/test_list_hosts.py +++ b/tests/test_cli/test_list_hosts.py @@ -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()