#2703 cli: list-untagged returns error non-exist package
Merged a year ago by tkopecek. Opened a year ago by jcupova.
jcupova/koji issue2601  into  master

file modified
+3 -1
@@ -2605,6 +2605,9 @@ 

          package = args[0]

      opts = {}

      if package:

+         package_id = session.getPackageID(package)

+         if package_id is None:

+             error("No such package: %s" % package)

          opts['name'] = package

      pathinfo = koji.PathInfo()

  
@@ -2634,7 +2637,6 @@ 

          fmt = "%(name)s-%(version)s-%(release)s"

      if options.show_references:

          fmt = fmt + "  %(refs)s"

- 

      output = sorted([fmt % x for x in data])

      for line in output:

          print(line)

@@ -0,0 +1,106 @@ 

+ from __future__ import absolute_import

+ import mock

+ import unittest

+ from six.moves import StringIO

+ 

+ from koji_cli.commands import anon_handle_list_untagged

+ from . import utils

+ 

+ 

+ class TestListUntagged(utils.CliTestCase):

+     def setUp(self):

+         self.session = mock.MagicMock()

+         self.options = mock.MagicMock()

+         self.untagged_values = [{'id': 1,

+                             'name': 'test-package-1234',

+                             'release': '11',

+                             'version': '1.1'},

+                            {'id': 2,

+                             'name': 'test-package-1234',

+                             'release': '99',

+                             'version': '1.33'}

+                            ]

+ 

+     @mock.patch('sys.stdout', new_callable=StringIO)

+     @mock.patch('koji_cli.commands.ensure_connection')

+     def test_list_untagged_without_arguments(self, ensure_connection_mock,

+                                              stdout):

+         package_name = 'test-package-1234'

+ 

+         self.session.untaggedBuilds.return_value = self.untagged_values

+         expected = "\n".join([u['name'] + '-' + u['version'] + '-' +

+                               u['release'] for u in self.untagged_values]) + "\n"

+         anon_handle_list_untagged(self.options, self.session, [package_name])

+         self.assert_console_message(stdout, expected)

+ 

+     @mock.patch('koji_cli.commands.ensure_connection')

+     def test_list_untagged_more_arguments(self, ensure_connection_mock):

+         packages_name = ['test-package-1', 'test-package-2']

+         expected = """Usage: %s list-untagged [options] [<package>]

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

+ 

+ %s: error: Only one package name may be specified\n""" % (self.progname,

+                                                           self.progname)

+         self.assert_system_exit(

+             anon_handle_list_untagged,

+             self.options,

+             self.session,

+             [packages_name[0], packages_name[0]],

+             stderr=expected,

+             activate_session=None)

+ 

+     @mock.patch('sys.stderr', new_callable=StringIO)

+     @mock.patch('sys.stdout', new_callable=StringIO)

+     @mock.patch('koji_cli.commands.ensure_connection')

+     def test_list_untagged_package(self, ensure_connection, stdout, stderr):

+         # test case when package is existing

+         package_name = 'test-package-1234'

+ 

+         self.session.untaggedBuilds.return_value = self.untagged_values

+         expected = "\n".join([u['name'] + '-' + u['version'] + '-' +

+                               u['release'] for u in self.untagged_values]) + "\n"

+         anon_handle_list_untagged(self.options, self.session, [package_name])

+         self.assert_console_message(stdout, expected)

+ 

+         self.session.untaggedBuilds.reset_mock()

+ 

+         # test case when package is not existing

+         package_name = 'test-package'

+         expected = "No such package: %s" % package_name + "\n"

+         self.session.untaggedBuilds.return_value = []

+         self.session.getPackageID.return_value = None

+         with self.assertRaises(SystemExit) as ex:

+             anon_handle_list_untagged(self.options, self.session,

+                                       [package_name])

+         self.assertExitCode(ex, 1)

+         self.assert_console_message(stderr, expected)

+ 

+     @mock.patch('sys.stdout', new_callable=StringIO)

+     @mock.patch('koji_cli.commands.ensure_connection')

+     def test_list_untagged_package_path(self, ensure_connection, stdout):

+         # test case when package is existing

+         package_name = 'test-package-1234'

+ 

+         self.session.untaggedBuilds.return_value = self.untagged_values

+         expected = "\n".join(['/mnt/koji/packages/' + u['name'] + '/' +

+                               u['version'] + '/' + u['release']

+                               for u in self.untagged_values]) + "\n"

+         anon_handle_list_untagged(self.options, self.session,

+                                   ['--paths', package_name])

+         self.assert_console_message(stdout, expected)

+ 

+     def test_handle_list_history_help(self):

+         self.assert_help(

+             anon_handle_list_untagged,

+             """Usage: %s list-untagged [options] [<package>]

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

+ 

+ Options:

+   -h, --help         show this help message and exit

+   --paths            Show the file paths

+   --show-references  Show build references

+ """ % self.progname)

+ 

+ 

+ if __name__ == '__main__':

+     unittest.main()

When package is not existing, list-untagged returns an error.

Fixes: https://pagure.io/koji/issue/2601

Also this needs to be fixed only on CLI side

rebased onto 63fd29946543e73c3800ff71c3979307d954cf7e

a year ago

rebased onto 60d47f69975676606e2b4dc1a391885ed6688e32

a year ago

rebased onto 2b60bfc9e5472e9cb21384729627accd977edb9e

a year ago

rebased onto e2b22128557f826353d980b88dbc7a339a7091fe

a year ago

rebased onto 8a9b7e7cc870fa114ac52a7793b14982ce88c2a9

a year ago

rebased onto 48f80aad1da2a3b889519d9a63e8b9aba86a721e

a year ago

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

a year ago

rebased onto d5f6df7f4b1b3432ef74569cbeb6fa480df485e4

a year ago

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

a year ago

rebased onto 2f04acd

a year ago

Commit cf1c2da fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago