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
1=== modified file 'lib/lp/code/errors.py'
2--- lib/lp/code/errors.py 2011-08-22 17:40:02 +0000
3+++ lib/lp/code/errors.py 2011-08-23 15:37:33 +0000
4@@ -60,6 +60,7 @@
5 """The context is not valid for a branch merge proposal search."""
6
7
8+@error_status(httplib.BAD_REQUEST)
9 class BadStateTransition(Exception):
10 """The user requested a state transition that is not possible."""
11
12
13=== modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py'
14--- lib/lp/code/model/tests/test_branchmergeproposal.py 2011-06-24 19:51:18 +0000
15+++ lib/lp/code/model/tests/test_branchmergeproposal.py 2011-08-23 15:37:33 +0000
16@@ -17,6 +17,7 @@
17 )
18
19 from lazr.lifecycle.event import ObjectModifiedEvent
20+from lazr.restfulclient.errors import BadRequest
21 from pytz import UTC
22 from sqlobject import SQLObjectNotFound
23 from storm.locals import Store
24@@ -86,6 +87,7 @@
25 person_logged_in,
26 TestCaseWithFactory,
27 ws_object,
28+ WebServiceTestCase,
29 )
30 from lp.testing.factory import (
31 GPGSigningContext,
32@@ -2005,11 +2007,9 @@
33 self.assertNotIn(r1, partial_revisions)
34
35
36-class TestWebservice(TestCaseWithFactory):
37+class TestWebservice(WebServiceTestCase):
38 """Tests for the webservice."""
39
40- layer = AppServerLayer
41-
42 def test_getMergeProposals_with_merged_revnos(self):
43 """Specifying merged revnos selects the correct merge proposal."""
44 mp = self.factory.makeBranchMergeProposal()
45@@ -2028,15 +2028,22 @@
46 def test_getRelatedBugTasks(self):
47 """Test the getRelatedBugTasks API."""
48 db_bmp = self.factory.makeBranchMergeProposal()
49- launchpad = launchpadlib_for(
50- 'test', db_bmp.registrant, version="devel",
51- service_root=self.layer.appserver_root_url('api'))
52-
53- with person_logged_in(db_bmp.registrant):
54- db_bug = self.factory.makeBug()
55- db_bmp.source_branch.linkBug(db_bug, db_bmp.registrant)
56- transaction.commit()
57- bmp = ws_object(launchpad, db_bmp)
58- bugtask = ws_object(launchpad, db_bug.default_bugtask)
59+ db_bug = self.factory.makeBug()
60+ db_bmp.source_branch.linkBug(db_bug, db_bmp.registrant)
61+ transaction.commit()
62+ bmp = self.wsObject(db_bmp)
63+ bugtask = self.wsObject(db_bug.default_bugtask)
64 self.assertEqual(
65 [bugtask], list(bmp.getRelatedBugTasks()))
66+
67+ def test_setStatus_invalid_transition(self):
68+ """Emit BadRequest when an invalid transition is requested."""
69+ bmp = self.factory.makeBranchMergeProposal()
70+ with person_logged_in(bmp.registrant):
71+ bmp.resubmit(bmp.registrant)
72+ transaction.commit()
73+ ws_bmp = self.wsObject(bmp, user=bmp.target_branch.owner)
74+ with ExpectedException(
75+ BadRequest,
76+ '(.|\n)*Invalid state transition for merge proposal(.|\n)*'):
77+ ws_bmp.setStatus(status='Approved')