From 693f196fa45da583cd67859a6bf4b2be5a39b7b4 Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: Wed, 1 Mar 2023 14:31:35 +0100 Subject: [PATCH] Add missing argument in edit-sidetag help msg Fixes: https://pagure.io/koji/issue/3717 --- plugins/cli/sidetag_cli.py | 2 +- tests/test_plugins/test_sidetag_cli.py | 124 +++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 tests/test_plugins/test_sidetag_cli.py diff --git a/plugins/cli/sidetag_cli.py b/plugins/cli/sidetag_cli.py index 297f6f09..401c8b72 100644 --- a/plugins/cli/sidetag_cli.py +++ b/plugins/cli/sidetag_cli.py @@ -99,7 +99,7 @@ def handle_list_sidetags(options, session, args): @export_cli def handle_edit_sidetag(options, session, args): "Edit sidetag" - usage = "%(prog)s edit-sidetag [options]" + usage = "%(prog)s edit-sidetag [options] " usage += "\n(Specify the --help global option for a list of other help options)" parser = ArgumentParser(usage=usage) parser.add_argument("sidetag", help="name of sidetag") diff --git a/tests/test_plugins/test_sidetag_cli.py b/tests/test_plugins/test_sidetag_cli.py new file mode 100644 index 00000000..d3bb9d6e --- /dev/null +++ b/tests/test_plugins/test_sidetag_cli.py @@ -0,0 +1,124 @@ +from __future__ import absolute_import +import io +import mock +import six +import unittest +import os +import sys + +import koji +from . import load_plugin + +sidetag = load_plugin.load_plugin('cli', 'sidetag_cli') + + +def mock_stdout(): + def get_mock(): + if six.PY2: + return six.StringIO() + else: + return io.TextIOWrapper(six.BytesIO()) + return mock.patch('sys.stdout', new_callable=get_mock) + + +def get_stdout_value(stdout): + if six.PY2: + return stdout.getvalue() + else: + # we have to force the TextIOWrapper to stop buffering + return stdout.detach().getvalue() + + +class TestSideTagCLI(unittest.TestCase): + + def setUp(self): + # Show long diffs in error output... + self.maxDiff = None + self.options = mock.MagicMock() + self.options.debug = False + self.options.quiet = False + self.session = mock.MagicMock() + self.session.getAPIVersion.return_value = koji.API_VERSION + self.activate_session_mock = mock.patch('koji_cli.commands.activate_session').start() + self.progname = os.path.basename(sys.argv[0]) or 'koji' + + def tearDown(self): + mock.patch.stopall() + + @mock_stdout() + def test_add_sidetag_help(self, stdout): + with self.assertRaises(SystemExit) as ex: + sidetag.handle_add_sidetag(self.options, self.session, ['--help']) + std_output = get_stdout_value(stdout).decode('utf-8') + expected_help = """usage: %s add-sidetag [options] +(Specify the --help global option for a list of other help options) + +positional arguments: + basetag name of basetag + +options: + -h, --help show this help message and exit + -q, --quiet Do not print tag name + -w, --wait Wait until repo is ready. + --debuginfo Buildroot repo will contain debuginfos + --suffix SUFFIX Suffix from hub-supported ones +""" % self.progname + self.assertMultiLineEqual(std_output, expected_help) + self.assertEqual('0', str(ex.exception)) + + @mock_stdout() + def test_edit_sidetag_help(self, stdout): + with self.assertRaises(SystemExit) as ex: + sidetag.handle_edit_sidetag(self.options, self.session, ['--help']) + std_output = get_stdout_value(stdout).decode('utf-8') + expected_help = """usage: %s edit-sidetag [options] +(Specify the --help global option for a list of other help options) + +positional arguments: + sidetag name of sidetag + +options: + -h, --help show this help message and exit + --debuginfo Generate debuginfo repository + --no-debuginfo + --rpm-macro key=value + Set tag-specific rpm macros + --remove-rpm-macro key + Remove rpm macros +""" % self.progname + self.assertMultiLineEqual(std_output, expected_help) + self.assertEqual('0', str(ex.exception)) + + @mock_stdout() + def test_list_sidetags_help(self, stdout): + with self.assertRaises(SystemExit) as ex: + sidetag.handle_list_sidetags(self.options, self.session, ['--help']) + std_output = get_stdout_value(stdout).decode('utf-8') + expected_help = """usage: %s list-sidetags [options] +(Specify the --help global option for a list of other help options) + +options: + -h, --help show this help message and exit + --basetag BASETAG Filter on basetag + --user USER Filter on user + --mine Filter on user +""" % self.progname + self.assertMultiLineEqual(std_output, expected_help) + self.assertEqual('0', str(ex.exception)) + + @mock_stdout() + def test_remove_sidetag_help(self, stdout): + with self.assertRaises(SystemExit) as ex: + sidetag.handle_remove_sidetag(self.options, self.session, ['--help']) + std_output = get_stdout_value(stdout).decode('utf-8') + expected_help = """usage: %s remove-sidetag [options] ... +(Specify the --help global option for a list of other help options) + +positional arguments: + sidetags name of sidetag + +options: + -h, --help show this help message and exit +""" % self.progname + self.assertMultiLineEqual(std_output, expected_help) + self.assertEqual('0', str(ex.exception))