From 258f5ae29843717f46c3dff31778fcf3b66e8aaf Mon Sep 17 00:00:00 2001 From: Vismay Golwala Date: Tue, 31 Jul 2018 16:52:49 -0400 Subject: [PATCH] Fix update error when 'bugs' not provided. fixes #2520 Signed-off-by: Vismay Golwala (cherry picked from commit 1e1d49fc4d4e2c1942d2493fc600e13b7d8f6f05) --- bodhi/client/__init__.py | 3 ++- bodhi/tests/client/test___init__.py | 40 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/bodhi/client/__init__.py b/bodhi/client/__init__.py index ad381d65d7..2d86cb75ca 100644 --- a/bodhi/client/__init__.py +++ b/bodhi/client/__init__.py @@ -384,9 +384,10 @@ def edit(user, password, url, **kwargs): kwargs['edited'] = title # Convert list of 'Bug' instances in DB to comma separated bug_ids for parsing. - former_update = resp['updates'][0] + former_update = resp['updates'][0].copy() if not kwargs['bugs']: kwargs['bugs'] = ",".join([str(bug['bug_id']) for bug in former_update['bugs']]) + former_update.pop('bugs', None) # Replace empty fields with former values from database. for field in kwargs: diff --git a/bodhi/tests/client/test___init__.py b/bodhi/tests/client/test___init__.py index 984e25a67d..978e20638b 100644 --- a/bodhi/tests/client/test___init__.py +++ b/bodhi/tests/client/test___init__.py @@ -1457,6 +1457,46 @@ def test_bodhi_client_exception(self, send_request): self.assertEqual(result.exit_code, 0) self.assertIn("This is a BodhiClientException message", result.output) + @mock.patch.dict(client_test_data.EXAMPLE_QUERY_MUNCH['updates'][0], {'bugs': []}) + @mock.patch('bodhi.client.bindings.BodhiClient.csrf', + mock.MagicMock(return_value='a_csrf_token')) + @mock.patch('bodhi.client.bindings.BodhiClient.query', + return_value=client_test_data.EXAMPLE_QUERY_MUNCH, autospec=True) + @mock.patch('bodhi.client.bindings.BodhiClient.send_request', + return_value=client_test_data.EXAMPLE_UPDATE_MUNCH, autospec=True) + def test_edit_bugless_update_without_bugs_param(self, send_request, query): + """Test editing an update with no bugs, without passing '--bugs' to it.""" + runner = testing.CliRunner() + + result = runner.invoke( + client.edit, ['FEDORA-2017-cc8582d738', '--user', 'bowlofeggs', + '--password', 's3kr3t']) + + self.assertEqual(result.exit_code, 0) + bindings_client = query.mock_calls[0][1][0] + query.assert_called_with( + bindings_client, updateid=u'FEDORA-2017-cc8582d738') + bindings_client = send_request.mock_calls[0][1][0] + calls = [ + mock.call( + bindings_client, 'updates/', auth=True, verb='POST', + data={ + 'close_bugs': False, 'stable_karma': 3, 'csrf_token': 'a_csrf_token', + 'staging': False, 'builds': u'nodejs-grunt-wrap-0.3.0-2.fc25', + 'autokarma': False, 'edited': u'nodejs-grunt-wrap-0.3.0-2.fc25', + 'suggest': u'unspecified', 'notes': u'New package.', + 'notes_file': None, 'request': None, 'severity': u'low', + 'bugs': '', 'requirements': u'', 'unstable_karma': -3, 'type': 'bugfix' + } + ), + mock.call( + bindings_client, + u'updates/FEDORA-EPEL-2016-3081a94111/get-test-results', + verb='GET' + ) + ] + self.assertEqual(send_request.mock_calls, calls) + class TestEditBuilrootOverrides(unittest.TestCase): """