Merge lp:~abentley/launchpad/bad-state-transition-2 into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 13776
Proposed branch: lp:~abentley/launchpad/bad-state-transition-2
Merge into: lp:launchpad
Diff against target: 77 lines (+21/-13)
2 files modified
lib/lp/code/errors.py (+1/-0)
lib/lp/code/model/tests/test_branchmergeproposal.py (+20/-13)
To merge this branch: bzr merge lp:~abentley/launchpad/bad-state-transition-2
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+72592@code.launchpad.net

Commit message

Treat BadStateTransition as BadRequest.

Description of the change

= Summary =
Fix bug #820050: BadStateTransition: Invalid state transition for merge proposal: Superseded -> Approved

== Proposed fix ==
Have the web service treat BadStateTransition as a 400 Bad Request instead of a 500 Internal Server Error.

== Pre-implementation notes ==
None

== Implementation details ==
Modernized nearby tests.

== Tests ==
bin/test -t test_setStatus_invalid_transition test_branchmergeproposal

== Demo and Q/A ==
Create a merge proposal with a target that you can approvve, and resubmit it.
Using the web service, call setStatus(status='Approved) on the proposal. You should get BadRequest exception, not an Internal Server Error.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/code/errors.py
  lib/lp/code/model/tests/test_branchmergeproposal.py

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/errors.py'
--- lib/lp/code/errors.py 2011-08-22 17:40:02 +0000
+++ lib/lp/code/errors.py 2011-08-23 15:37:33 +0000
@@ -60,6 +60,7 @@
60 """The context is not valid for a branch merge proposal search."""60 """The context is not valid for a branch merge proposal search."""
6161
6262
63@error_status(httplib.BAD_REQUEST)
63class BadStateTransition(Exception):64class BadStateTransition(Exception):
64 """The user requested a state transition that is not possible."""65 """The user requested a state transition that is not possible."""
6566
6667
=== modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py'
--- lib/lp/code/model/tests/test_branchmergeproposal.py 2011-06-24 19:51:18 +0000
+++ lib/lp/code/model/tests/test_branchmergeproposal.py 2011-08-23 15:37:33 +0000
@@ -17,6 +17,7 @@
17 )17 )
1818
19from lazr.lifecycle.event import ObjectModifiedEvent19from lazr.lifecycle.event import ObjectModifiedEvent
20from lazr.restfulclient.errors import BadRequest
20from pytz import UTC21from pytz import UTC
21from sqlobject import SQLObjectNotFound22from sqlobject import SQLObjectNotFound
22from storm.locals import Store23from storm.locals import Store
@@ -86,6 +87,7 @@
86 person_logged_in,87 person_logged_in,
87 TestCaseWithFactory,88 TestCaseWithFactory,
88 ws_object,89 ws_object,
90 WebServiceTestCase,
89 )91 )
90from lp.testing.factory import (92from lp.testing.factory import (
91 GPGSigningContext,93 GPGSigningContext,
@@ -2005,11 +2007,9 @@
2005 self.assertNotIn(r1, partial_revisions)2007 self.assertNotIn(r1, partial_revisions)
20062008
20072009
2008class TestWebservice(TestCaseWithFactory):2010class TestWebservice(WebServiceTestCase):
2009 """Tests for the webservice."""2011 """Tests for the webservice."""
20102012
2011 layer = AppServerLayer
2012
2013 def test_getMergeProposals_with_merged_revnos(self):2013 def test_getMergeProposals_with_merged_revnos(self):
2014 """Specifying merged revnos selects the correct merge proposal."""2014 """Specifying merged revnos selects the correct merge proposal."""
2015 mp = self.factory.makeBranchMergeProposal()2015 mp = self.factory.makeBranchMergeProposal()
@@ -2028,15 +2028,22 @@
2028 def test_getRelatedBugTasks(self):2028 def test_getRelatedBugTasks(self):
2029 """Test the getRelatedBugTasks API."""2029 """Test the getRelatedBugTasks API."""
2030 db_bmp = self.factory.makeBranchMergeProposal()2030 db_bmp = self.factory.makeBranchMergeProposal()
2031 launchpad = launchpadlib_for(2031 db_bug = self.factory.makeBug()
2032 'test', db_bmp.registrant, version="devel",2032 db_bmp.source_branch.linkBug(db_bug, db_bmp.registrant)
2033 service_root=self.layer.appserver_root_url('api'))2033 transaction.commit()
20342034 bmp = self.wsObject(db_bmp)
2035 with person_logged_in(db_bmp.registrant):2035 bugtask = self.wsObject(db_bug.default_bugtask)
2036 db_bug = self.factory.makeBug()
2037 db_bmp.source_branch.linkBug(db_bug, db_bmp.registrant)
2038 transaction.commit()
2039 bmp = ws_object(launchpad, db_bmp)
2040 bugtask = ws_object(launchpad, db_bug.default_bugtask)
2041 self.assertEqual(2036 self.assertEqual(
2042 [bugtask], list(bmp.getRelatedBugTasks()))2037 [bugtask], list(bmp.getRelatedBugTasks()))
2038
2039 def test_setStatus_invalid_transition(self):
2040 """Emit BadRequest when an invalid transition is requested."""
2041 bmp = self.factory.makeBranchMergeProposal()
2042 with person_logged_in(bmp.registrant):
2043 bmp.resubmit(bmp.registrant)
2044 transaction.commit()
2045 ws_bmp = self.wsObject(bmp, user=bmp.target_branch.owner)
2046 with ExpectedException(
2047 BadRequest,
2048 '(.|\n)*Invalid state transition for merge proposal(.|\n)*'):
2049 ws_bmp.setStatus(status='Approved')