← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~bryce/launchpad/lp-617699-api into lp:launchpad

 

Bryce Harrington has proposed merging lp:~bryce/launchpad/lp-617699-api into lp:launchpad with lp:~bryce/launchpad/lp-644794-db-foreign-keys as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers): code
Related bugs:
  #617699 Export bug_tracker APIs for upstream components
  https://bugs.launchpad.net/bugs/617699


Expose distribution source package functionality for component linking in API.

This branch is to expose launchpad API calls for interacting with the component and component group objects, used to model the component and product values in Bugzilla.  Most of the needed api functionality was implemented in an earlier branch, but this adds support for distro_source_package.


-- 
https://code.launchpad.net/~bryce/launchpad/lp-617699-api/+merge/37824
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~bryce/launchpad/lp-617699-api into lp:launchpad.
=== modified file 'database/schema/comments.sql'
--- database/schema/comments.sql	2010-10-04 22:56:09 +0000
+++ database/schema/comments.sql	2010-10-07 06:41:47 +0000
@@ -353,7 +353,8 @@
 COMMENT ON COLUMN BugTrackerComponent.is_visible IS 'Whether to display or hide the item in the Launchpad user interface.';
 COMMENT ON COLUMN BugTrackerComponent.is_custom IS 'Whether the item was added by a user in Launchpad or is kept in sync with the remote bug tracker.';
 COMMENT ON COLUMN BugTrackerComponent.component_group IS 'The product or other higher level category used by the remote bug tracker to group projects, if any.';
-COMMENT ON COLUMN BugTrackerComponent.distro_source_package IS 'A link to the source package in a distribution that corresponds to this component.  This can be undefined if no link has been established yet.';
+COMMENT ON COLUMN BugTrackerComponent.distribution IS 'Link to the distribution for the associated source package.  This can be NULL if no ling has been established.';
+COMMENT ON COLUMN BugTrackerComponent.source_package_name IS 'The text name of the source package in a distribution that corresponds to this component.  This can be NULL if no link has been established yet.';
 
 -- BugTrackerComponentGroup
 

=== added file 'database/schema/patch-2208-19-0.sql'
--- database/schema/patch-2208-19-0.sql	1970-01-01 00:00:00 +0000
+++ database/schema/patch-2208-19-0.sql	2010-10-07 06:41:47 +0000
@@ -0,0 +1,24 @@
+-- Copyright 2010 Canonical Ltd.  This software is licensed under the
+-- GNU Affero General Public License version 3 (see the file LICENSE).
+
+SET client_min_messages=ERROR;
+
+ALTER TABLE BugTrackerComponent
+    ADD COLUMN distribution integer REFERENCES Distribution;
+
+ALTER TABLE BugTrackerComponent
+    ADD COLUMN source_package_name integer REFERENCES SourcePackageName;
+
+ALTER TABLE BugTrackerComponent
+    DROP CONSTRAINT bugtrackercomponent__distro_source_package__key;
+
+ALTER TABLE BugTrackerComponent
+    DROP COLUMN distro_source_package;
+
+ALTER TABLE BugTrackerComponent ADD CONSTRAINT bugtrackercomponent__disto__spn__key
+    UNIQUE (distribution, source_package_name);
+
+ALTER TABLE BugTrackerComponent ADD CONSTRAINT valid_target
+    CHECK (distribution IS NULL = source_package_name IS NULL);
+
+INSERT INTO LaunchpadDatabaseRevision VALUES(2208, 19, 0);

=== added file 'database/schema/patch-2208-20-0.sql'
--- database/schema/patch-2208-20-0.sql	1970-01-01 00:00:00 +0000
+++ database/schema/patch-2208-20-0.sql	2010-10-07 06:41:47 +0000
@@ -0,0 +1,12 @@
+-- Copyright 2010 Canonical Ltd.  This software is licensed under the
+-- GNU Affero General Public License version 3 (see the file LICENSE).
+
+SET client_min_messages=ERROR;
+
+ALTER TABLE BugTrackerComponentGroup
+    DROP CONSTRAINT valid_name;
+
+ALTER TABLE BugTrackerComponent
+    DROP CONSTRAINT valid_name;
+
+INSERT INTO LaunchpadDatabaseRevision VALUES(2208, 20, 0);

=== modified file 'lib/lp/bugs/interfaces/bugtracker.py'
--- lib/lp/bugs/interfaces/bugtracker.py	2010-09-29 21:18:47 +0000
+++ lib/lp/bugs/interfaces/bugtracker.py	2010-10-07 06:41:47 +0000
@@ -67,7 +67,6 @@
     URIField,
     )
 
-
 LOCATION_SCHEMES_ALLOWED = 'http', 'https', 'mailto'
 
 
@@ -363,6 +362,7 @@
     def addRemoteComponentGroup(component_group_name):
         """Adds a new component group to the bug tracker"""
 
+    @export_read_operation()
     def getAllRemoteComponentGroups():
         """Return collection of all component groups for this bug tracker"""
 
@@ -513,17 +513,17 @@
     name = exported(
         Text(
             title=_('Name'),
-            constraint=name_validator,
-            description=_('The name of a software component'
-                          'in a remote bug tracker')))
+            description=_("The name of a software component "
+                          "as shown in Launchpad.  This is a sanitized "
+                          "form of the Remote Name.")))
 
-# XXX: Bug 644794 will implement this link
-#    distro_source_package = exported(
-#        Reference(
-#            title=_('Distribution Source Package'),
-#            schema=Interface,
-#            description=_('The distribution source package for this '
-#                          'component, if one has been defined.')))
+    distro_source_package = exported(
+        Reference(
+            Interface,
+            title=_("Distribution Source Package"),
+            description=_("The distribution source package object that should be "
+                    "linked to this component."),
+            required=False))
 
 
 class IBugTrackerComponentGroup(Interface):
@@ -538,7 +538,6 @@
     name = exported(
         Text(
             title=_('Name'),
-            constraint=name_validator,
             description=_('The name of the bug tracker product.')))
     components = exported(
         Reference(title=_('Components'), schema=IBugTrackerComponent))

=== modified file 'lib/lp/bugs/model/bugtracker.py'
--- lib/lp/bugs/model/bugtracker.py	2010-09-28 21:51:56 +0000
+++ lib/lp/bugs/model/bugtracker.py	2010-10-07 06:41:47 +0000
@@ -86,6 +86,10 @@
     IPersonSet,
     validate_public_person,
     )
+from lp.registry.interfaces.distributionsourcepackage import (
+    IDistributionSourcePackage,
+    )
+from lp.registry.model.sourcepackagename import SourcePackageName
 
 
 def normalise_leading_slashes(rest):
@@ -739,11 +743,34 @@
     is_visible = Bool(allow_none=False)
     is_custom = Bool(allow_none=False)
 
-    distro_source_package_id = Int('distro_source_package')
-    distro_source_package = Reference(
-        distro_source_package_id,
-        'DistributionSourcePackageInDatabase.id')
-
+    distribution_id = Int('distribution')
+    distribution = Reference(
+        distribution_id,
+        'Distribution.id')
+
+    source_package_name_id = Int('source_package_name')
+    source_package_name = Reference(
+        source_package_name_id,
+        'SourcePackageName.id')
+
+    def _getDistroSourcePackage(self):
+        """Retrieves the corresponding source package"""
+        if self.distribution is None or self.source_package_name is None:
+            return None
+        self.distribution.getSourcePackage(
+            self.source_package_name)
+
+    def _setDistroSourcePackage(self, distro_source_package):
+        """Links this component to its corresponding source package"""
+        if distro_source_package is None:
+            self.distribution = None
+            self.source_package_name = None
+        else:
+            self.distribution = distro_source_package.distribution
+            self.source_package_name = distro_source_package.source_package_name
+
+    distro_source_package = property(_getDistroSourcePackage,
+                                     _setDistroSourcePackage)
 
 class BugTrackerComponentGroup(Storm):
     """A collection of components in a remote bug tracker.

=== modified file 'lib/lp/bugs/tests/test_bugtracker_components.py'
--- lib/lp/bugs/tests/test_bugtracker_components.py	2010-09-28 21:27:22 +0000
+++ lib/lp/bugs/tests/test_bugtracker_components.py	2010-10-07 06:41:47 +0000
@@ -78,6 +78,17 @@
         self.assertTrue(comp_b is not None)
         self.assertTrue(comp_c is not None)
 
+    def test_link_distro_source_package(self):
+        """Check that a link can be set to a distro source package"""
+        component = self.factory.makeBugTrackerComponent(
+            u'example', self.comp_group)
+        package = self.factory.makeDistributionSourcePackage()
+        self.assertTrue(component.distro_source_package is None)
+
+        # Set the source package on the component
+        component.distro_source_package = package
+        self.assertTrue(component.distro_source_package is not None)
+
 
 class TestBugTrackerWithComponents(TestCaseWithFactory):