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
1=== modified file 'lib/lp/app/browser/configure.zcml'
2--- lib/lp/app/browser/configure.zcml 2011-08-22 14:33:01 +0000
3+++ lib/lp/app/browser/configure.zcml 2011-08-31 15:19:09 +0000
4@@ -424,6 +424,14 @@
5 />
6
7 <adapter
8+ factory="lp.app.browser.vocabulary.ProductPickerEntrySourceAdapter"
9+ />
10+
11+ <adapter
12+ factory="lp.app.browser.vocabulary.DistributionPickerEntrySourceAdapter"
13+ />
14+
15+ <adapter
16 factory="lp.app.browser.vocabulary.ArchivePickerEntrySourceAdapter"
17 />
18
19
20=== modified file 'lib/lp/app/browser/tests/test_vocabulary.py'
21--- lib/lp/app/browser/tests/test_vocabulary.py 2011-08-21 21:19:39 +0000
22+++ lib/lp/app/browser/tests/test_vocabulary.py 2011-08-31 15:19:09 +0000
23@@ -150,6 +150,71 @@
24 self.assertEqual(None, None)
25
26
27+class TestDistributionSourcePackagePickerEntrySourceAdapter(
28+ TestCaseWithFactory):
29+
30+ layer = DatabaseFunctionalLayer
31+
32+ def test_dsp_to_picker_entry(self):
33+ dsp = self.factory.makeDistributionSourcePackage()
34+ adapter = IPickerEntrySource(dsp)
35+ self.assertTrue(IPickerEntrySource.providedBy(adapter))
36+
37+ def test_dsp_provides_summary(self):
38+ dsp = self.factory.makeDistributionSourcePackage()
39+ series = self.factory.makeDistroSeries(distribution=dsp.distribution)
40+ release = self.factory.makeSourcePackageRelease(
41+ distroseries=series,
42+ sourcepackagename=dsp.sourcepackagename)
43+ self.factory.makeSourcePackagePublishingHistory(
44+ distroseries=series,
45+ sourcepackagerelease=release)
46+ [entry] = IPickerEntrySource(dsp).getPickerEntries([dsp], object())
47+ self.assertEqual(entry.description, 'Not yet built.')
48+
49+ archseries = self.factory.makeDistroArchSeries(distroseries=series)
50+ bpn = self.factory.makeBinaryPackageName(name='fnord')
51+ self.factory.makeBinaryPackagePublishingHistory(
52+ binarypackagename=bpn,
53+ source_package_release=release,
54+ sourcepackagename=dsp.sourcepackagename,
55+ distroarchseries=archseries)
56+ [entry] = IPickerEntrySource(dsp).getPickerEntries([dsp], object())
57+ self.assertEqual(entry.description, 'fnord')
58+
59+
60+class TestProductPickerEntrySourceAdapter(TestCaseWithFactory):
61+
62+ layer = DatabaseFunctionalLayer
63+
64+ def test_product_to_picker_entry(self):
65+ product = self.factory.makeProduct()
66+ adapter = IPickerEntrySource(product)
67+ self.assertTrue(IPickerEntrySource.providedBy(adapter))
68+
69+ def test_product_provides_summary(self):
70+ product = self.factory.makeProduct()
71+ [entry] = IPickerEntrySource(product).getPickerEntries(
72+ [product], object())
73+ self.assertEqual(entry.description, product.summary)
74+
75+
76+class TestDistributionPickerEntrySourceAdapter(TestCaseWithFactory):
77+
78+ layer = DatabaseFunctionalLayer
79+
80+ def test_distribution_to_picker_entry(self):
81+ distribution = self.factory.makeDistribution()
82+ adapter = IPickerEntrySource(distribution)
83+ self.assertTrue(IPickerEntrySource.providedBy(adapter))
84+
85+ def test_distribution_provides_summary(self):
86+ distribution = self.factory.makeDistribution()
87+ [entry] = IPickerEntrySource(distribution).getPickerEntries(
88+ [distribution], object())
89+ self.assertEqual(entry.description, distribution.summary)
90+
91+
92 class TestPersonVocabulary:
93 implements(IHugeVocabulary)
94 test_persons = []
95
96=== modified file 'lib/lp/app/browser/vocabulary.py'
97--- lib/lp/app/browser/vocabulary.py 2011-08-28 07:29:11 +0000
98+++ lib/lp/app/browser/vocabulary.py 2011-08-31 15:19:09 +0000
99@@ -40,10 +40,12 @@
100 )
101 from lp.app.errors import UnexpectedFormData
102 from lp.code.interfaces.branch import IBranch
103+from lp.registry.interfaces.distribution import IDistribution
104 from lp.registry.interfaces.distributionsourcepackage import (
105 IDistributionSourcePackage,
106 )
107 from lp.registry.interfaces.person import IPerson
108+from lp.registry.interfaces.product import IProduct
109 from lp.registry.interfaces.sourcepackagename import ISourcePackageName
110 from lp.registry.model.pillaraffiliation import IHasAffiliation
111 from lp.registry.model.sourcepackagename import getSourcePackageDescriptions
112@@ -226,12 +228,29 @@
113 return entries
114
115
116+class TargetPickerEntrySourceAdapter(DefaultPickerEntrySourceAdapter):
117+ """Adapt targets (Product, Package, Distribution) to PickerEntrySource."""
118+
119+ def getDescription(self, target):
120+ """Gets the description data for target picker entries."""
121+ raise NotImplemented
122+
123+ def getPickerEntries(self, term_values, context_object, **kwarg):
124+ """See `IPickerEntrySource`"""
125+ entries = (
126+ super(TargetPickerEntrySourceAdapter, self)
127+ .getPickerEntries(term_values, context_object, **kwarg))
128+ for target, picker_entry in izip(term_values, entries):
129+ picker_entry.description = self.getDescription(target)
130+ return entries
131+
132+
133 @adapter(ISourcePackageName)
134 class SourcePackageNamePickerEntrySourceAdapter(
135 DefaultPickerEntrySourceAdapter):
136 """Adapts ISourcePackageName to IPickerEntrySource."""
137
138- def getPickerEntry(self, term_values, context_object, **kwarg):
139+ def getPickerEntries(self, term_values, context_object, **kwarg):
140 """See `IPickerEntrySource`"""
141 entries = (
142 super(SourcePackageNamePickerEntrySourceAdapter, self)
143@@ -245,23 +264,35 @@
144
145 @adapter(IDistributionSourcePackage)
146 class DistributionSourcePackagePickerEntrySourceAdapter(
147- DefaultPickerEntrySourceAdapter):
148- """Adapts ISourcePackageName to IPickerEntrySource."""
149-
150- def getPickerEntries(self, term_values, context_object, **kwarg):
151- """See `IPickerEntrySource`"""
152- entries = (
153- super(DistributionSourcePackagePickerEntrySourceAdapter, self)
154- .getPickerEntries(term_values, context_object, **kwarg))
155- for dsp, picker_entry in izip(term_values, entries):
156- binaries = dsp.publishing_history[0].getBuiltBinaries()
157- binary_names = [binary.binary_package_name for binary in binaries]
158- if binary_names != []:
159- description = ', '.join(binary_names)
160- else:
161- description = 'Not yet built.'
162- picker_entry.description = description
163- return entries
164+ TargetPickerEntrySourceAdapter):
165+ """Adapts IDistributionSourcePackage to IPickerEntrySource."""
166+
167+ def getDescription(self, target):
168+ """See `TargetPickerEntrySource`"""
169+ binaries = target.publishing_history[0].getBuiltBinaries()
170+ binary_names = [binary.binary_package_name for binary in binaries]
171+ if binary_names != []:
172+ description = ', '.join(binary_names)
173+ else:
174+ description = 'Not yet built.'
175+ return description
176+
177+
178+@adapter(IProduct)
179+class ProductPickerEntrySourceAdapter(TargetPickerEntrySourceAdapter):
180+ """Adapts IProduct to IPickerEntrySource."""
181+
182+ def getDescription(self, target):
183+ """See `TargetPickerEntrySource`"""
184+ return target.summary
185+
186+
187+@adapter(IDistribution)
188+class DistributionPickerEntrySourceAdapter(TargetPickerEntrySourceAdapter):
189+
190+ def getDescription(self, target):
191+ """See `TargetPickerEntrySource`"""
192+ return target.summary
193
194
195 @adapter(IArchive)