Skip to content

Commit 5a9c188

Browse files
committed
Don't expect return value from API.patch_set
The XML-RPC API returns True if a patch update is successful else it raises an exception. The REST API returns an updated copy of the patch if successful else it returns a HTTP 4xx error. These different return styles meant we couldn't effectively return a value from the 'patch_set' API method in the success case, only raise an exception in the failure case. We addressed this in commit 0949e9e but forgot to update callers than were checking for a success return value. Do this now. Signed-off-by: Stephen Finucane <[email protected]> Fixes: 0949e9e ("api: More signature corrections") Closes: #23
1 parent e05174e commit 5a9c188

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

pwclient/patches.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,13 @@ def action_update(api, patch_id, state=None, archived=None, commit_ref=None):
225225
print(str(exc), file=sys.stderr)
226226
sys.exit(1)
227227

228-
success = False
229228
try:
230-
success = api.patch_set(
229+
api.patch_set(
231230
patch_id,
232231
state=state,
233232
archived=archived,
234233
commit_ref=commit_ref,
235234
)
236235
except Exception as exc:
237236
print(str(exc), file=sys.stderr)
238-
239-
if not success:
240-
print('Patch not updated', file=sys.stderr)
237+
sys.exit(1)

tests/test_patches.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ def test_action_update__error(capsys):
519519
api.patch_get.return_value = fakes.fake_patches()[0]
520520
api.patch_set.side_effect = exceptions.APIError('foo')
521521

522-
patches.action_update(api, 1157169)
522+
with pytest.raises(SystemExit):
523+
patches.action_update(api, 1157169)
523524

524525
api.patch_set.assert_called_once_with(
525526
1157169, archived=None, commit_ref=None, state=None
@@ -532,23 +533,5 @@ def test_action_update__error(capsys):
532533
captured.err
533534
== """\
534535
foo
535-
Patch not updated
536536
"""
537537
)
538-
539-
540-
def test_action_update__no_updates(capsys):
541-
api = mock.Mock()
542-
api.patch_get.return_value = fakes.fake_patches()[0]
543-
api.patch_set.return_value = None
544-
545-
patches.action_update(api, 1157169)
546-
547-
api.patch_set.assert_called_once_with(
548-
1157169, archived=None, commit_ref=None, state=None
549-
)
550-
551-
captured = capsys.readouterr()
552-
553-
assert captured.out == ''
554-
assert captured.err == 'Patch not updated\n'

0 commit comments

Comments
 (0)