Merge lp:~wgrant/launchpad/bug-522800-getFileByName into lp:launchpad

Proposed by William Grant on 2010-12-09
Status: Merged
Approved by: Julian Edwards on 2010-12-09
Approved revision: no longer in the source branch.
Merged at revision: 12043
Proposed branch: lp:~wgrant/launchpad/bug-522800-getFileByName
Merge into: lp:launchpad
Diff against target: 332 lines (+113/-140)
5 files modified
lib/lp/soyuz/doc/build-files.txt (+7/-136)
lib/lp/soyuz/model/archive.py (+1/-0)
lib/lp/soyuz/stories/ppa/xx-ppa-files.txt (+2/-2)
lib/lp/soyuz/tests/test_archive.py (+100/-0)
lib/lp/testing/factory.py (+3/-2)
To merge this branch: bzr merge lp:~wgrant/launchpad/bug-522800-getFileByName
Reviewer Review Type Date Requested Status
Julian Edwards (community) 2010-12-09 Approve on 2010-12-10
Review via email: mp+43159@code.launchpad.net

Commit Message

Archive.getFileByName now returns only unexpired files.

Description of the Change

Archive.getFileByName currently doesn't care if the file it returns is expired. That isn't excellent, since an expired file is just about useless. This branch fixes it to only return unexpired files, fixing bug #522800. It also happens to fix bug #687662, a 10.12 regression that was just discovered.

To post a comment you must log in.
Julian Edwards (julian-edwards) wrote :

Turn the doctest change into a unit test and r=me

review: Approve
Julian Edwards (julian-edwards) wrote :

Looks good, I shall land it.

Julian Edwards (julian-edwards) wrote :

Except - there's a failing test!
Please fix xx-ppa-files.txt

kthxbye

review: Needs Fixing
William Grant (wgrant) wrote :

The test is fixed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'lib/lp/soyuz/doc/archive-files.txt' => 'lib/lp/soyuz/doc/build-files.txt'
2--- lib/lp/soyuz/doc/archive-files.txt 2010-10-18 22:24:59 +0000
3+++ lib/lp/soyuz/doc/build-files.txt 2010-12-10 00:12:15 +0000
4@@ -1,157 +1,28 @@
5-= Archive files =
6+= Build files =
7
8-`IArchive` provides a method that looks up files involved in the context
9-archive, getFileByName()
10+Create a test build.
11
12 >>> from lp.registry.interfaces.person import IPersonSet
13- >>> cprov = getUtility(IPersonSet).getByName('cprov')
14-
15-The given filename is looked up in the context corresponding to its
16-extension:
17-
18- * Source files: '.orig.tar.gz', 'tar.gz', '.diff.gz' and '.dsc';
19- * Binary files: '.deb' and '.udeb';
20- * Source changesfile: '_source.changes';
21- * Package diffs: '.diff.gz';
22-
23-Any other extension will result in a `NotFoundError`.
24-
25- >>> cprov.archive.getFileByName('biscuit.cookie')
26- Traceback (most recent call last):
27- ...
28- NotFoundError: 'biscuit.cookie'
29-
30-Create a test source publication.
31-
32 >>> from lp.soyuz.tests.test_publishing import (
33 ... SoyuzTestPublisher)
34
35 >>> login('foo.bar@canonical.com')
36
37+ >>> cprov = getUtility(IPersonSet).getByName('cprov')
38 >>> test_publisher = SoyuzTestPublisher()
39 >>> test_publisher.prepareBreezyAutotest()
40 >>> test_publisher.addFakeChroots()
41 >>> test_source = test_publisher.getPubSource(
42 ... archive=cprov.archive, sourcename='test-pkg',
43 ... version='1.0')
44-
45-When the file exists, the corresponding `ILibraryFileAlias` is returned.
46-
47- >>> from canonical.launchpad.interfaces.librarian import ILibraryFileAlias
48- >>> from canonical.launchpad.webapp.testing import verifyObject
49-
50- >>> result = cprov.archive.getFileByName('test-pkg_1.0.dsc')
51-
52- >>> verifyObject(ILibraryFileAlias, result)
53- True
54-
55-Otherwise a `NotFoundError` is raised.
56-
57- >>> cprov.archive.getFileByName('test-pkg_1.0.orig.tar.gz')
58- Traceback (most recent call last):
59- ...
60- NotFoundError: 'test-pkg_1.0.orig.tar.gz'
61-
62-Adding an original source tarball.
63-
64- >>> lost_orig_tar_gz = test_publisher.addMockFile(
65- ... 'test-pkg_1.0.orig.tar.gz')
66-
67-NotFoundError still being raised if the file exists but is not
68-attached to the IArchive context.
69-
70- >>> cprov.archive.getFileByName('test-pkg_1.0.orig.tar.gz')
71- Traceback (most recent call last):
72- ...
73- NotFoundError: 'test-pkg_1.0.orig.tar.gz'
74-
75-Attached a new file to Celso's PPA context.
76-
77- >>> orig_tar_gz = test_publisher.addMockFile(
78- ... 'test-pkg_1.0.orig.tar.gz')
79- >>> unused = test_source.sourcepackagerelease.addFile(orig_tar_gz)
80-
81-The retrieved file is the one attached to Celso's PPA and not the old
82-one.
83-
84- >>> libraryfile = cprov.archive.getFileByName('test-pkg_1.0.orig.tar.gz')
85-
86- >>> libraryfile == lost_orig_tar_gz
87- False
88-
89- >>> libraryfile == orig_tar_gz
90- True
91-
92-Adding and retrieving a source diff.
93-
94- >>> diff_gz = test_publisher.addMockFile('test-pkg_1.0.diff.gz')
95- >>> unused = test_source.sourcepackagerelease.addFile(diff_gz)
96-
97- >>> cprov.archive.getFileByName('test-pkg_1.0.diff.gz') == diff_gz
98- True
99-
100-Adding and retrieving a binary 'deb'.
101-
102 >>> binary_pubs = test_publisher.getPubBinaries(
103 ... binaryname='test', pub_source=test_source)
104 >>> deb = binary_pubs[0].binarypackagerelease.files[0].libraryfile
105-
106- >>> deb == cprov.archive.getFileByName('test_1.0_all.deb')
107- True
108-
109-Adding and retrieving a binary 'udeb'.
110-
111 >>> [build] = test_source.getBuilds()
112- >>> binary = test_publisher.uploadBinaryForBuild(
113- ... build, binaryname='micro-test')
114- >>> unused = test_publisher.publishBinaryInArchive(binary, cprov.archive)
115-
116- >>> from zope.security.proxy import removeSecurityProxy
117- >>> bin_file = removeSecurityProxy(binary.files[0].libraryfile)
118- >>> bin_file.filename = 'micro-test_1.0_all.udeb'
119-
120- >>> bin_file == cprov.archive.getFileByName('micro-test_1.0_all.udeb')
121- True
122-
123-Adding and retrieving a source changesfile.
124-
125- >>> from lp.registry.interfaces.pocket import (
126- ... PackagePublishingPocket)
127- >>> source_upload = test_source.distroseries.createQueueEntry(
128- ... pocket=PackagePublishingPocket.RELEASE,
129- ... changesfilename='test-pkg_1.0_source.changes',
130- ... changesfilecontent='Bogus',
131- ... archive=cprov.archive)
132- >>> unused = source_upload.addSource(test_source.sourcepackagerelease)
133- >>> source_upload.setDone()
134-
135- >>> cprov.archive.getFileByName('test-pkg_1.0_source.changes')
136- <LibraryFileAlias ...>
137-
138-Adding and retrieving a package-diff.
139-
140- >>> another_test_source = test_publisher.getPubSource(
141- ... archive=cprov.archive, sourcename='test-pkg',
142- ... version='1.1')
143-
144- >>> print another_test_source.sourcepackagerelease.package_diffs.count()
145- 0
146-
147- >>> package_diff = test_source.sourcepackagerelease.requestDiffTo(
148- ... cprov, another_test_source.sourcepackagerelease)
149-
150- >>> print another_test_source.sourcepackagerelease.package_diffs.count()
151- 1
152-
153- >>> diff_name = 'test-pkg_1.0_1.1.diff.gz'
154- >>> diff = test_publisher.addMockFile(diff_name)
155- >>> package_diff.diff_content = diff
156-
157- >>> diff == cprov.archive.getFileByName(diff_name)
158- True
159-
160-Similarly, IBuild provide a getFileByName() method, which retuns one
161-of the following file type in its context.
162+
163+
164+IBuild provide a getFileByName() method, which retuns one of the
165+following file type in its context.
166
167 * Binary changesfile: '.changes';
168 * Build logs: '.txt.gz';
169
170=== modified file 'lib/lp/soyuz/model/archive.py'
171--- lib/lp/soyuz/model/archive.py 2010-12-03 17:35:33 +0000
172+++ lib/lp/soyuz/model/archive.py 2010-12-10 00:12:15 +0000
173@@ -1311,6 +1311,7 @@
174
175 base_clauses = (
176 LibraryFileAlias.filename == filename,
177+ LibraryFileAlias.content != None,
178 )
179
180 if re_issource.match(filename):
181
182=== modified file 'lib/lp/soyuz/stories/ppa/xx-ppa-files.txt'
183--- lib/lp/soyuz/stories/ppa/xx-ppa-files.txt 2010-11-06 12:50:22 +0000
184+++ lib/lp/soyuz/stories/ppa/xx-ppa-files.txt 2010-12-10 00:12:15 +0000
185@@ -465,7 +465,7 @@
186 ...
187 Include the error ID OOPS-...
188 ...
189- DeletedProxiedLibraryFileAlias:
190- Object: u'test-pkg_1.0.dsc', name: &lt;Archive at
191+ NotFound:
192+ Object: &lt;Archive at ...&gt;, name: u'test-pkg_1.0.dsc'...
193 ...
194
195
196=== modified file 'lib/lp/soyuz/tests/test_archive.py'
197--- lib/lp/soyuz/tests/test_archive.py 2010-12-03 17:35:33 +0000
198+++ lib/lp/soyuz/tests/test_archive.py 2010-12-10 00:12:15 +0000
199@@ -21,6 +21,7 @@
200 DatabaseFunctionalLayer,
201 LaunchpadZopelessLayer,
202 )
203+from lp.app.errors import NotFoundError
204 from lp.buildmaster.enums import BuildStatus
205 from lp.registry.interfaces.pocket import PackagePublishingPocket
206 from lp.registry.interfaces.series import SeriesStatus
207@@ -1505,3 +1506,102 @@
208 archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
209 self.assertEqual(
210 [PackagePublishingPocket.RELEASE], archive.getPockets())
211+
212+
213+class TestGetFileByName(TestCaseWithFactory):
214+ """Tests for Archive.getFileByName."""
215+
216+ layer = LaunchpadZopelessLayer
217+
218+ def setUp(self):
219+ super(TestGetFileByName, self).setUp()
220+ self.archive = self.factory.makeArchive()
221+
222+ def test_unknown_file_is_not_found(self):
223+ # A file with an unsupported extension is not found.
224+ self.assertRaises(NotFoundError, self.archive.getFileByName, 'a.bar')
225+
226+ def test_source_file_is_found(self):
227+ # A file from a published source package can be retrieved.
228+ pub = self.factory.makeSourcePackagePublishingHistory(
229+ archive=self.archive)
230+ dsc = self.factory.makeLibraryFileAlias(filename='foo_1.0.dsc')
231+ self.assertRaises(
232+ NotFoundError, self.archive.getFileByName, dsc.filename)
233+ pub.sourcepackagerelease.addFile(dsc)
234+ self.assertEquals(dsc, self.archive.getFileByName(dsc.filename))
235+
236+ def test_nonexistent_source_file_is_not_found(self):
237+ # Something that looks like a source file but isn't is not
238+ # found.
239+ self.assertRaises(
240+ NotFoundError, self.archive.getFileByName, 'foo_1.0.dsc')
241+
242+ def test_binary_file_is_found(self):
243+ # A file from a published binary package can be retrieved.
244+ pub = self.factory.makeBinaryPackagePublishingHistory(
245+ archive=self.archive)
246+ deb = self.factory.makeLibraryFileAlias(filename='foo_1.0_all.deb')
247+ self.assertRaises(
248+ NotFoundError, self.archive.getFileByName, deb.filename)
249+ pub.binarypackagerelease.addFile(deb)
250+ self.assertEquals(deb, self.archive.getFileByName(deb.filename))
251+
252+ def test_nonexistent_binary_file_is_not_found(self):
253+ # Something that looks like a binary file but isn't is not
254+ # found.
255+ self.assertRaises(
256+ NotFoundError, self.archive.getFileByName, 'foo_1.0_all.deb')
257+
258+ def test_source_changes_file_is_found(self):
259+ # A .changes file from a published source can be retrieved.
260+ pub = self.factory.makeSourcePackagePublishingHistory(
261+ archive=self.archive)
262+ pu = self.factory.makePackageUpload(
263+ changes_filename='foo_1.0_source.changes')
264+ pu.setDone()
265+ self.assertRaises(
266+ NotFoundError, self.archive.getFileByName,
267+ pu.changesfile.filename)
268+ pu.addSource(pub.sourcepackagerelease)
269+ self.assertEquals(
270+ pu.changesfile,
271+ self.archive.getFileByName(pu.changesfile.filename))
272+
273+ def test_nonexistent_source_changes_file_is_not_found(self):
274+ # Something that looks like a source .changes file but isn't is not
275+ # found.
276+ self.assertRaises(
277+ NotFoundError, self.archive.getFileByName,
278+ 'foo_1.0_source.changes')
279+
280+ def test_package_diff_is_found(self):
281+ # A .diff.gz from a package diff can be retrieved.
282+ pub = self.factory.makeSourcePackagePublishingHistory(
283+ archive=self.archive)
284+ diff = self.factory.makePackageDiff(
285+ to_source=pub.sourcepackagerelease,
286+ diff_filename='foo_1.0.diff.gz')
287+ self.assertEquals(
288+ diff.diff_content,
289+ self.archive.getFileByName(diff.diff_content.filename))
290+
291+ def test_expired_files_are_skipped(self):
292+ # Expired files are ignored.
293+ pub = self.factory.makeSourcePackagePublishingHistory(
294+ archive=self.archive)
295+ dsc = self.factory.makeLibraryFileAlias(filename='foo_1.0.dsc')
296+ pub.sourcepackagerelease.addFile(dsc)
297+
298+ # The file is initially found without trouble.
299+ self.assertEquals(dsc, self.archive.getFileByName(dsc.filename))
300+
301+ # But after expiry it is not.
302+ removeSecurityProxy(dsc).content = None
303+ self.assertRaises(
304+ NotFoundError, self.archive.getFileByName, dsc.filename)
305+
306+ # It reappears if we create a new one.
307+ new_dsc = self.factory.makeLibraryFileAlias(filename=dsc.filename)
308+ pub.sourcepackagerelease.addFile(new_dsc)
309+ self.assertEquals(new_dsc, self.archive.getFileByName(dsc.filename))
310
311=== modified file 'lib/lp/testing/factory.py'
312--- lib/lp/testing/factory.py 2010-12-08 19:03:17 +0000
313+++ lib/lp/testing/factory.py 2010-12-10 00:12:15 +0000
314@@ -3270,7 +3270,7 @@
315
316 def makePackageDiff(self, from_source=None, to_source=None,
317 requester=None, status=None, date_fulfilled=None,
318- diff_content=None):
319+ diff_content=None, diff_filename=None):
320 """Create a new `PackageDiff`."""
321 if from_source is None:
322 from_source = self.makeSourcePackageRelease()
323@@ -3284,7 +3284,8 @@
324 date_fulfilled = UTC_NOW
325 if diff_content is None:
326 diff_content = self.getUniqueString("packagediff")
327- lfa = self.makeLibraryFileAlias(content=diff_content)
328+ lfa = self.makeLibraryFileAlias(
329+ filename=diff_filename, content=diff_content)
330 return ProxyFactory(
331 PackageDiff(
332 requester=requester, from_source=from_source,