From f11628000e0e7ddc4e75807876675501059d95e6 Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: Thu, 6 Oct 2022 09:39:31 +0200 Subject: [PATCH] CLI edit-channel set default value for None and error msg to stderr. Fixes: https://pagure.io/koji/issue/3534 --- cli/koji_cli/commands.py | 3 ++- tests/test_cli/test_edit_channel.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 1c7dd21e..1b943dfd 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -348,6 +348,7 @@ def handle_edit_channel(goptions, session, args): cinfo = session.getChannel(args[0]) if not cinfo: error("No such channel: %s" % args[0]) + result = None try: result = session.editChannel(args[0], **vals) except koji.GenericError as ex: @@ -357,7 +358,7 @@ def handle_edit_channel(goptions, session, args): error("editChannel is available on hub from Koji 1.26 version, your version is %s" % version) else: - print(msg) + warn(msg) if not result: error("No changes made, please correct the command line") diff --git a/tests/test_cli/test_edit_channel.py b/tests/test_cli/test_edit_channel.py index 55f391e1..cbd3fb1d 100644 --- a/tests/test_cli/test_edit_channel.py +++ b/tests/test_cli/test_edit_channel.py @@ -133,6 +133,29 @@ Options: self.session.getChannel.assert_called_once_with(self.channel_old) self.session.getKojiVersion.assert_not_called() + def test_handle_edit_channel_other_error_message(self): + expected_api = "Other error message" + expected = """Other error message +No changes made, please correct the command line +""" + + self.session.editChannel.side_effect = koji.GenericError(expected_api) + self.assert_system_exit( + handle_edit_channel, + self.options, + self.session, + [self.channel_old, '--name', self.channel_new, '--description', self.description], + stderr=expected, + stdout='', + activate_session=None, + exit_code=1 + ) + self.session.editChannel.assert_called_once_with(self.channel_old, name=self.channel_new, + description=self.description) + self.activate_session_mock.assert_called_once_with(self.session, self.options) + self.session.getChannel.assert_called_once_with(self.channel_old) + self.session.getKojiVersion.assert_not_called() + if __name__ == '__main__': unittest.main()