From dc47bcc8ccdfd8e1149a1ade746ec596a622a88d Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Dec 15 2021 14:28:26 +0000 Subject: PR#3108: Remove rename-channel CLI and use editChannel in renameChannel Merges #3108 https://pagure.io/koji/pull-request/3108 Fixes: #3035 https://pagure.io/koji/issue/3035 Remove deprecated rename_channel --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 620c12b..5ac5f58 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -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] " - 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] " diff --git a/hub/kojihub.py b/hub/kojihub.py index 2917433..54f527d 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -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): diff --git a/tests/test_cli/data/list-commands-admin.txt b/tests/test_cli/data/list-commands-admin.txt index 109ed8e..acdca5c 100644 --- a/tests/test_cli/data/list-commands-admin.txt +++ b/tests/test_cli/data/list-commands-admin.txt @@ -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 diff --git a/tests/test_cli/data/list-commands.txt b/tests/test_cli/data/list-commands.txt index 833f502..ac4dab6 100644 --- a/tests/test_cli/data/list-commands.txt +++ b/tests/test_cli/data/list-commands.txt @@ -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 diff --git a/tests/test_cli/test_rename_channel.py b/tests/test_cli/test_rename_channel.py deleted file mode 100644 index dd6cd4f..0000000 --- a/tests/test_cli/test_rename_channel.py +++ /dev/null @@ -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] -(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()