#2770 cli: buildinfo returns error for non exist build
Merged a year ago by tkopecek. Opened a year ago by jcupova.
jcupova/koji issue2762  into  master

@@ -3227,12 +3227,14 @@ 

      if len(args) < 1:

          parser.error(_("Please specify a build"))

      ensure_connection(session, goptions)

+     error_hit = False

      for build in args:

          if build.isdigit():

              build = int(build)

          info = session.getBuild(build)

          if info is None:

              warn("No such build: %s\n" % build)

+             error_hit = True

              continue

          task = None

          if info['task_id']:
@@ -3315,6 +3317,8 @@ 

              if changelog:

                  print("Changelog:")

                  print(koji.util.formatChangelog(changelog))

+     if error_hit:

+         error()

  

  

  def anon_handle_hostinfo(goptions, session, args):

@@ -0,0 +1,119 @@ 

+ from __future__ import absolute_import

+ import koji

+ import mock

+ import os

+ import time

+ import copy

+ import locale

+ from six.moves import StringIO

+ 

+ from koji_cli.commands import anon_handle_buildinfo

+ from . import utils

+ 

+ 

+ class TestBuildinfo(utils.CliTestCase):

+     def setUp(self):

+         # force locale to compare 'expect' value

+         locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8'))

+         self.maxDiff = None

+         self.options = mock.MagicMock()

+         self.options.quiet = True

+         self.options.debug = False

+         self.session = mock.MagicMock()

+         self.session.getAPIVersion.return_value = koji.API_VERSION

+         self.original_timezone = os.environ.get('TZ')

+         os.environ['TZ'] = 'UTC'

+         time.tzset()

+         self.taskinfo = {'arch': 'noarch',

+                          'id': 8,

+                          'method': 'build'}

+         self.buildinfo = {'build_id': 1,

+                           'id': 1,

+                           'name': 'test-build',

+                           'release': '1',

+                           'task_id': 8,

+                           'version': '1',

+                           'state': 1,

+                           'completion_ts': 1614869140.368759,

+                           'owner_name': 'kojiadmin',

+                           'volume_name': 'DEFAULT'}

+ 

+     def tearDown(self):

+         locale.resetlocale()

+         if self.original_timezone is None:

+             del os.environ['TZ']

+         else:

+             os.environ['TZ'] = self.original_timezone

+         time.tzset()

+ 

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

+     def test_buildinfo_valid(self, stdout):

+         build = 'test-build-1-1'

+         self.session.getBuild.return_value = self.buildinfo

+         self.session.getTaskInfo.return_value = self.taskinfo

+         self.session.listTags.return_value = []

+         self.session.getMavenBuild.return_value = None

+         self.session.getWinBuild.return_value = None

+         self.session.listArchives.return_value = []

+         self.session.listRPMs.return_value = []

+         expected_stdout = """BUILD: test-build-1-1 [1]

+ State: COMPLETE

+ Built by: kojiadmin

+ Volume: DEFAULT

+ Task: 8 build (noarch)

+ Finished: Thu, 04 Mar 2021 14:45:40 UTC

+ Tags: 

+ """

+         anon_handle_buildinfo(self.options, self.session, [build])

+         self.assert_console_message(stdout, expected_stdout)

+         self.session.listTags.assert_called_once_with(build)

+         self.session.getBuild.assert_called_once_with(build)

+         self.session.getTaskInfo.assert_called_once_with(self.buildinfo['task_id'], request=True)

+         self.session.getMavenBuild.assert_called_once_with(self.buildinfo['id'])

+         self.session.getWinBuild.assert_called_once_with(self.buildinfo['id'])

+         self.session.listRPMs.assert_called_once_with(buildID=self.buildinfo['id'])

+         self.assertEqual(self.session.listArchives.call_count, 4)

+ 

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

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

+     def test_buildinfo_more_build_with_non_exist_build(self, stdout, stderr):

+         build = 'test-build-1-1'

+         non_exist_build = 'test-build-11-12'

+         buildinfo = copy.deepcopy(self.buildinfo)

+         buildinfo['task_id'] = None

+         self.session.getBuild.side_effect = [None, buildinfo]

+         self.session.listTags.return_value = []

+         self.session.getMavenBuild.return_value = None

+         self.session.getWinBuild.return_value = None

+         self.session.listArchives.return_value = []

+         self.session.listRPMs.return_value = []

+         expected_stdout = """BUILD: test-build-1-1 [1]

+ State: COMPLETE

+ Built by: kojiadmin

+ Volume: DEFAULT

+ Task: none

+ Finished: Thu, 04 Mar 2021 14:45:40 UTC

+ Tags: 

+ """

+         expected_error = "No such build: %s\n\n" % non_exist_build

+         with self.assertRaises(SystemExit) as ex:

+             anon_handle_buildinfo(self.options, self.session, [non_exist_build, build])

+         self.assertExitCode(ex, 1)

+         self.assert_console_message(stderr, expected_error)

+         self.assert_console_message(stdout, expected_stdout)

+         self.session.listTags.assert_called_once_with(build)

+         self.session.getMavenBuild.assert_called_once_with(self.buildinfo['id'])

+         self.session.getWinBuild.assert_called_once_with(self.buildinfo['id'])

+         self.session.listRPMs.assert_called_once_with(buildID=self.buildinfo['id'])

+         self.assertEqual(self.session.getBuild.call_count, 2)

+         self.assertEqual(self.session.listArchives.call_count, 4)

+ 

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

+     def test_buildinfo_non_exist_build(self, stderr):

+         non_exist_build = 'test-build-11-12'

+         self.session.getBuild.return_value = None

+         expected = "No such build: %s\n\n" % non_exist_build

+         with self.assertRaises(SystemExit) as ex:

+             anon_handle_buildinfo(self.options, self.session, [non_exist_build])

+         self.assertExitCode(ex, 1)

+         self.assert_console_message(stderr, expected)

Same problem with locales/lang in test.

rebased onto 46a8915

a year ago

pretty please pagure-ci rebuild

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

Commit fa1e3f8 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago