From f472ab972472706563c14d723c9bb9bc32604bd3 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mar 23 2023 12:21:53 +0000 Subject: PR#3731: CLI list-untagged: One space only instead of double space before references Merges #3731 https://pagure.io/koji/pull-request/3731 Fixes: #3730 https://pagure.io/koji/issue/3730 Double space before references in list-untagged --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 72ea3a2..2776068 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2854,7 +2854,7 @@ def anon_handle_list_untagged(goptions, session, args): else: fmt = "%(name)s-%(version)s-%(release)s" if options.show_references: - fmt = fmt + " %(refs)s" + fmt = fmt + " %(refs)s" output = sorted([fmt % x for x in data]) for line in output: print(line) diff --git a/tests/test_cli/test_list_untagged.py b/tests/test_cli/test_list_untagged.py index fffa7a3..bf251c3 100644 --- a/tests/test_cli/test_list_untagged.py +++ b/tests/test_cli/test_list_untagged.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +import koji import mock import unittest from six.moves import StringIO @@ -9,17 +10,29 @@ from . import utils class TestListUntagged(utils.CliTestCase): def setUp(self): + self.maxDiff = None 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'} - ] + 'name': 'test-package-1234', + 'release': '11', + 'version': '1.1'}, + {'id': 2, + 'name': 'test-package-1234', + 'release': '99', + 'version': '1.33'} + ] + + def __vm(self, result): + m = koji.VirtualCall('mcall_method', [], {}) + if isinstance(result, dict) and result.get('faultCode'): + m._result = result + else: + m._result = (result,) + return m + + def tearDown(self): + mock.patch.stopall() @mock.patch('sys.stdout', new_callable=StringIO) @mock.patch('koji_cli.commands.ensure_connection') @@ -89,6 +102,34 @@ class TestListUntagged(utils.CliTestCase): ['--paths', package_name]) self.assert_console_message(stdout, expected) + @mock.patch('sys.stdout', new_callable=StringIO) + @mock.patch('koji_cli.commands.ensure_connection') + def test_list_untagged_package_show_references(self, ensure_connection, stdout): + # test case when package is existing + rpms = [{'rpm_id': 123}, {'rpm_id': 125}] + archives = [{'archive_id': 999}, {'archive_id': 888}] + components = [{'archive_id': 999, 'rpm_id': 125}] + build_references = {'tags': [{'name': 'tag-48rj15ma3a', 'tag_id': 2}], + 'rpms': rpms, + 'component_of': components, + 'archives': archives, + 'last_used': None, + 'images': []} + mcall = self.session.multicall.return_value.__enter__.return_value + mcall.buildReferences.return_value = self.__vm(build_references) + package_name = 'test-package-1234' + + self.session.untaggedBuilds.return_value = self.untagged_values + list_untagged = [u['name'] + '-' + u['version'] + '-' + u['release'] + for u in self.untagged_values] + expected = """(Showing build references) +%s rpms: %s, images/archives: %s, archives buildroots: %s +%s rpms: %s, images/archives: %s, archives buildroots: %s +""" % (list_untagged[0], rpms, components, archives, list_untagged[1], rpms, components, archives) + anon_handle_list_untagged(self.options, self.session, + ['--show-references', package_name]) + self.assert_console_message(stdout, expected) + def test_handle_list_history_help(self): self.assert_help( anon_handle_list_untagged,