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
=== modified file 'lib/canonical/launchpad/interfaces/_schema_circular_imports.py'
--- lib/canonical/launchpad/interfaces/_schema_circular_imports.py 2011-02-24 23:41:43 +0000
+++ lib/canonical/launchpad/interfaces/_schema_circular_imports.py 2011-03-04 11:08:14 +0000
@@ -190,6 +190,8 @@
190IBranchMergeProposal['nominateReviewer'].queryTaggedValue(190IBranchMergeProposal['nominateReviewer'].queryTaggedValue(
191 LAZR_WEBSERVICE_EXPORTED)['return_type'].schema = ICodeReviewVoteReference191 LAZR_WEBSERVICE_EXPORTED)['return_type'].schema = ICodeReviewVoteReference
192IBranchMergeProposal['votes'].value_type.schema = ICodeReviewVoteReference192IBranchMergeProposal['votes'].value_type.schema = ICodeReviewVoteReference
193patch_collection_return_type(
194 IBranchMergeProposal, 'getRelatedBugTasks', IBugTask)
193195
194patch_collection_return_type(IHasBranches, 'getBranches', IBranch)196patch_collection_return_type(IHasBranches, 'getBranches', IBranch)
195patch_collection_return_type(197patch_collection_return_type(
196198
=== modified file 'lib/lp/code/interfaces/branchmergeproposal.py'
--- lib/lp/code/interfaces/branchmergeproposal.py 2011-03-04 11:08:11 +0000
+++ lib/lp/code/interfaces/branchmergeproposal.py 2011-03-04 11:08:14 +0000
@@ -39,7 +39,9 @@
39 export_read_operation,39 export_read_operation,
40 export_write_operation,40 export_write_operation,
41 exported,41 exported,
42 operation_for_version,
42 operation_parameters,43 operation_parameters,
44 operation_returns_collection_of,
43 operation_returns_entry,45 operation_returns_entry,
44 rename_parameters_as,46 rename_parameters_as,
45 REQUEST_USER,47 REQUEST_USER,
@@ -296,6 +298,10 @@
296 def getComment(id):298 def getComment(id):
297 """Return the CodeReviewComment with the specified ID."""299 """Return the CodeReviewComment with the specified ID."""
298300
301 @call_with(user=REQUEST_USER)
302 @operation_returns_collection_of(Interface) # IBugTask
303 @export_read_operation()
304 @operation_for_version('devel')
299 def getRelatedBugTasks(user):305 def getRelatedBugTasks(user):
300 """Return the Bug tasks related to this merge proposal."""306 """Return the Bug tasks related to this merge proposal."""
301307
302308
=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py 2011-03-02 04:25:06 +0000
+++ lib/lp/code/model/tests/test_branch.py 2011-03-04 11:08:14 +0000
@@ -12,7 +12,6 @@
12 datetime,12 datetime,
13 timedelta,13 timedelta,
14 )14 )
15from unittest import TestLoader
1615
17from bzrlib.bzrdir import BzrDir16from bzrlib.bzrdir import BzrDir
18from bzrlib.revision import NULL_REVISION17from bzrlib.revision import NULL_REVISION
@@ -2787,7 +2786,7 @@
2787 db_queue = self.factory.makeBranchMergeQueue()2786 db_queue = self.factory.makeBranchMergeQueue()
2788 db_branch = self.factory.makeBranch()2787 db_branch = self.factory.makeBranch()
2789 launchpad = launchpadlib_for('test', db_branch.owner,2788 launchpad = launchpadlib_for('test', db_branch.owner,
2790 service_root="http://api.launchpad.dev:8085")2789 service_root=self.layer.appserver_root_url('api'))
27912790
2792 configuration = simplejson.dumps({'test': 'make check'})2791 configuration = simplejson.dumps({'test': 'make check'})
27932792
@@ -2804,7 +2803,7 @@
2804 with person_logged_in(ANONYMOUS):2803 with person_logged_in(ANONYMOUS):
2805 db_branch = self.factory.makeBranch()2804 db_branch = self.factory.makeBranch()
2806 launchpad = launchpadlib_for('test', db_branch.owner,2805 launchpad = launchpadlib_for('test', db_branch.owner,
2807 service_root="http://api.launchpad.dev:8085")2806 service_root=self.layer.appserver_root_url('api'))
28082807
2809 configuration = simplejson.dumps({'test': 'make check'})2808 configuration = simplejson.dumps({'test': 'make check'})
28102809
@@ -2814,20 +2813,3 @@
28142813
2815 branch2 = ws_object(launchpad, db_branch)2814 branch2 = ws_object(launchpad, db_branch)
2816 self.assertEqual(branch2.merge_queue_config, configuration)2815 self.assertEqual(branch2.merge_queue_config, configuration)
2817
2818 def test_getMergeProposals_with_merged_revnos(self):
2819 """Specifying merged revnos selects the correct merge proposal."""
2820 mp = self.factory.makeBranchMergeProposal()
2821 launchpad = launchpadlib_for('test', mp.registrant,
2822 service_root="http://api.launchpad.dev:8085")
2823 with person_logged_in(mp.registrant):
2824 mp.markAsMerged(merged_revno=123)
2825 transaction.commit()
2826 target = ws_object(launchpad, mp.target_branch)
2827 mp = ws_object(launchpad, mp)
2828 self.assertEqual([mp], list(target.getMergeProposals(
2829 status=['Merged'], merged_revnos=[123])))
2830
2831
2832def test_suite():
2833 return TestLoader().loadTestsFromName(__name__)
28342816
=== modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py'
--- lib/lp/code/model/tests/test_branchmergeproposal.py 2011-03-04 11:08:11 +0000
+++ lib/lp/code/model/tests/test_branchmergeproposal.py 2011-03-04 11:08:14 +0000
@@ -14,7 +14,6 @@
14from difflib import unified_diff14from difflib import unified_diff
15from unittest import (15from unittest import (
16 TestCase,16 TestCase,
17 TestLoader,
18 )17 )
1918
20from lazr.lifecycle.event import ObjectModifiedEvent19from lazr.lifecycle.event import ObjectModifiedEvent
@@ -32,6 +31,7 @@
32from canonical.launchpad.webapp import canonical_url31from canonical.launchpad.webapp import canonical_url
33from canonical.launchpad.webapp.testing import verifyObject32from canonical.launchpad.webapp.testing import verifyObject
34from canonical.testing.layers import (33from canonical.testing.layers import (
34 AppServerLayer,
35 DatabaseFunctionalLayer,35 DatabaseFunctionalLayer,
36 LaunchpadFunctionalLayer,36 LaunchpadFunctionalLayer,
37 LaunchpadZopelessLayer,37 LaunchpadZopelessLayer,
@@ -78,10 +78,12 @@
78from lp.registry.interfaces.person import IPersonSet78from lp.registry.interfaces.person import IPersonSet
79from lp.registry.interfaces.product import IProductSet79from lp.registry.interfaces.product import IProductSet
80from lp.testing import (80from lp.testing import (
81 launchpadlib_for,
81 login,82 login,
82 login_person,83 login_person,
83 person_logged_in,84 person_logged_in,
84 TestCaseWithFactory,85 TestCaseWithFactory,
86 ws_object,
85 )87 )
86from lp.testing.factory import (88from lp.testing.factory import (
87 GPGSigningContext,89 GPGSigningContext,
@@ -1993,5 +1995,38 @@
1993 self.assertNotIn(r1, partial_revisions)1995 self.assertNotIn(r1, partial_revisions)
19941996
19951997
1996def test_suite():1998class TestWebservice(TestCaseWithFactory):
1997 return TestLoader().loadTestsFromName(__name__)1999 """Tests for the webservice."""
2000
2001 layer = AppServerLayer
2002
2003 def test_getMergeProposals_with_merged_revnos(self):
2004 """Specifying merged revnos selects the correct merge proposal."""
2005 mp = self.factory.makeBranchMergeProposal()
2006 launchpad = launchpadlib_for(
2007 'test', mp.registrant,
2008 service_root=self.layer.appserver_root_url('api'))
2009
2010 with person_logged_in(mp.registrant):
2011 mp.markAsMerged(merged_revno=123)
2012 transaction.commit()
2013 target = ws_object(launchpad, mp.target_branch)
2014 mp = ws_object(launchpad, mp)
2015 self.assertEqual([mp], list(target.getMergeProposals(
2016 status=['Merged'], merged_revnos=[123])))
2017
2018 def test_getRelatedBugTasks(self):
2019 """Test the getRelatedBugTasks API."""
2020 db_bmp = self.factory.makeBranchMergeProposal()
2021 launchpad = launchpadlib_for(
2022 'test', db_bmp.registrant, version="devel",
2023 service_root=self.layer.appserver_root_url('api'))
2024
2025 with person_logged_in(db_bmp.registrant):
2026 db_bug = self.factory.makeBug()
2027 db_bmp.source_branch.linkBug(db_bug, db_bmp.registrant)
2028 transaction.commit()
2029 bmp = ws_object(launchpad, db_bmp)
2030 bugtask = ws_object(launchpad, db_bug.default_bugtask)
2031 self.assertEqual(
2032 [bugtask], list(bmp.getRelatedBugTasks()))