Merge lp:~cjwatson/launchpad/fix-bpph-binaryfileurls into lp:launchpad

Proposed by Colin Watson on 2015-05-14
Status: Merged
Merged at revision: 17503
Proposed branch: lp:~cjwatson/launchpad/fix-bpph-binaryfileurls
Merge into: lp:launchpad
Diff against target: 78 lines (+22/-7)
2 files modified
lib/lp/soyuz/model/publishing.py (+5/-6)
lib/lp/soyuz/tests/test_publishing_models.py (+17/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/fix-bpph-binaryfileurls
Reviewer Review Type Date Requested Status
William Grant code 2015-05-14 Approve on 2015-05-14
Review via email: mp+259112@code.launchpad.net

Commit Message

Make BPPH.binaryFileUrls return URLs even for files that have been removed from the published archive.

Description of the Change

Make BPPH.binaryFileUrls return URLs even for files that have been removed from the published archive.

BPPH.files only returns files that haven't been removed, because it goes through the BinaryPackageFilePublishing view.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/model/publishing.py'
2--- lib/lp/soyuz/model/publishing.py 2015-04-29 13:58:31 +0000
3+++ lib/lp/soyuz/model/publishing.py 2015-05-14 13:27:56 +0000
4@@ -75,7 +75,6 @@
5 )
6 from lp.services.worlddata.model.country import Country
7 from lp.soyuz.enums import (
8- ArchivePurpose,
9 BinaryPackageFormat,
10 PackagePublishingPriority,
11 PackagePublishingStatus,
12@@ -101,7 +100,6 @@
13 OverrideError,
14 PoolFileOverwriteError,
15 )
16-from lp.soyuz.interfaces.queue import QueueInconsistentStateError
17 from lp.soyuz.interfaces.section import ISectionSet
18 from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
19 from lp.soyuz.model.binarypackagename import BinaryPackageName
20@@ -1059,12 +1057,13 @@
21 def binaryFileUrls(self, include_meta=False):
22 """See `IBinaryPackagePublishingHistory`."""
23 binary_urls = proxied_urls(
24- [f.libraryfilealias for f in self.files], self.archive)
25+ [f.libraryfile for f in self.binarypackagerelease.files],
26+ self.archive)
27 if include_meta:
28 meta = [(
29- f.libraryfilealias.content.filesize,
30- f.libraryfilealias.content.sha1,
31- ) for f in self.files]
32+ f.libraryfile.content.filesize,
33+ f.libraryfile.content.sha1,
34+ ) for f in self.binarypackagerelease.files]
35 return [dict(url=url, size=size, sha1=sha1)
36 for url, (size, sha1) in zip(binary_urls, meta)]
37 return binary_urls
38
39=== modified file 'lib/lp/soyuz/tests/test_publishing_models.py'
40--- lib/lp/soyuz/tests/test_publishing_models.py 2015-04-08 10:35:22 +0000
41+++ lib/lp/soyuz/tests/test_publishing_models.py 2015-05-14 13:27:56 +0000
42@@ -1,12 +1,14 @@
43-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
44+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
45 # GNU Affero General Public License version 3 (see the file LICENSE).
46
47 """Test model and set utilities used for publishing."""
48
49 from zope.component import getUtility
50+from zope.security.proxy import removeSecurityProxy
51
52 from lp.app.errors import NotFoundError
53 from lp.buildmaster.enums import BuildStatus
54+from lp.services.database.constants import UTC_NOW
55 from lp.services.librarian.browser import ProxiedLibraryFileAlias
56 from lp.services.webapp.publisher import canonical_url
57 from lp.soyuz.enums import (
58@@ -212,6 +214,20 @@
59 self.assertContentEqual(
60 self.get_urls_for_bpph(bpph, include_meta=True), urls)
61
62+ def test_binaryFileUrls_removed(self):
63+ # binaryFileUrls returns URLs even if the files have been removed
64+ # from the published archive.
65+ bpph = self.make_bpph(num_binaries=2)
66+ expected_urls = self.get_urls_for_bpph(bpph)
67+ expected_urls_meta = self.get_urls_for_bpph(bpph, include_meta=True)
68+ self.assertContentEqual(expected_urls, bpph.binaryFileUrls())
69+ self.assertContentEqual(
70+ expected_urls_meta, bpph.binaryFileUrls(include_meta=True))
71+ removeSecurityProxy(bpph).dateremoved = UTC_NOW
72+ self.assertContentEqual(expected_urls, bpph.binaryFileUrls())
73+ self.assertContentEqual(
74+ expected_urls_meta, bpph.binaryFileUrls(include_meta=True))
75+
76 def test_is_debug_false_for_deb(self):
77 bpph = self.factory.makeBinaryPackagePublishingHistory(
78 binpackageformat=BinaryPackageFormat.DEB)