Merge lp:~cjwatson/launchpad/queue-api-custom-files into lp:launchpad

Proposed by Colin Watson
Status: Merged
Approved by: j.c.sackett
Approved revision: no longer in the source branch.
Merged at revision: 15571
Proposed branch: lp:~cjwatson/launchpad/queue-api-custom-files
Merge into: lp:launchpad
Diff against target: 111 lines (+57/-14)
2 files modified
lib/lp/soyuz/model/queue.py (+7/-1)
lib/lp/soyuz/tests/test_packageupload.py (+50/-13)
To merge this branch: bzr merge lp:~cjwatson/launchpad/queue-api-custom-files
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+113574@code.launchpad.net

Commit message

Add details of custom uploads to PackageUpload.getBinaryProperties.

Description of the change

== Summary ==

Fix a slight flaw in https://code.launchpad.net/~cjwatson/launchpad/queue-api-readonly/+merge/113202; there's no sensible way to get details of custom uploads.

== Proposed fix ==

I considered changing customFileUrls to customFiles and adding metadata there, but on reflection that is not ideal because the queue API client would have to add a call to customFiles for every build upload in the queue. A lighter-weight approach is to add custom file properties to getBinaryProperties (the separation between binaries and custom files is in some ways a bit artificial anyway), so the client just gets back a dict with some different keys.

Since there are no production clients for this yet, this slight interface change should be fine.

== LOC Rationale ==

+43, but I'm still comfortably within the limit for this whole arc of work as described in https://code.launchpad.net/~cjwatson/launchpad/queue-api/+merge/108967.

== Tests ==

bin/test -vvct TestPackageUploadWebservice

== Demo and Q/A ==

As with https://code.launchpad.net/~cjwatson/launchpad/queue-api-readonly/+merge/113202; just make sure it looks sensible for builds with custom uploads attached.

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

This looks good, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/model/queue.py'
2--- lib/lp/soyuz/model/queue.py 2012-07-04 13:02:32 +0000
3+++ lib/lp/soyuz/model/queue.py 2012-07-05 13:10:27 +0000
4@@ -320,8 +320,14 @@
5
6 def getBinaryProperties(self):
7 """See `IPackageUpload`."""
8- return list(chain.from_iterable(
9+ properties = list(chain.from_iterable(
10 build.binaries for build in self.builds))
11+ for file in self.customfiles:
12+ properties.append({
13+ "name": file.libraryfilealias.filename,
14+ "customformat": file.customformat.title,
15+ })
16+ return properties
17
18 def setNew(self):
19 """See `IPackageUpload`."""
20
21=== modified file 'lib/lp/soyuz/tests/test_packageupload.py'
22--- lib/lp/soyuz/tests/test_packageupload.py 2012-07-04 13:02:32 +0000
23+++ lib/lp/soyuz/tests/test_packageupload.py 2012-07-05 13:10:27 +0000
24@@ -1034,6 +1034,18 @@
25 for file in upload.sourcepackagerelease.files]
26 self.assertContentEqual(source_file_urls, ws_source_file_urls)
27
28+ def assertBinaryPropertiesMatch(self, arch, bpr, ws_binary):
29+ expected_binary = {
30+ "is_new": True,
31+ "name": bpr.name,
32+ "version": bpr.version,
33+ "architecture": arch,
34+ "component": "universe",
35+ "section": bpr.section.name,
36+ "priority": bpr.priority.name,
37+ }
38+ self.assertEqual(expected_binary, ws_binary)
39+
40 def test_binary_info(self):
41 # API clients can inspect properties of binary uploads.
42 person = self.makeQueueAdmin([self.universe])
43@@ -1047,19 +1059,8 @@
44 self.assertTrue(ws_upload.contains_build)
45 ws_binaries = ws_upload.getBinaryProperties()
46 self.assertEqual(len(list(bprs)), len(ws_binaries))
47- for bpr, binary in zip(bprs, ws_binaries):
48- expected_binary = {
49- "is_new": True,
50- "name": bpr.name,
51- "version": bpr.version,
52- "architecture": arch,
53- "component": "universe",
54- "section": bpr.section.name,
55- "priority": bpr.priority.name,
56- }
57- self.assertContentEqual(expected_binary.keys(), binary.keys())
58- for key, value in expected_binary.items():
59- self.assertEqual(value, binary[key])
60+ for bpr, ws_binary in zip(bprs, ws_binaries):
61+ self.assertBinaryPropertiesMatch(arch, bpr, ws_binary)
62
63 def test_binary_fetch(self):
64 # API clients can fetch files attached to binary uploads.
65@@ -1091,6 +1092,13 @@
66 "debian-installer-images_1.tar.gz", ws_upload.display_name)
67 self.assertEqual("-", ws_upload.display_version)
68 self.assertEqual("raw-installer", ws_upload.display_arches)
69+ ws_binaries = ws_upload.getBinaryProperties()
70+ self.assertEqual(1, len(ws_binaries))
71+ expected_binary = {
72+ "name": "debian-installer-images_1.tar.gz",
73+ "customformat": "raw-installer",
74+ }
75+ self.assertEqual(expected_binary, ws_binaries[0])
76
77 def test_custom_fetch(self):
78 # API clients can fetch files attached to custom uploads.
79@@ -1106,3 +1114,32 @@
80 file.libraryfilealias, upload.archive).http_url
81 for file in upload.customfiles]
82 self.assertContentEqual(custom_file_urls, ws_custom_file_urls)
83+
84+ def test_binary_and_custom_info(self):
85+ # API clients can inspect properties of uploads containing both
86+ # ordinary binaries and custom upload files.
87+ person = self.makeQueueAdmin([self.universe])
88+ upload, _ = self.makeBinaryPackageUpload(
89+ person, binarypackagename="foo", component=self.universe)
90+ with person_logged_in(person):
91+ arch = upload.builds[0].build.arch_tag
92+ bprs = upload.builds[0].build.binarypackages
93+ version = bprs[0].version
94+ lfa = self.factory.makeLibraryFileAlias(
95+ filename="foo_%s_%s_translations.tar.gz" % (version, arch))
96+ upload.addCustom(
97+ lfa, PackageUploadCustomFormat.ROSETTA_TRANSLATIONS)
98+ transaction.commit()
99+ ws_upload = self.load(upload, person)
100+
101+ self.assertFalse(ws_upload.contains_source)
102+ self.assertTrue(ws_upload.contains_build)
103+ ws_binaries = ws_upload.getBinaryProperties()
104+ self.assertEqual(len(list(bprs)) + 1, len(ws_binaries))
105+ for bpr, ws_binary in zip(bprs, ws_binaries):
106+ self.assertBinaryPropertiesMatch(arch, bpr, ws_binary)
107+ expected_custom = {
108+ "name": "foo_%s_%s_translations.tar.gz" % (version, arch),
109+ "customformat": "raw-translations",
110+ }
111+ self.assertEqual(expected_custom, ws_binaries[-1])