← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/invalid-mp-api into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #905278 in Launchpad itself: "InvalidBranchMergeProposal: Source and target branches must be different using the API "
  https://bugs.launchpad.net/launchpad/+bug/905278

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/invalid-mp-api/+merge/91607

Raise BadRequest with a useful error message if a user calls IBranch.createMergeProposal() over the API where source == target.
-- 
https://code.launchpad.net/~stevenk/launchpad/invalid-mp-api/+merge/91607
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/invalid-mp-api into lp:launchpad.
=== modified file 'lib/lp/code/errors.py'
--- lib/lp/code/errors.py	2011-10-25 04:43:18 +0000
+++ lib/lp/code/errors.py	2012-02-06 05:38:21 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Errors used in the lp/code modules."""
@@ -217,6 +217,7 @@
     """The user cannot claim the pending review."""
 
 
+@error_status(httplib.BAD_REQUEST)
 class InvalidBranchMergeProposal(Exception):
     """Raised during the creation of a new branch merge proposal.
 

=== modified file 'lib/lp/code/tests/test_branch_webservice.py'
--- lib/lp/code/tests/test_branch_webservice.py	2012-01-30 06:02:10 +0000
+++ lib/lp/code/tests/test_branch_webservice.py	2012-02-06 05:38:21 +0000
@@ -1,4 +1,4 @@
-# Copyright 2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2011-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -69,6 +69,19 @@
         self.assertEqual('Fred', info['person_name'])
         self.assertEqual([visible_name], info['visible_branches'])
 
+    def test_createMergeProposal_fails_if_source_and_target_are_equal(self):
+        source = self.factory.makeBranch()
+        source_url = api_url(source)
+        lp = launchpadlib_for("test", source.owner.name)
+        source = lp.load(source_url)
+        exception = self.assertRaises(
+            BadRequest, source.createMergeProposal,
+            target_branch=source, initial_comment='Merge\nit!',
+            needs_review=True, commit_message='It was merged!\n')
+        self.assertEquals(
+            exception.content,
+            'Source and target branches must be different.')
+
 
 class TestBranchDeletes(TestCaseWithFactory):