launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #05873
[Merge] lp:~james-w/launchpad/binaries-created-since into lp:launchpad
James Westby has proposed merging lp:~james-w/launchpad/binaries-created-since into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~james-w/launchpad/binaries-created-since/+merge/85022
Hi,
This change adds created_since_date to getPublishedBinaries on
the webservice, to parallel the same option for getPublishedSources.
We need this to keep up to date without having to query every package
in Ubuntu on every run.
Thanks,
James
--
https://code.launchpad.net/~james-w/launchpad/binaries-created-since/+merge/85022
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~james-w/launchpad/binaries-created-since into lp:launchpad.
=== modified file 'lib/lp/soyuz/browser/tests/test_archive_webservice.py'
--- lib/lp/soyuz/browser/tests/test_archive_webservice.py 2011-12-05 16:01:37 +0000
+++ lib/lp/soyuz/browser/tests/test_archive_webservice.py 2011-12-08 20:14:26 +0000
@@ -3,6 +3,8 @@
__metaclass__ = type
+from datetime import timedelta
+
from lazr.restfulclient.errors import (
BadRequest,
NotFound,
@@ -377,3 +379,28 @@
job_source = getUtility(IPlainPackageCopyJobSource)
copy_job = job_source.getActiveJobs(target_archive).one()
self.assertEqual(target_archive, copy_job.target_archive)
+
+
+class TestgetPublishedBinaries(WebServiceTestCase):
+ """test getPublishedSources."""
+
+ def test_getPublishedBinaries(self):
+ self.ws_version = 'beta'
+ person = self.factory.makePerson()
+ archive = self.factory.makeArchive()
+ publishing = self.factory.makeBinaryPackagePublishingHistory(
+ archive=archive)
+ ws_archive = self.wsObject(archive, user=person)
+ self.assertEqual(1, len(ws_archive.getPublishedBinaries()))
+
+ def test_getPublishedBinaries_created_since_date(self):
+ self.ws_version = 'beta'
+ person = self.factory.makePerson()
+ archive = self.factory.makeArchive()
+ datecreated = self.factory.getUniqueDate()
+ later_date = datecreated + timedelta(minutes=1)
+ publishing = self.factory.makeBinaryPackagePublishingHistory(
+ archive=archive, datecreated=datecreated)
+ ws_archive = self.wsObject(archive, user=person)
+ publications = ws_archive.getPublishedBinaries(created_since_date=later_date)
+ self.assertEqual(0, len(publications))
=== modified file 'lib/lp/soyuz/interfaces/archive.py'
--- lib/lp/soyuz/interfaces/archive.py 2011-12-05 16:01:37 +0000
+++ lib/lp/soyuz/interfaces/archive.py 2011-12-08 20:14:26 +0000
@@ -1004,6 +1004,11 @@
# Really PackagePublishingPocket, circular import fixed below.
vocabulary=DBEnumeratedType,
required=False, readonly=True),
+ created_since_date=Datetime(
+ title=_("Created Since Date"),
+ description=_("Return entries whose `date_created` is greater "
+ "than or equal to this date."),
+ required=False),
exact_match=Bool(
description=_("Whether or not to filter binary names by exact "
"matching."),
@@ -1015,7 +1020,7 @@
@export_read_operation()
def getAllPublishedBinaries(name=None, version=None, status=None,
distroarchseries=None, pocket=None,
- exact_match=False):
+ exact_match=False, created_since_date=None):
"""All `IBinaryPackagePublishingHistory` target to this archive.
:param: name: binary name filter (exact match or SQL LIKE controlled
@@ -1026,6 +1031,8 @@
:param: pocket: `PackagePublishingPocket` filter.
:param: exact_match: either or not filter source names by exact
matching.
+ :param: created_since_date: a filter on teh `date_created` of the
+ publishing record.
:return: A collection containing `BinaryPackagePublishingHistory`.
"""
=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py 2011-12-02 15:07:54 +0000
+++ lib/lp/soyuz/model/archive.py 2011-12-08 20:14:26 +0000
@@ -714,7 +714,7 @@
def _getBinaryPublishingBaseClauses(
self, name=None, version=None, status=None, distroarchseries=None,
- pocket=None, exact_match=False):
+ pocket=None, exact_match=False, created_since_date=None):
"""Base clauses and clauseTables for binary publishing queries.
Returns a list of 'clauses' (to be joined in the callsite) and
@@ -781,15 +781,21 @@
BinaryPackagePublishingHistory.pocket = %s
""" % sqlvalues(pocket))
+ if created_since_date is not None:
+ clauses.append(
+ "BinaryPackagePublishingHistory.datecreated >= %s"
+ % sqlvalues(created_since_date))
+
return clauses, clauseTables, orderBy
def getAllPublishedBinaries(self, name=None, version=None, status=None,
distroarchseries=None, pocket=None,
- exact_match=False):
+ exact_match=False, created_since_date=None):
"""See `IArchive`."""
clauses, clauseTables, orderBy = self._getBinaryPublishingBaseClauses(
name=name, version=version, status=status, pocket=pocket,
- distroarchseries=distroarchseries, exact_match=exact_match)
+ distroarchseries=distroarchseries, exact_match=exact_match,
+ created_since_date=created_since_date)
all_binaries = BinaryPackagePublishingHistory.select(
' AND '.join(clauses), clauseTables=clauseTables,
@@ -799,11 +805,12 @@
def getPublishedOnDiskBinaries(self, name=None, version=None, status=None,
distroarchseries=None, pocket=None,
- exact_match=False):
+ exact_match=False, created_since_date=None):
"""See `IArchive`."""
clauses, clauseTables, orderBy = self._getBinaryPublishingBaseClauses(
name=name, version=version, status=status, pocket=pocket,
- distroarchseries=distroarchseries, exact_match=exact_match)
+ distroarchseries=distroarchseries, exact_match=exact_match,
+ created_since_date=created_since_date)
clauses.append("""
BinaryPackagePublishingHistory.distroarchseries =
=== modified file 'lib/lp/soyuz/tests/test_archive.py'
--- lib/lp/soyuz/tests/test_archive.py 2011-12-02 15:07:54 +0000
+++ lib/lp/soyuz/tests/test_archive.py 2011-12-08 20:14:26 +0000
@@ -2303,6 +2303,51 @@
person=person)
+class TestgetAllPublishedBinaries(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_returns_publication(self):
+ archive = self.factory.makeArchive()
+ publication = self.factory.makeBinaryPackagePublishingHistory(
+ archive=archive)
+ publications = archive.getAllPublishedBinaries()
+ self.assertEqual(1, publications.count())
+ self.assertEqual(publication, publications[0])
+
+ def test_created_since_date_newer(self):
+ archive = self.factory.makeArchive()
+ datecreated = self.factory.getUniqueDate()
+ self.factory.makeBinaryPackagePublishingHistory(
+ archive=archive, datecreated=datecreated)
+ later_date = datecreated + timedelta(minutes=1)
+ publications = archive.getAllPublishedBinaries(created_since_date=later_date)
+ self.assertEqual(0, publications.count())
+
+ def test_created_since_date_older(self):
+ archive = self.factory.makeArchive()
+ datecreated = self.factory.getUniqueDate()
+ publication = self.factory.makeBinaryPackagePublishingHistory(
+ archive=archive, datecreated=datecreated)
+ earlier_date = datecreated - timedelta(minutes=1)
+ publications = archive.getAllPublishedBinaries(created_since_date=earlier_date)
+ self.assertEqual(1, publications.count())
+ self.assertEqual(publication, publications[0])
+
+ def test_created_since_date_middle(self):
+ archive = self.factory.makeArchive()
+ datecreated = self.factory.getUniqueDate()
+ publication1 = self.factory.makeBinaryPackagePublishingHistory(
+ archive=archive, datecreated=datecreated)
+ middle_date = datecreated + timedelta(minutes=1)
+ later_date = middle_date + timedelta(minutes=1)
+ publication2 = self.factory.makeBinaryPackagePublishingHistory(
+ archive=archive, datecreated=later_date)
+ publications = archive.getAllPublishedBinaries(created_since_date=middle_date)
+ self.assertEqual(1, publications.count())
+ self.assertEqual(publication2, publications[0])
+
+
class TestRemovingPermissions(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2011-11-29 16:48:56 +0000
+++ lib/lp/testing/factory.py 2011-12-08 20:14:26 +0000
@@ -3837,6 +3837,7 @@
priority=None, status=None,
scheduleddeletiondate=None,
dateremoved=None,
+ datecreated=None,
pocket=None, archive=None,
source_package_release=None,
sourcepackagename=None):
@@ -3878,6 +3879,9 @@
section_name=section_name,
priority=priority)
+ if datecreated is None:
+ datecreated = self.getUniqueDate()
+
bpph = getUtility(IPublishingSet).newBinaryPublication(
archive, binarypackagerelease, distroarchseries,
binarypackagerelease.component, binarypackagerelease.section,
@@ -3885,6 +3889,7 @@
naked_bpph = removeSecurityProxy(bpph)
naked_bpph.status = status
naked_bpph.dateremoved = dateremoved
+ naked_bpph.datecreated = datecreated
naked_bpph.scheduleddeletiondate = scheduleddeletiondate
naked_bpph.priority = priority
if status == PackagePublishingStatus.PUBLISHED:
Follow ups