From 787d956885400d55ccc621b812cb5ec9e48f9193 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Sep 25 2018 14:20:11 +0000 Subject: PR#1098: cli: [download-task] readable error when no task found Merges #1098 https://pagure.io/koji/pull-request/1098 Fixes: #1080 https://pagure.io/koji/issue/1080 CLI download-task should respond "No such task" for task which is not exists. --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 3714c14..5b89b0c 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -6750,6 +6750,8 @@ def anon_handle_download_task(options, session, args): # get downloadable tasks base_task = session.getTaskInfo(base_task_id) + if not base_task: + error(_('No such task: #%i') % base_task_id) check_downloadable = lambda task: task["method"] == "buildArch" downloadable_tasks = [] diff --git a/tests/test_cli/test_download_task.py b/tests/test_cli/test_download_task.py index 2635b25..29c0634 100644 --- a/tests/test_cli/test_download_task.py +++ b/tests/test_cli/test_download_task.py @@ -89,6 +89,32 @@ class TestDownloadTask(unittest.TestCase): self.assertListEqual(self.download_file.mock_calls, calls) self.assertIsNone(rv) + def test_handle_download_task_not_found(self): + task_id = 123333 + args = [str(task_id)] + self.session.getTaskInfo.return_value = None + + # Run it and check immediate output + # args: task_id + # expected: error + with self.assertRaises(SystemExit) as cm: + anon_handle_download_task(self.options, self.session, args) + actual = self.stdout.getvalue() + expected = '' + self.assertMultiLineEqual(actual, expected) + actual = self.stderr.getvalue() + expected = 'No such task: #123333\n' + self.assertMultiLineEqual(actual, expected) + # Finally, assert that things were called as we expected. + self.activate_session.assert_called_once_with(self.session, + self.options) + self.session.getTaskInfo.assert_called_once_with(task_id) + self.session.getTaskChildren.assert_not_called() + if isinstance(cm.exception, int): + self.assertEqual(cm.exception, 1) + else: + self.assertEqual(cm.exception.code, 1) + def test_handle_download_task_parent(self): task_id = 123333 args = [str(task_id), '--arch=noarch,x86_64']