From 6fe42b6212d6e45c8b304d599b1cc7ef0d256b46 Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Wed, 18 Oct 2023 17:51:02 +0800 Subject: [PATCH] cil wrapper-rpm: input check and more reasonable opt --create-draft --- cli/koji_cli/commands.py | 14 ++++++++----- tests/test_cli/test_wrapper_rpm.py | 33 +++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 4b29c3bc..2b63876a 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -834,8 +834,8 @@ def handle_wrapper_rpm(options, session, args): parser.add_option("--nowait", action="store_false", dest="wait", help="Don't wait on build") parser.add_option("--background", action="store_true", help="Run the build at a lower priority") - parser.add_option("--draft", action="store_true", - help="Build draft build instead") + parser.add_option("--create-draft", action="store_true", + help="Create a new draft build instead") (build_opts, args) = parser.parse_args(args) if build_opts.inis: @@ -845,8 +845,12 @@ def handle_wrapper_rpm(options, session, args): if len(args) < 3: parser.error("You must provide a build target, a build ID or NVR, " "and a SCM URL to a specfile fragment") - if build_opts.scratch and build_opts.draft: - parser.error("--scratch and --draft cannot be both specfied") + if build_opts.create_draft: + print("Will create a draft build instead") + build_opts.create_build = True + if build_opts.scratch: + # TODO: --scratch and --create-build conflict too + parser.error("--scratch and --create-draft cannot be both specfied") activate_session(session, options) target = args[0] @@ -882,7 +886,7 @@ def handle_wrapper_rpm(options, session, args): opts['skip_tag'] = True if build_opts.scratch: opts['scratch'] = True - if build_opts.draft: + if build_opts.create_draft: opts['draft'] = True task_id = session.wrapperRPM(build_id, url, target, priority, opts=opts) print("Created task: %d" % task_id) diff --git a/tests/test_cli/test_wrapper_rpm.py b/tests/test_cli/test_wrapper_rpm.py index 94fbd880..507b5d4a 100644 --- a/tests/test_cli/test_wrapper_rpm.py +++ b/tests/test_cli/test_wrapper_rpm.py @@ -196,7 +196,7 @@ class TestWrapperRpm(utils.CliTestCase): @mock.patch('koji_cli.commands.activate_session') def test_handle_wrapper_rpm_argument_error( self, activate_session_mock, stderr, stdout): - """Test handle_wrapper_rpm help message output""" + """Test handle_wrapper_rpm error message output""" arguments = [] options = mock.MagicMock() @@ -219,8 +219,35 @@ class TestWrapperRpm(utils.CliTestCase): # Finally, assert that things were called as we expected. activate_session_mock.assert_not_called() + @mock.patch('sys.stdout', new_callable=six.StringIO) + @mock.patch('sys.stderr', new_callable=six.StringIO) + @mock.patch('koji_cli.commands.activate_session') + def test_handle_wrapper_rpm_argument_conflict_error( + self, activate_session_mock, stderr, stdout): + """Test handle_wrapper_rpm error message output""" + arguments = ['--scratch', '--create-draft', 'foo', 'n-v-r', 'scmurl'] + options = mock.MagicMock() + + # Mock out the xmlrpc server + session = mock.MagicMock() + + # Run it and check immediate output + expected = self.format_error_message( + "--scratch and --create-draft cannot be both specfied") + self.assert_system_exit( + handle_wrapper_rpm, + options, + session, + arguments, + stdout='Will create a draft build instead\n', + stderr=expected, + activate_session=None) + + # Finally, assert that things were called as we expected. + activate_session_mock.assert_not_called() + def test_handle_wrapper_rpm_help(self): - """Test handle_wrapper_rpm help message output""" + """Test handle_wrapper_rpm help message output""" self.assert_help( handle_wrapper_rpm, """Usage: %s wrapper-rpm [options] @@ -237,7 +264,7 @@ Options: --wait Wait on build, even if running in the background --nowait Don't wait on build --background Run the build at a lower priority - --draft Build draft build instead + --create-draft Create a new draft build instead """ % self.progname)