← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~jugmac00/launchpad:archive.getPublishedBinaries-should-accept-component-name into launchpad:master

 

jugmac00 has proposed merging ~jugmac00/launchpad:archive.getPublishedBinaries-should-accept-component-name into launchpad:master.

Commit message:
Add component_name filter to getPublishedBinaries

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jugmac00/launchpad/+git/launchpad/+merge/410072
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/launchpad:archive.getPublishedBinaries-should-accept-component-name into launchpad:master.
diff --git a/lib/lp/soyuz/browser/tests/test_archive_webservice.py b/lib/lp/soyuz/browser/tests/test_archive_webservice.py
index f9e675b..0c06199 100644
--- a/lib/lp/soyuz/browser/tests/test_archive_webservice.py
+++ b/lib/lp/soyuz/browser/tests/test_archive_webservice.py
@@ -788,6 +788,32 @@ class TestGetPublishedBinaries(TestCaseWithFactory):
         self.assertThat(
             recorder2, HasQueryCount(Equals(recorder1.count + 3), recorder1))
 
+    def test_getPublishedBinaries_filter_by_component(self):
+        self.factory.makeBinaryPackagePublishingHistory(
+            archive=self.archive, component="main"
+            )
+        ws = webservice_for_person(self.person, default_api_version="devel")
+
+        response = ws.named_get(
+            self.archive_url, "getPublishedBinaries",
+            component_name="main"
+        )
+
+        self.assertEqual(200, response.status)
+        self.assertEqual(1, response.jsonBody()["total_size"])
+
+        # make sure there are only results form the `main` component
+        for entry in response.jsonBody()["entries"]:
+            self.assertEqual("main", entry["component_name"])
+
+        # make sure there are no results for component `universe`
+        response = ws.named_get(
+            self.archive_url, "getPublishedBinaries",
+            component_name="restricted")
+
+        self.assertEqual(200, response.status)
+        self.assertEqual(0, response.jsonBody()["total_size"])
+
 
 class TestRemoveCopyNotification(TestCaseWithFactory):
     """Test removeCopyNotification."""
diff --git a/lib/lp/soyuz/interfaces/archive.py b/lib/lp/soyuz/interfaces/archive.py
index 84d6932..f8f18f6 100644
--- a/lib/lp/soyuz/interfaces/archive.py
+++ b/lib/lp/soyuz/interfaces/archive.py
@@ -628,7 +628,8 @@ class IArchiveSubscriberView(Interface):
                           "for applications that need to catch up with "
                           "publications since their last run."),
             required=False),
-        )
+        component_name=TextLine(title=_("Component name"), required=False),
+    )
     # Really returns IBinaryPackagePublishingHistory, see below for
     # patch to avoid circular import.
     @operation_returns_collection_of(Interface)
@@ -639,7 +640,7 @@ class IArchiveSubscriberView(Interface):
                                 exact_match=False, created_since_date=None,
                                 ordered=True, order_by_date=False,
                                 include_removed=True, only_unpublished=False,
-                                eager_load=False):
+                                eager_load=False, component_name=None):
         """All `IBinaryPackagePublishingHistory` target to this archive.
 
         :param name: binary name filter (exact match or SQL LIKE controlled
@@ -664,6 +665,8 @@ class IArchiveSubscriberView(Interface):
             removed from disk as well as those that have not.
         :param only_unpublished: If True, only include publications that
             have never been published to disk.
+        :param component_name: component filter. Only return binaries that are
+            in this component.
 
         :return: A collection containing `BinaryPackagePublishingHistory`.
         """
diff --git a/lib/lp/soyuz/model/archive.py b/lib/lp/soyuz/model/archive.py
index 0feb787..4ae8006 100644
--- a/lib/lp/soyuz/model/archive.py
+++ b/lib/lp/soyuz/model/archive.py
@@ -790,7 +790,7 @@ class Archive(SQLBase):
         self, name=None, version=None, status=None, distroarchseries=None,
         pocket=None, exact_match=False, created_since_date=None,
         ordered=True, order_by_date=False, include_removed=True,
-        only_unpublished=False, need_bpr=False):
+        only_unpublished=False, need_bpr=False, component_name=None):
         """Base clauses for binary publishing queries.
 
         Returns a list of 'clauses' (to be joined in the callsite).
@@ -873,6 +873,14 @@ class Archive(SQLBase):
             clauses.append(
                 BinaryPackagePublishingHistory.datepublished == None)
 
+        if component_name is not None:
+            clauses.extend(
+                [BinaryPackagePublishingHistory.componentID == Component.id,
+                 Component.name == component_name,
+                 ]
+            )
+
+
         return clauses, order_by
 
     def getAllPublishedBinaries(self, name=None, version=None, status=None,
@@ -880,18 +888,17 @@ class Archive(SQLBase):
                                 exact_match=False, created_since_date=None,
                                 ordered=True, order_by_date=False,
                                 include_removed=True, only_unpublished=False,
-                                eager_load=False):
+                                eager_load=False, component_name=None):
         """See `IArchive`."""
         # Circular imports.
         from lp.registry.model.distroseries import DistroSeries
         from lp.soyuz.model.distroarchseries import DistroArchSeries
-
         clauses, order_by = self._getBinaryPublishingBaseClauses(
             name=name, version=version, status=status, pocket=pocket,
             distroarchseries=distroarchseries, exact_match=exact_match,
             created_since_date=created_since_date, ordered=ordered,
             order_by_date=order_by_date, include_removed=include_removed,
-            only_unpublished=only_unpublished)
+            only_unpublished=only_unpublished, component_name=component_name)
 
         result = Store.of(self).find(
             BinaryPackagePublishingHistory, *clauses).order_by(*order_by)