← Back to team overview

launchpad-reviewers team mailing list archive

lp:~julian-edwards/launchpad/getPublishedSources-pocket-filtering into lp:launchpad

 

Julian Edwards has proposed merging lp:~julian-edwards/launchpad/getPublishedSources-pocket-filtering into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~julian-edwards/launchpad/getPublishedSources-pocket-filtering/+merge/68825

Super simple change to make the "pocket" argument of IArchive.getPublishedSources also work with an iterable so that the query generate will use an "IN" instead of equality with a single item.
-- 
https://code.launchpad.net/~julian-edwards/launchpad/getPublishedSources-pocket-filtering/+merge/68825
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/launchpad/getPublishedSources-pocket-filtering into lp:launchpad.
=== modified file 'lib/lp/soyuz/interfaces/archive.py'
--- lib/lp/soyuz/interfaces/archive.py	2011-07-18 12:11:04 +0000
+++ lib/lp/soyuz/interfaces/archive.py	2011-07-22 11:41:28 +0000
@@ -1008,7 +1008,8 @@
         :param version: source version filter (always exact match).
         :param status: `PackagePublishingStatus` filter, can be a sequence.
         :param distroseries: `IDistroSeries` filter.
-        :param pocket: `PackagePublishingPocket` filter.
+        :param pocket: `PackagePublishingPocket` filter.  This may be an
+            iterable of more than one pocket or a single pocket.
         :param exact_match: either or not filter source names by exact
                              matching.
         :param created_since_date: Only return results whose `date_created`

=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py	2011-07-21 15:00:54 +0000
+++ lib/lp/soyuz/model/archive.py	2011-07-22 11:41:28 +0000
@@ -554,8 +554,14 @@
                     distroseries.id)
 
         if pocket is not None:
-            storm_clauses.append(
-                SourcePackagePublishingHistory.pocket == pocket)
+            try:
+                pockets = tuple(pocket)
+                storm_clauses.append(
+                    "SourcePackagePublishingHistory.pocket IN %s " %
+                       sqlvalues(pockets))
+            except TypeError:
+                storm_clauses.append(
+                    SourcePackagePublishingHistory.pocket == pocket)
 
         if created_since_date is not None:
             clauses.append(

=== modified file 'lib/lp/soyuz/tests/test_archive.py'
--- lib/lp/soyuz/tests/test_archive.py	2011-07-22 08:53:53 +0000
+++ lib/lp/soyuz/tests/test_archive.py	2011-07-22 11:41:28 +0000
@@ -1939,6 +1939,27 @@
             [filtered_source.sourcepackagerelease.name for filtered_source in
             filtered_sources])
 
+    def test_getPublishedSources_multi_pockets(self):
+        # Passing an iterable of pockets should return publications
+        # with any of them in.
+        distroseries =  self.factory.makeDistroSeries()
+        for pocket in [
+            PackagePublishingPocket.RELEASE, PackagePublishingPocket.UPDATES,
+            PackagePublishingPocket.BACKPORTS]:
+            self.factory.makeSourcePackagePublishingHistory(
+                sourcepackagename=pocket.name.lower(),
+                distroseries=distroseries,
+                archive=distroseries.main_archive,
+                pocket=pocket)
+        filtered = distroseries.main_archive.getPublishedSources(
+            pocket=[
+                PackagePublishingPocket.RELEASE,
+                PackagePublishingPocket.UPDATES])
+
+        self.assertContentEqual(
+            [PackagePublishingPocket.RELEASE, PackagePublishingPocket.UPDATES],
+            [source.pocket for source in filtered])
+
 
 class TestSyncSourceFeatureFlag(TestCaseWithFactory):