Remove rename-channel CLI and use editChannel in renameChannel

Fixes: https://pagure.io/koji/issue/3035
This commit is contained in:
Jana Cupova 2021-11-01 10:18:21 +01:00 committed by Tomas Kopecek
parent 109feb5629
commit 18b136d386
5 changed files with 1 additions and 126 deletions

View file

@ -346,22 +346,6 @@ def handle_remove_channel(goptions, session, args):
session.removeChannel(args[0], force=options.force)
def handle_rename_channel(goptions, session, args):
"[admin] Rename a channel"
usage = "usage: %prog rename-channel [options] <old-name> <new-name>"
parser = OptionParser(usage=get_usage_str(usage))
(options, args) = parser.parse_args(args)
print("rename-channel is deprecated and will be removed in 1.28, this call is replaced by "
"edit-channel")
if len(args) != 2:
parser.error("Incorrect number of arguments")
activate_session(session, goptions)
cinfo = session.getChannel(args[0])
if not cinfo:
error("No such channel: %s" % args[0])
session.renameChannel(args[0], args[1])
def handle_edit_channel(goptions, session, args):
"[admin] Edit a channel"
usage = "usage: %prog edit-channel [options] <old-name>"

View file

@ -2345,18 +2345,7 @@ def remove_host_from_channel(hostname, channel_name):
def rename_channel(old, new):
"""Rename a channel"""
logger.warning("renameChannel call is deprecated and will be removed in 1.28")
context.session.assertPerm('admin')
if not isinstance(new, str):
raise koji.GenericError("new channel name must be a string")
verify_name_internal(new)
cinfo = get_channel(old, strict=True)
dup_check = get_channel(new, strict=False)
if dup_check:
raise koji.GenericError("channel %(name)s already exists (id=%(id)i)" % dup_check)
update = UpdateProcessor('channels', clauses=['id=%(id)i'], values=cinfo)
update.set(name=new)
update.execute()
edit_channel(old, name=new)
def edit_channel(channelInfo, **kw):

View file

@ -54,7 +54,6 @@ admin commands:
remove-tag Remove a tag
remove-tag-inheritance Remove a tag inheritance link
remove-target Remove a build target
rename-channel Rename a channel
restart-hosts Restart enabled hosts
revoke-cg-access Remove a user from a content generator
revoke-permission Revoke a permission from a user

View file

@ -54,7 +54,6 @@ admin commands:
remove-tag Remove a tag
remove-tag-inheritance Remove a tag inheritance link
remove-target Remove a build target
rename-channel Rename a channel
restart-hosts Restart enabled hosts
revoke-cg-access Remove a user from a content generator
revoke-permission Revoke a permission from a user

View file

@ -1,96 +0,0 @@
from __future__ import absolute_import
import unittest
import mock
import six
from koji_cli.commands import handle_rename_channel
from . import utils
class TestRenameChannel(utils.CliTestCase):
def setUp(self):
self.options = mock.MagicMock()
self.session = mock.MagicMock()
self.channel_name_old = 'old-channel'
self.channel_name_new = 'new-channel'
self.description = 'description'
self.channel_info = {
'id': 123,
'name': self.channel_name_old,
'description': self.description,
}
self.maxDiff = None
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_handle_rename_channel(self, activate_session_mock, stdout):
args = [self.channel_name_old, self.channel_name_new]
self.session.getChannel.return_value = self.channel_info
# Run it and check immediate output
# args: old_name, new_name
# expected: success
rv = handle_rename_channel(self.options, self.session, args)
depr_warn = 'rename-channel is deprecated and will be removed in 1.28'
self.assert_console_message(stdout, depr_warn, regex=True)
# Finally, assert that things were called as we expected.
activate_session_mock.assert_called_once_with(self.session, self.options)
self.session.getChannel.assert_called_once_with(self.channel_name_old)
self.session.renameChannel.assert_called_once_with(self.channel_name_old,
self.channel_name_new)
self.assertNotEqual(rv, 1)
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_handle_rename_channel_no_channel(self, activate_session_mock, stderr, stdout):
channel_info = None
args = [self.channel_name_old, self.channel_name_new]
self.session.getChannel.return_value = channel_info
# Run it and check immediate output
# args: old_name, new_name
# expected: failed: no such channel
with self.assertRaises(SystemExit) as ex:
handle_rename_channel(self.options, self.session, args)
self.assertExitCode(ex, 1)
expected = 'No such channel: %s' % self.channel_name_old
depr_warn = 'rename-channel is deprecated and will be removed in 1.28'
self.assert_console_message(stderr, expected, wipe=False, regex=True)
self.assert_console_message(stdout, depr_warn, wipe=False, regex=True)
# Finally, assert that things were called as we expected.
activate_session_mock.assert_called_once_with(self.session, self.options)
self.session.getChannel.assert_called_once_with(self.channel_name_old)
self.session.renameChannel.assert_not_called()
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_handle_rename_channel_more_args(self, activate_session_mock, stderr, stdout):
args = [self.channel_name_old, self.channel_name_new, 'extra-arg']
with self.assertRaises(SystemExit) as ex:
handle_rename_channel(self.options, self.session, args)
self.assertExitCode(ex, 2)
expected = 'Incorrect number of arguments'
depr_warn = 'rename-channel is deprecated and will be removed in 1.28'
self.assert_console_message(stderr, expected, wipe=False, regex=True)
self.assert_console_message(stdout, depr_warn, wipe=False, regex=True)
# Finally, assert that things were called as we expected.
activate_session_mock.assert_not_called()
self.session.getChannel.assert_not_called()
self.session.renameChannel.assert_not_called()
def test_handle_rename_channel_help(self):
self.assert_help(
handle_rename_channel,
"""Usage: %s rename-channel [options] <old-name> <new-name>
(Specify the --help global option for a list of other help options)
Options:
-h, --help show this help message and exit
""" % self.progname)
if __name__ == '__main__':
unittest.main()