Merge lp:~stevenk/launchpad/invalid-mp-api into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 14751
Proposed branch: lp:~stevenk/launchpad/invalid-mp-api
Merge into: lp:launchpad
Diff against target: 46 lines (+16/-2)
2 files modified
lib/lp/code/errors.py (+2/-1)
lib/lp/code/tests/test_branch_webservice.py (+14/-1)
To merge this branch: bzr merge lp:~stevenk/launchpad/invalid-mp-api
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+91607@code.launchpad.net

Commit message

[r=stub][bug=905278] Raise BadRequest with a useful error message if a user calls IBranch.createMergeProposal() over the API where source == target.

Description of the change

Raise BadRequest with a useful error message if a user calls IBranch.createMergeProposal() over the API where source == target.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/errors.py'
2--- lib/lp/code/errors.py 2011-10-25 04:43:18 +0000
3+++ lib/lp/code/errors.py 2012-02-06 05:42:18 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Errors used in the lp/code modules."""
10@@ -217,6 +217,7 @@
11 """The user cannot claim the pending review."""
12
13
14+@error_status(httplib.BAD_REQUEST)
15 class InvalidBranchMergeProposal(Exception):
16 """Raised during the creation of a new branch merge proposal.
17
18
19=== modified file 'lib/lp/code/tests/test_branch_webservice.py'
20--- lib/lp/code/tests/test_branch_webservice.py 2012-01-30 06:02:10 +0000
21+++ lib/lp/code/tests/test_branch_webservice.py 2012-02-06 05:42:18 +0000
22@@ -1,4 +1,4 @@
23-# Copyright 2011 Canonical Ltd. This software is licensed under the
24+# Copyright 2011-2012 Canonical Ltd. This software is licensed under the
25 # GNU Affero General Public License version 3 (see the file LICENSE).
26
27 __metaclass__ = type
28@@ -69,6 +69,19 @@
29 self.assertEqual('Fred', info['person_name'])
30 self.assertEqual([visible_name], info['visible_branches'])
31
32+ def test_createMergeProposal_fails_if_source_and_target_are_equal(self):
33+ source = self.factory.makeBranch()
34+ source_url = api_url(source)
35+ lp = launchpadlib_for("test", source.owner.name)
36+ source = lp.load(source_url)
37+ exception = self.assertRaises(
38+ BadRequest, source.createMergeProposal,
39+ target_branch=source, initial_comment='Merge\nit!',
40+ needs_review=True, commit_message='It was merged!\n')
41+ self.assertEquals(
42+ exception.content,
43+ 'Source and target branches must be different.')
44+
45
46 class TestBranchDeletes(TestCaseWithFactory):
47