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
=== modified file 'lib/lp/soyuz/model/queue.py'
--- lib/lp/soyuz/model/queue.py 2012-07-04 13:02:32 +0000
+++ lib/lp/soyuz/model/queue.py 2012-07-05 13:10:27 +0000
@@ -320,8 +320,14 @@
320320
321 def getBinaryProperties(self):321 def getBinaryProperties(self):
322 """See `IPackageUpload`."""322 """See `IPackageUpload`."""
323 return list(chain.from_iterable(323 properties = list(chain.from_iterable(
324 build.binaries for build in self.builds))324 build.binaries for build in self.builds))
325 for file in self.customfiles:
326 properties.append({
327 "name": file.libraryfilealias.filename,
328 "customformat": file.customformat.title,
329 })
330 return properties
325331
326 def setNew(self):332 def setNew(self):
327 """See `IPackageUpload`."""333 """See `IPackageUpload`."""
328334
=== modified file 'lib/lp/soyuz/tests/test_packageupload.py'
--- lib/lp/soyuz/tests/test_packageupload.py 2012-07-04 13:02:32 +0000
+++ lib/lp/soyuz/tests/test_packageupload.py 2012-07-05 13:10:27 +0000
@@ -1034,6 +1034,18 @@
1034 for file in upload.sourcepackagerelease.files]1034 for file in upload.sourcepackagerelease.files]
1035 self.assertContentEqual(source_file_urls, ws_source_file_urls)1035 self.assertContentEqual(source_file_urls, ws_source_file_urls)
10361036
1037 def assertBinaryPropertiesMatch(self, arch, bpr, ws_binary):
1038 expected_binary = {
1039 "is_new": True,
1040 "name": bpr.name,
1041 "version": bpr.version,
1042 "architecture": arch,
1043 "component": "universe",
1044 "section": bpr.section.name,
1045 "priority": bpr.priority.name,
1046 }
1047 self.assertEqual(expected_binary, ws_binary)
1048
1037 def test_binary_info(self):1049 def test_binary_info(self):
1038 # API clients can inspect properties of binary uploads.1050 # API clients can inspect properties of binary uploads.
1039 person = self.makeQueueAdmin([self.universe])1051 person = self.makeQueueAdmin([self.universe])
@@ -1047,19 +1059,8 @@
1047 self.assertTrue(ws_upload.contains_build)1059 self.assertTrue(ws_upload.contains_build)
1048 ws_binaries = ws_upload.getBinaryProperties()1060 ws_binaries = ws_upload.getBinaryProperties()
1049 self.assertEqual(len(list(bprs)), len(ws_binaries))1061 self.assertEqual(len(list(bprs)), len(ws_binaries))
1050 for bpr, binary in zip(bprs, ws_binaries):1062 for bpr, ws_binary in zip(bprs, ws_binaries):
1051 expected_binary = {1063 self.assertBinaryPropertiesMatch(arch, bpr, ws_binary)
1052 "is_new": True,
1053 "name": bpr.name,
1054 "version": bpr.version,
1055 "architecture": arch,
1056 "component": "universe",
1057 "section": bpr.section.name,
1058 "priority": bpr.priority.name,
1059 }
1060 self.assertContentEqual(expected_binary.keys(), binary.keys())
1061 for key, value in expected_binary.items():
1062 self.assertEqual(value, binary[key])
10631064
1064 def test_binary_fetch(self):1065 def test_binary_fetch(self):
1065 # API clients can fetch files attached to binary uploads.1066 # API clients can fetch files attached to binary uploads.
@@ -1091,6 +1092,13 @@
1091 "debian-installer-images_1.tar.gz", ws_upload.display_name)1092 "debian-installer-images_1.tar.gz", ws_upload.display_name)
1092 self.assertEqual("-", ws_upload.display_version)1093 self.assertEqual("-", ws_upload.display_version)
1093 self.assertEqual("raw-installer", ws_upload.display_arches)1094 self.assertEqual("raw-installer", ws_upload.display_arches)
1095 ws_binaries = ws_upload.getBinaryProperties()
1096 self.assertEqual(1, len(ws_binaries))
1097 expected_binary = {
1098 "name": "debian-installer-images_1.tar.gz",
1099 "customformat": "raw-installer",
1100 }
1101 self.assertEqual(expected_binary, ws_binaries[0])
10941102
1095 def test_custom_fetch(self):1103 def test_custom_fetch(self):
1096 # API clients can fetch files attached to custom uploads.1104 # API clients can fetch files attached to custom uploads.
@@ -1106,3 +1114,32 @@
1106 file.libraryfilealias, upload.archive).http_url1114 file.libraryfilealias, upload.archive).http_url
1107 for file in upload.customfiles]1115 for file in upload.customfiles]
1108 self.assertContentEqual(custom_file_urls, ws_custom_file_urls)1116 self.assertContentEqual(custom_file_urls, ws_custom_file_urls)
1117
1118 def test_binary_and_custom_info(self):
1119 # API clients can inspect properties of uploads containing both
1120 # ordinary binaries and custom upload files.
1121 person = self.makeQueueAdmin([self.universe])
1122 upload, _ = self.makeBinaryPackageUpload(
1123 person, binarypackagename="foo", component=self.universe)
1124 with person_logged_in(person):
1125 arch = upload.builds[0].build.arch_tag
1126 bprs = upload.builds[0].build.binarypackages
1127 version = bprs[0].version
1128 lfa = self.factory.makeLibraryFileAlias(
1129 filename="foo_%s_%s_translations.tar.gz" % (version, arch))
1130 upload.addCustom(
1131 lfa, PackageUploadCustomFormat.ROSETTA_TRANSLATIONS)
1132 transaction.commit()
1133 ws_upload = self.load(upload, person)
1134
1135 self.assertFalse(ws_upload.contains_source)
1136 self.assertTrue(ws_upload.contains_build)
1137 ws_binaries = ws_upload.getBinaryProperties()
1138 self.assertEqual(len(list(bprs)) + 1, len(ws_binaries))
1139 for bpr, ws_binary in zip(bprs, ws_binaries):
1140 self.assertBinaryPropertiesMatch(arch, bpr, ws_binary)
1141 expected_custom = {
1142 "name": "foo_%s_%s_translations.tar.gz" % (version, arch),
1143 "customformat": "raw-translations",
1144 }
1145 self.assertEqual(expected_custom, ws_binaries[-1])