Merge lp:~jcsackett/launchpad/target-adapters-aplenty into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 13840
Proposed branch: lp:~jcsackett/launchpad/target-adapters-aplenty
Merge into: lp:launchpad
Diff against target: 195 lines (+122/-18)
3 files modified
lib/lp/app/browser/configure.zcml (+8/-0)
lib/lp/app/browser/tests/test_vocabulary.py (+65/-0)
lib/lp/app/browser/vocabulary.py (+49/-18)
To merge this branch: bzr merge lp:~jcsackett/launchpad/target-adapters-aplenty
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+73248@code.launchpad.net

Commit message

[r=gmb][bug=820005][incr] Creates new base adapter for targets for target pickers.

Description of the change

Summary
=======
This branch introduces a new base TargetPickerSource adapter to adapt targets (DistributionSourcePackage, Products, and Distributions) for use with the enhanced target pickers that are part of the disclosure work. It also creates very basic Product and Distribution to PickerEntrySource adapters and updates the DistributionSourcePackage adapter using the new base adapter.

Preimplementation
=================
Spoke with Curtis Hovey.

Implementation
==============
lib/lp/app/browser/configure.zcml
lib/lp/app/browser/vocabulary.py
--------------------------------
Created new base adapter, created product and distro adapters derived from new base, and updated the dsp adapter from the new base.

lib/lp/app/browser/tests/test_vocabulary.py
-------------------------------------------
Added tests.

Tests
=====
bin/test -vvct test_vocabulary

QA
==
None, this is a refactor and new parts aren't effectively bolted in to any new pickers.

Lint
====
= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/app/browser/configure.zcml
  lib/lp/app/browser/vocabulary.py
  lib/lp/app/browser/tests/test_vocabulary.py

./lib/lp/app/browser/vocabulary.py
     389: E251 no spaces around keyword / parameter equals

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/app/browser/configure.zcml'
--- lib/lp/app/browser/configure.zcml 2011-08-22 14:33:01 +0000
+++ lib/lp/app/browser/configure.zcml 2011-08-31 15:19:09 +0000
@@ -424,6 +424,14 @@
424 />424 />
425425
426 <adapter426 <adapter
427 factory="lp.app.browser.vocabulary.ProductPickerEntrySourceAdapter"
428 />
429
430 <adapter
431 factory="lp.app.browser.vocabulary.DistributionPickerEntrySourceAdapter"
432 />
433
434 <adapter
427 factory="lp.app.browser.vocabulary.ArchivePickerEntrySourceAdapter"435 factory="lp.app.browser.vocabulary.ArchivePickerEntrySourceAdapter"
428 />436 />
429437
430438
=== modified file 'lib/lp/app/browser/tests/test_vocabulary.py'
--- lib/lp/app/browser/tests/test_vocabulary.py 2011-08-21 21:19:39 +0000
+++ lib/lp/app/browser/tests/test_vocabulary.py 2011-08-31 15:19:09 +0000
@@ -150,6 +150,71 @@
150 self.assertEqual(None, None)150 self.assertEqual(None, None)
151151
152152
153class TestDistributionSourcePackagePickerEntrySourceAdapter(
154 TestCaseWithFactory):
155
156 layer = DatabaseFunctionalLayer
157
158 def test_dsp_to_picker_entry(self):
159 dsp = self.factory.makeDistributionSourcePackage()
160 adapter = IPickerEntrySource(dsp)
161 self.assertTrue(IPickerEntrySource.providedBy(adapter))
162
163 def test_dsp_provides_summary(self):
164 dsp = self.factory.makeDistributionSourcePackage()
165 series = self.factory.makeDistroSeries(distribution=dsp.distribution)
166 release = self.factory.makeSourcePackageRelease(
167 distroseries=series,
168 sourcepackagename=dsp.sourcepackagename)
169 self.factory.makeSourcePackagePublishingHistory(
170 distroseries=series,
171 sourcepackagerelease=release)
172 [entry] = IPickerEntrySource(dsp).getPickerEntries([dsp], object())
173 self.assertEqual(entry.description, 'Not yet built.')
174
175 archseries = self.factory.makeDistroArchSeries(distroseries=series)
176 bpn = self.factory.makeBinaryPackageName(name='fnord')
177 self.factory.makeBinaryPackagePublishingHistory(
178 binarypackagename=bpn,
179 source_package_release=release,
180 sourcepackagename=dsp.sourcepackagename,
181 distroarchseries=archseries)
182 [entry] = IPickerEntrySource(dsp).getPickerEntries([dsp], object())
183 self.assertEqual(entry.description, 'fnord')
184
185
186class TestProductPickerEntrySourceAdapter(TestCaseWithFactory):
187
188 layer = DatabaseFunctionalLayer
189
190 def test_product_to_picker_entry(self):
191 product = self.factory.makeProduct()
192 adapter = IPickerEntrySource(product)
193 self.assertTrue(IPickerEntrySource.providedBy(adapter))
194
195 def test_product_provides_summary(self):
196 product = self.factory.makeProduct()
197 [entry] = IPickerEntrySource(product).getPickerEntries(
198 [product], object())
199 self.assertEqual(entry.description, product.summary)
200
201
202class TestDistributionPickerEntrySourceAdapter(TestCaseWithFactory):
203
204 layer = DatabaseFunctionalLayer
205
206 def test_distribution_to_picker_entry(self):
207 distribution = self.factory.makeDistribution()
208 adapter = IPickerEntrySource(distribution)
209 self.assertTrue(IPickerEntrySource.providedBy(adapter))
210
211 def test_distribution_provides_summary(self):
212 distribution = self.factory.makeDistribution()
213 [entry] = IPickerEntrySource(distribution).getPickerEntries(
214 [distribution], object())
215 self.assertEqual(entry.description, distribution.summary)
216
217
153class TestPersonVocabulary:218class TestPersonVocabulary:
154 implements(IHugeVocabulary)219 implements(IHugeVocabulary)
155 test_persons = []220 test_persons = []
156221
=== modified file 'lib/lp/app/browser/vocabulary.py'
--- lib/lp/app/browser/vocabulary.py 2011-08-28 07:29:11 +0000
+++ lib/lp/app/browser/vocabulary.py 2011-08-31 15:19:09 +0000
@@ -40,10 +40,12 @@
40 )40 )
41from lp.app.errors import UnexpectedFormData41from lp.app.errors import UnexpectedFormData
42from lp.code.interfaces.branch import IBranch42from lp.code.interfaces.branch import IBranch
43from lp.registry.interfaces.distribution import IDistribution
43from lp.registry.interfaces.distributionsourcepackage import (44from lp.registry.interfaces.distributionsourcepackage import (
44 IDistributionSourcePackage,45 IDistributionSourcePackage,
45 )46 )
46from lp.registry.interfaces.person import IPerson47from lp.registry.interfaces.person import IPerson
48from lp.registry.interfaces.product import IProduct
47from lp.registry.interfaces.sourcepackagename import ISourcePackageName49from lp.registry.interfaces.sourcepackagename import ISourcePackageName
48from lp.registry.model.pillaraffiliation import IHasAffiliation50from lp.registry.model.pillaraffiliation import IHasAffiliation
49from lp.registry.model.sourcepackagename import getSourcePackageDescriptions51from lp.registry.model.sourcepackagename import getSourcePackageDescriptions
@@ -226,12 +228,29 @@
226 return entries228 return entries
227229
228230
231class TargetPickerEntrySourceAdapter(DefaultPickerEntrySourceAdapter):
232 """Adapt targets (Product, Package, Distribution) to PickerEntrySource."""
233
234 def getDescription(self, target):
235 """Gets the description data for target picker entries."""
236 raise NotImplemented
237
238 def getPickerEntries(self, term_values, context_object, **kwarg):
239 """See `IPickerEntrySource`"""
240 entries = (
241 super(TargetPickerEntrySourceAdapter, self)
242 .getPickerEntries(term_values, context_object, **kwarg))
243 for target, picker_entry in izip(term_values, entries):
244 picker_entry.description = self.getDescription(target)
245 return entries
246
247
229@adapter(ISourcePackageName)248@adapter(ISourcePackageName)
230class SourcePackageNamePickerEntrySourceAdapter(249class SourcePackageNamePickerEntrySourceAdapter(
231 DefaultPickerEntrySourceAdapter):250 DefaultPickerEntrySourceAdapter):
232 """Adapts ISourcePackageName to IPickerEntrySource."""251 """Adapts ISourcePackageName to IPickerEntrySource."""
233252
234 def getPickerEntry(self, term_values, context_object, **kwarg):253 def getPickerEntries(self, term_values, context_object, **kwarg):
235 """See `IPickerEntrySource`"""254 """See `IPickerEntrySource`"""
236 entries = (255 entries = (
237 super(SourcePackageNamePickerEntrySourceAdapter, self)256 super(SourcePackageNamePickerEntrySourceAdapter, self)
@@ -245,23 +264,35 @@
245264
246@adapter(IDistributionSourcePackage)265@adapter(IDistributionSourcePackage)
247class DistributionSourcePackagePickerEntrySourceAdapter(266class DistributionSourcePackagePickerEntrySourceAdapter(
248 DefaultPickerEntrySourceAdapter):267 TargetPickerEntrySourceAdapter):
249 """Adapts ISourcePackageName to IPickerEntrySource."""268 """Adapts IDistributionSourcePackage to IPickerEntrySource."""
250269
251 def getPickerEntries(self, term_values, context_object, **kwarg):270 def getDescription(self, target):
252 """See `IPickerEntrySource`"""271 """See `TargetPickerEntrySource`"""
253 entries = (272 binaries = target.publishing_history[0].getBuiltBinaries()
254 super(DistributionSourcePackagePickerEntrySourceAdapter, self)273 binary_names = [binary.binary_package_name for binary in binaries]
255 .getPickerEntries(term_values, context_object, **kwarg))274 if binary_names != []:
256 for dsp, picker_entry in izip(term_values, entries):275 description = ', '.join(binary_names)
257 binaries = dsp.publishing_history[0].getBuiltBinaries()276 else:
258 binary_names = [binary.binary_package_name for binary in binaries]277 description = 'Not yet built.'
259 if binary_names != []:278 return description
260 description = ', '.join(binary_names)279
261 else:280
262 description = 'Not yet built.'281@adapter(IProduct)
263 picker_entry.description = description282class ProductPickerEntrySourceAdapter(TargetPickerEntrySourceAdapter):
264 return entries283 """Adapts IProduct to IPickerEntrySource."""
284
285 def getDescription(self, target):
286 """See `TargetPickerEntrySource`"""
287 return target.summary
288
289
290@adapter(IDistribution)
291class DistributionPickerEntrySourceAdapter(TargetPickerEntrySourceAdapter):
292
293 def getDescription(self, target):
294 """See `TargetPickerEntrySource`"""
295 return target.summary
265296
266297
267@adapter(IArchive)298@adapter(IArchive)