#2688 cli: list-api method
Merged a year ago by tkopecek. Opened a year ago by tkopecek.
tkopecek/koji issue2687  into  master

file modified
+25 -20
@@ -2459,29 +2459,34 @@ 

  

  def anon_handle_list_api(goptions, session, args):

      "[info] Print the list of XML-RPC APIs"

-     usage = _("usage: %prog list-api [options]")

+     usage = _("usage: %prog list-api [options] [method_name ...]")

      parser = OptionParser(usage=get_usage_str(usage))

      (options, args) = parser.parse_args(args)

-     if len(args) != 0:

-         parser.error(_("This command takes no arguments"))

      ensure_connection(session, goptions)

-     for x in sorted(session._listapi(), key=lambda x: x['name']):

-         if 'argdesc' in x:

-             args = x['argdesc']

-         elif x['args']:

-             # older servers may not provide argdesc

-             expanded = []

-             for arg in x['args']:

-                 if isinstance(arg, str):

-                     expanded.append(arg)

-                 else:

-                     expanded.append('%s=%s' % (arg[0], arg[1]))

-             args = "(%s)" % ", ".join(expanded)

-         else:

-             args = "()"

-         print('%s%s' % (x['name'], args))

-         if x['doc']:

-             print("  description: %s" % x['doc'])

+     if args:

+         for method in args:

+             help = session.system.methodHelp(method)

+             if not help:

+                 parser.error(_("Unknown method: %s") % method)

+             print(help)

+     else:

+         for x in sorted(session._listapi(), key=lambda x: x['name']):

+             if 'argdesc' in x:

+                 args = x['argdesc']

+             elif x['args']:

+                 # older servers may not provide argdesc

+                 expanded = []

+                 for arg in x['args']:

+                     if isinstance(arg, str):

+                         expanded.append(arg)

+                     else:

+                         expanded.append('%s=%s' % (arg[0], arg[1]))

+                 args = "(%s)" % ", ".join(expanded)

+             else:

+                 args = "()"

+             print('%s%s' % (x['name'], args))

+             if x['doc']:

+                 print("  description: %s" % x['doc'])

  

  

  def anon_handle_list_tagged(goptions, session, args):

file modified
+22 -14
@@ -13,7 +13,7 @@ 

      maxDiff = None

  

      def setUp(self):

-         self.error_format = """Usage: %s list-api [options]

+         self.error_format = """Usage: %s list-api [options] [method_name]

  (Specify the --help global option for a list of other help options)

  

  %s: error: {message}
@@ -29,18 +29,7 @@ 

          session = mock.MagicMock()

          options = mock.MagicMock()

  

-         # Case 1. argument error

-         expected = self.format_error_message(

-             "This command takes no arguments")

-         self.assert_system_exit(

-             anon_handle_list_api,

-             options,

-             session,

-             ['arg'],

-             stderr=expected,

-             activate_session=None)

- 

-         # Case 2.

+         # Case 1. list all methods

          session._listapi.return_value = [

              {

                  'argdesc': '(tagInfo, **kwargs)',
@@ -70,10 +59,29 @@ 

          anon_handle_list_api(options, session, [])

          self.assert_console_message(stdout, expected)

  

+         # Case 2. non-existent fake method

+         session.system.methodHelp.return_value = None

+         expected = self.format_error_message("Unknown method: non-existent-fake-method")

+         self.assert_system_exit(

+             anon_handle_list_api,

+             options,

+             session,

+             ['non-existent-fake-method'],

+             stderr=expected,

+             activate_session=None)

+ 

+         # Case 3. known method

+         session.system.methodHelp.return_value = "editTag2(tagInfo, **kwargs)\n" \

+                                           "  description: Edit information for an existing tag."

+         anon_handle_list_api(options, session, ['editTag2'])

+         expected = "editTag2(tagInfo, **kwargs)\n"

+         expected += "  description: Edit information for an existing tag.\n"

+         self.assert_console_message(stdout, expected)

+ 

      def test_anon_handle_list_api_help(self):

          self.assert_help(

              anon_handle_list_api,

-             """Usage: %s list-api [options]

+             """Usage: %s list-api [options] [method_name]

  (Specify the --help global option for a list of other help options)

  

  Options:

There's a smaller RPC to get one single method back from the server. The RPC is named system.methodHelp. For example:

koji --noauth call system.methodHelp listPackages

Makes sense - too quick fix.

rebased onto cd781cdd8630fe581d8f8b313761d7c6191ba21b

a year ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

a year ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

a year ago

I was a little confused when I read this test and saw the method name is "unknown". What do you think about naming this "bogusMethod" or "foobarMethod" so it's clearer that it's a fake method?

1 new commit added

  • more informative test string
a year ago

rebased onto 5b06b6fc920efd386120a8946ff355caaa80d218

a year ago

this might be

usage = _("usage: %prog list-api [options] [<method_name> ...]")

rebased onto fdf64d0

a year ago

Commit 9d559a6 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago