From 6e68939811f4ef6967f3459f2d909bb1d234e21c Mon Sep 17 00:00:00 2001 From: mprahl Date: Nov 08 2018 12:43:10 +0000 Subject: Raise an error if the module build command receives optional arguments that conflict Signed-off-by: mprahl --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index cc3c6ba..7615e42 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -3514,6 +3514,10 @@ class Commands(object): raise rpkgError( 'Optional arguments are not in the proper "key=value" format') + conflicting_keys = set(body.keys()) & set(optional_dict.keys()) + if conflicting_keys: + raise rpkgError('The following optional arguments conflict with other arguments: {0}' + .format(', '.join(conflicting_keys))) body.update(optional_dict) url = self.module_get_url(build_id=None, action='POST') resp = self.module_send_authorized_request( diff --git a/tests/test_cli.py b/tests/test_cli.py index 745a97c..8ffd040 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2072,6 +2072,32 @@ class TestModulesCli(CliTestCase): '1095 and 1096 were submitted to the MBS') self.assertEqual(output, expected_output) + @patch('requests.get') + def test_module_build_conflicting_keys(self, mock_get): + """ + Test a module build with optional arguments the conflict with other arguments + """ + cli_cmd = [ + 'rpkg', + '--path', + self.cloned_repo_path, + 'module-build', + 'git://pkgs.fedoraproject.org/modules/testmodule?#79d87a5a', + 'master', + '--optional', 'scmurl=git://pkgs.fedoraproject.org/modules/testmodule?#1234' + ] + mock_get.return_value.ok = True + mock_get.return_value.json.return_value = { + 'auth_method': 'oidc', + 'api_version': 2 + } + + expected_error = 'The following optional arguments conflict with other arguments: scmurl' + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + with six.assertRaisesRegex(self, rpkgError, expected_error): + cli.module_build() + @patch('sys.stdout', new=StringIO()) @patch('requests.get') @patch('openidc_client.OpenIDCClient.send_request')