Merge lp:~wallyworld/launchpad/mp-related-bugtasks-webservice into lp:launchpad

Proposed by Ian Booth
Status: Merged
Approved by: Ian Booth
Approved revision: no longer in the source branch.
Merged at revision: 12539
Proposed branch: lp:~wallyworld/launchpad/mp-related-bugtasks-webservice
Merge into: lp:launchpad
Prerequisite: lp:~wallyworld/launchpad/remove-decoratedbug
Diff against target: 162 lines (+48/-23)
4 files modified
lib/canonical/launchpad/interfaces/_schema_circular_imports.py (+2/-0)
lib/lp/code/interfaces/branchmergeproposal.py (+6/-0)
lib/lp/code/model/tests/test_branch.py (+2/-20)
lib/lp/code/model/tests/test_branchmergeproposal.py (+38/-3)
To merge this branch: bzr merge lp:~wallyworld/launchpad/mp-related-bugtasks-webservice
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Robert Collins (community) Abstain
Review via email: mp+52004@code.launchpad.net

Commit message

Export branch merge proposal getReleatedBugTasks as a webservice API

Description of the change

Export branch merge proposal getReleatedBugTasks as a webservice API.

== Tests ==

Create new TestWebservice test case in lp.code.model.tests.test_branchmergeproposal
Move test test_getMergeProposals_with_merged_revnos() from test_branch
Add new test test_getRelatedBugTasks()

Drive by fix in test_branch to replace hard coded service_root with "self.layer.appserver_root_url('api')"

== Lint ==

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/canonical/launchpad/interfaces/_schema_circular_imports.py
  lib/lp/code/interfaces/branchmergeproposal.py
  lib/lp/code/model/tests/test_branch.py
  lib/lp/code/model/tests/test_branchmergeproposal.py

./lib/canonical/launchpad/interfaces/_schema_circular_imports.py
     555: E501 line too long (82 characters)
     555: Line exceeds 78 characters.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

This exports to the 1.0 and beta api versions; we should not be changing 1.0 - you should only export to the devel web service.

review: Needs Fixing
Revision history for this message
Ian Booth (wallyworld) wrote :

> This exports to the 1.0 and beta api versions; we should not be changing 1.0 -
> you should only export to the devel web service.

Done

Revision history for this message
Robert Collins (lifeless) wrote :

my objection based on api version is resolved; I've no particular opinion on the rest of the code. This seems to be extremely close to the bug search facilities for linked branches (though the latest stuff might need api export tweaks to support mapping back in from urls through the API). This kindof gets into the fatness and redundancy we have already : perhaps it would be better to permit searching for bugtasks that are relevant to some merge proposals. (e.g. you could search for bugs relevant to any open merge proposal in the launchpad-project). That would be more powerful than single-object dereferencing.

review: Abstain
Revision history for this message
Tim Penhey (thumper) wrote :

If we are going to have a definitive API strategy, then we should look to apply it to everything.

I think this adds value right now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/interfaces/_schema_circular_imports.py'
2--- lib/canonical/launchpad/interfaces/_schema_circular_imports.py 2011-02-24 23:41:43 +0000
3+++ lib/canonical/launchpad/interfaces/_schema_circular_imports.py 2011-03-04 11:08:14 +0000
4@@ -190,6 +190,8 @@
5 IBranchMergeProposal['nominateReviewer'].queryTaggedValue(
6 LAZR_WEBSERVICE_EXPORTED)['return_type'].schema = ICodeReviewVoteReference
7 IBranchMergeProposal['votes'].value_type.schema = ICodeReviewVoteReference
8+patch_collection_return_type(
9+ IBranchMergeProposal, 'getRelatedBugTasks', IBugTask)
10
11 patch_collection_return_type(IHasBranches, 'getBranches', IBranch)
12 patch_collection_return_type(
13
14=== modified file 'lib/lp/code/interfaces/branchmergeproposal.py'
15--- lib/lp/code/interfaces/branchmergeproposal.py 2011-03-04 11:08:11 +0000
16+++ lib/lp/code/interfaces/branchmergeproposal.py 2011-03-04 11:08:14 +0000
17@@ -39,7 +39,9 @@
18 export_read_operation,
19 export_write_operation,
20 exported,
21+ operation_for_version,
22 operation_parameters,
23+ operation_returns_collection_of,
24 operation_returns_entry,
25 rename_parameters_as,
26 REQUEST_USER,
27@@ -296,6 +298,10 @@
28 def getComment(id):
29 """Return the CodeReviewComment with the specified ID."""
30
31+ @call_with(user=REQUEST_USER)
32+ @operation_returns_collection_of(Interface) # IBugTask
33+ @export_read_operation()
34+ @operation_for_version('devel')
35 def getRelatedBugTasks(user):
36 """Return the Bug tasks related to this merge proposal."""
37
38
39=== modified file 'lib/lp/code/model/tests/test_branch.py'
40--- lib/lp/code/model/tests/test_branch.py 2011-03-02 04:25:06 +0000
41+++ lib/lp/code/model/tests/test_branch.py 2011-03-04 11:08:14 +0000
42@@ -12,7 +12,6 @@
43 datetime,
44 timedelta,
45 )
46-from unittest import TestLoader
47
48 from bzrlib.bzrdir import BzrDir
49 from bzrlib.revision import NULL_REVISION
50@@ -2787,7 +2786,7 @@
51 db_queue = self.factory.makeBranchMergeQueue()
52 db_branch = self.factory.makeBranch()
53 launchpad = launchpadlib_for('test', db_branch.owner,
54- service_root="http://api.launchpad.dev:8085")
55+ service_root=self.layer.appserver_root_url('api'))
56
57 configuration = simplejson.dumps({'test': 'make check'})
58
59@@ -2804,7 +2803,7 @@
60 with person_logged_in(ANONYMOUS):
61 db_branch = self.factory.makeBranch()
62 launchpad = launchpadlib_for('test', db_branch.owner,
63- service_root="http://api.launchpad.dev:8085")
64+ service_root=self.layer.appserver_root_url('api'))
65
66 configuration = simplejson.dumps({'test': 'make check'})
67
68@@ -2814,20 +2813,3 @@
69
70 branch2 = ws_object(launchpad, db_branch)
71 self.assertEqual(branch2.merge_queue_config, configuration)
72-
73- def test_getMergeProposals_with_merged_revnos(self):
74- """Specifying merged revnos selects the correct merge proposal."""
75- mp = self.factory.makeBranchMergeProposal()
76- launchpad = launchpadlib_for('test', mp.registrant,
77- service_root="http://api.launchpad.dev:8085")
78- with person_logged_in(mp.registrant):
79- mp.markAsMerged(merged_revno=123)
80- transaction.commit()
81- target = ws_object(launchpad, mp.target_branch)
82- mp = ws_object(launchpad, mp)
83- self.assertEqual([mp], list(target.getMergeProposals(
84- status=['Merged'], merged_revnos=[123])))
85-
86-
87-def test_suite():
88- return TestLoader().loadTestsFromName(__name__)
89
90=== modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py'
91--- lib/lp/code/model/tests/test_branchmergeproposal.py 2011-03-04 11:08:11 +0000
92+++ lib/lp/code/model/tests/test_branchmergeproposal.py 2011-03-04 11:08:14 +0000
93@@ -14,7 +14,6 @@
94 from difflib import unified_diff
95 from unittest import (
96 TestCase,
97- TestLoader,
98 )
99
100 from lazr.lifecycle.event import ObjectModifiedEvent
101@@ -32,6 +31,7 @@
102 from canonical.launchpad.webapp import canonical_url
103 from canonical.launchpad.webapp.testing import verifyObject
104 from canonical.testing.layers import (
105+ AppServerLayer,
106 DatabaseFunctionalLayer,
107 LaunchpadFunctionalLayer,
108 LaunchpadZopelessLayer,
109@@ -78,10 +78,12 @@
110 from lp.registry.interfaces.person import IPersonSet
111 from lp.registry.interfaces.product import IProductSet
112 from lp.testing import (
113+ launchpadlib_for,
114 login,
115 login_person,
116 person_logged_in,
117 TestCaseWithFactory,
118+ ws_object,
119 )
120 from lp.testing.factory import (
121 GPGSigningContext,
122@@ -1993,5 +1995,38 @@
123 self.assertNotIn(r1, partial_revisions)
124
125
126-def test_suite():
127- return TestLoader().loadTestsFromName(__name__)
128+class TestWebservice(TestCaseWithFactory):
129+ """Tests for the webservice."""
130+
131+ layer = AppServerLayer
132+
133+ def test_getMergeProposals_with_merged_revnos(self):
134+ """Specifying merged revnos selects the correct merge proposal."""
135+ mp = self.factory.makeBranchMergeProposal()
136+ launchpad = launchpadlib_for(
137+ 'test', mp.registrant,
138+ service_root=self.layer.appserver_root_url('api'))
139+
140+ with person_logged_in(mp.registrant):
141+ mp.markAsMerged(merged_revno=123)
142+ transaction.commit()
143+ target = ws_object(launchpad, mp.target_branch)
144+ mp = ws_object(launchpad, mp)
145+ self.assertEqual([mp], list(target.getMergeProposals(
146+ status=['Merged'], merged_revnos=[123])))
147+
148+ def test_getRelatedBugTasks(self):
149+ """Test the getRelatedBugTasks API."""
150+ db_bmp = self.factory.makeBranchMergeProposal()
151+ launchpad = launchpadlib_for(
152+ 'test', db_bmp.registrant, version="devel",
153+ service_root=self.layer.appserver_root_url('api'))
154+
155+ with person_logged_in(db_bmp.registrant):
156+ db_bug = self.factory.makeBug()
157+ db_bmp.source_branch.linkBug(db_bug, db_bmp.registrant)
158+ transaction.commit()
159+ bmp = ws_object(launchpad, db_bmp)
160+ bugtask = ws_object(launchpad, db_bug.default_bugtask)
161+ self.assertEqual(
162+ [bugtask], list(bmp.getRelatedBugTasks()))