PR#3535: CLI edit-channel set default value for None and error msg to stderr.

Merges #3535
https://pagure.io/koji/pull-request/3535

Fixes: #3534
https://pagure.io/koji/issue/3534
CLI edit-channel prints error message to stdout
This commit is contained in:
Tomas Kopecek 2022-10-24 10:03:03 +02:00
commit 79d3750629
2 changed files with 25 additions and 1 deletions

View file

@ -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")

View file

@ -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()