PR#442 list-channels CLI command
Merges #442 https://pagure.io/koji/pull-request/442 Fixes #437 PR#442 list-channels CLI command
This commit is contained in:
commit
2c4f09d891
3 changed files with 62 additions and 1 deletions
21
cli/koji
21
cli/koji
|
|
@ -709,7 +709,7 @@ def handle_add_host_to_channel(options, session, args):
|
|||
usage = _("usage: %prog add-host-to-channel [options] hostname channel")
|
||||
usage += _("\n(Specify the --help global option for a list of other help options)")
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option("--list", action="store_true", help=_("List possible channels"))
|
||||
parser.add_option("--list", action="store_true", help=optparse.SUPPRESS_HELP)
|
||||
parser.add_option("--new", action="store_true", help=_("Create channel if needed"))
|
||||
(options, args) = parser.parse_args(args)
|
||||
if not options.list and len(args) != 2:
|
||||
|
|
@ -3189,6 +3189,25 @@ def handle_unblock_group_req(options, session, args):
|
|||
activate_session(session)
|
||||
session.groupReqListUnblock(tag, group, req)
|
||||
|
||||
def anon_handle_list_channels(options, session, args):
|
||||
"[info] Print channels listing"
|
||||
usage = _("usage: %prog list-channels")
|
||||
usage += _("\n(Specify the --help global option for a list of other help options)")
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option("--quiet", action="store_true", help=_("Do not print header information"), default=options.quiet)
|
||||
(options, args) = parser.parse_args(args)
|
||||
activate_session(session)
|
||||
channels = session.listChannels()
|
||||
session.multicall = True
|
||||
for channel in channels:
|
||||
session.listHosts(channelID=channel['id'])
|
||||
for channel, hosts in zip(channels, session.multiCall()):
|
||||
channel['hosts'] = len(hosts[0])
|
||||
if not options.quiet:
|
||||
print('Channel Hosts')
|
||||
for channel in channels:
|
||||
print("%(name)-15s %(hosts) 5d" % channel)
|
||||
|
||||
def anon_handle_list_hosts(options, session, args):
|
||||
"[info] Print the host listing"
|
||||
usage = _("usage: %prog list-hosts [options]")
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ info commands:
|
|||
latest-build Print the latest builds for a tag
|
||||
list-api Print the list of XML-RPC APIs
|
||||
list-buildroot List the rpms used in or built in a buildroot
|
||||
list-channels Print channels listing
|
||||
list-external-repos List external repos
|
||||
list-groups Print the group listings
|
||||
list-history Display historical data
|
||||
|
|
|
|||
41
tests/test_cli/test_list_channels.py
Normal file
41
tests/test_cli/test_list_channels.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
import unittest
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
|
||||
from . import loadcli
|
||||
cli = loadcli.cli
|
||||
|
||||
class TestListChannels(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
self.args = mock.MagicMock()
|
||||
self.original_parser = cli.OptionParser
|
||||
cli.OptionParser = mock.MagicMock()
|
||||
self.parser = cli.OptionParser.return_value
|
||||
cli.options = self.options # globals!!!
|
||||
|
||||
def tearDown(self):
|
||||
cli.OptionParser = self.original_parser
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
def test_list_channels(self, stdout):
|
||||
options = mock.MagicMock()
|
||||
options.quiet = True
|
||||
self.parser.parse_args.return_value = [options, []]
|
||||
|
||||
# mock xmlrpc
|
||||
self.session.listChannels.return_value = [
|
||||
{'id': 1, 'name': 'default'},
|
||||
{'id': 2, 'name': 'test'},
|
||||
]
|
||||
self.session.multiCall.return_value = [[[1,2,3]], [[4,5]]]
|
||||
|
||||
cli.anon_handle_list_channels(self.options, self.session, self.args)
|
||||
actual = stdout.getvalue()
|
||||
expected = 'successfully connected to hub\ndefault 3\ntest 2\n'
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
Loading…
Add table
Add a link
Reference in a new issue