Merge lp:~stevenk/launchpad/dsp-vocab-use-spn into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 13447
Proposed branch: lp:~stevenk/launchpad/dsp-vocab-use-spn
Merge into: lp:launchpad
Diff against target: 159 lines (+27/-31)
2 files modified
lib/lp/registry/tests/test_dsp_vocabularies.py (+21/-24)
lib/lp/registry/vocabularies.py (+6/-7)
To merge this branch: bzr merge lp:~stevenk/launchpad/dsp-vocab-use-spn
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Ian Booth (community) code* Approve
Review via email: mp+68046@code.launchpad.net

Commit message

[r=adeuring,wallyworld][no-qa] Force the DistributionSourcePackage vocab to expect and return SourcePackageNames.

Description of the change

Rejig the DistributionSourcePackage vocab so that it uses DSPes internally only and expects (and returns) SourcePackageNames.

To post a comment you must log in.
Revision history for this message
Ian Booth (wallyworld) wrote :

The changes look good to me.

review: Approve (code*)
Revision history for this message
Abel Deuring (adeuring) wrote :

As discussed on IRC, I think that having a constructor

     def __init__(self, context=None):
         self.context = context

conflicts with

     def toTerm(self, spn):
         """See `IVocabulary`."""
         dsp = self.context.getSourcePackage(spn)

where self.context must not be None. So, please remove the "=None" from the constructor.

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/registry/tests/test_dsp_vocabularies.py'
2--- lib/lp/registry/tests/test_dsp_vocabularies.py 2011-06-24 09:28:46 +0000
3+++ lib/lp/registry/tests/test_dsp_vocabularies.py 2011-07-15 09:31:55 +0000
4@@ -16,19 +16,18 @@
5 expected."""
6 layer = DatabaseFunctionalLayer
7
8- def setUp(self):
9- super(TestDistributionSourcePackageVocabulary, self).setUp()
10- self.vocabulary = DistributionSourcePackageVocabulary()
11-
12 def test_provides_ihugevocabulary(self):
13- self.assertProvides(self.vocabulary, IHugeVocabulary)
14+ vocabulary = DistributionSourcePackageVocabulary(
15+ self.factory.makeDistribution())
16+ self.assertProvides(vocabulary, IHugeVocabulary)
17
18 def test_toTerm_unbuilt_dsp(self):
19 # If the source has no built binaries, the term's value contains a
20 # string to that effect.
21 dsp = self.factory.makeDistributionSourcePackage(
22 sourcepackagename='foo')
23- term = self.vocabulary.toTerm(dsp)
24+ vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
25+ term = vocabulary.toTerm(dsp.name)
26 self.assertEqual(dsp.sourcepackagename.name, term.title)
27 expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
28 self.assertEqual(expected_token, term.token)
29@@ -41,7 +40,8 @@
30 dsp = self.factory.makeDistributionSourcePackage(
31 sourcepackagename=spr.sourcepackagename,
32 distribution=bpph.distroseries.distribution)
33- term = self.vocabulary.toTerm(dsp)
34+ vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
35+ term = vocabulary.toTerm(spr.sourcepackagename)
36 expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
37 self.assertEqual(expected_token, term.token)
38 self.assertEqual(bpph.binary_package_name, term.value)
39@@ -61,14 +61,17 @@
40 self.factory.makeBinaryPackagePublishingHistory(
41 binarypackagerelease=bpr, distroarchseries=das)
42 dsp = spr.distrosourcepackage
43- term = self.vocabulary.toTerm(dsp)
44+ vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
45+ term = vocabulary.toTerm(spr.sourcepackagename)
46 expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
47 self.assertEqual(expected_token, term.token)
48 self.assertEqual(', '.join(expected_names), term.value)
49
50 def test_searchForTerms_None(self):
51 # Searching for nothing gets you that.
52- results = self.vocabulary.searchForTerms()
53+ vocabulary = DistributionSourcePackageVocabulary(
54+ self.factory.makeDistribution())
55+ results = vocabulary.searchForTerms()
56 self.assertIs(None, results)
57
58 def assertTermsEqual(self, expected, actual):
59@@ -78,16 +81,14 @@
60 self.assertEqual(expected.value, actual.value)
61
62 def test_searchForTerms_published_source(self):
63- # When we search for a source package name that is published, a DSP
64- # is returned.
65+ # When we search for a source package name that is published, it is
66+ # returned.
67 spph = self.factory.makeSourcePackagePublishingHistory()
68 vocabulary = DistributionSourcePackageVocabulary(
69 context=spph.distroseries.distribution)
70 results = vocabulary.searchForTerms(query=spph.source_package_name)
71- dsp = self.factory.makeDistributionSourcePackage(
72- sourcepackagename=spph.source_package_name,
73- distribution=spph.distroseries.distribution)
74- self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
75+ self.assertTermsEqual(
76+ vocabulary.toTerm(spph.source_package_name), results[0])
77
78 def test_searchForTerms_unpublished_source(self):
79 # If the source package name isn't published in the distribution,
80@@ -108,19 +109,18 @@
81 self.assertEqual([], list(results))
82
83 def test_searchForTerms_published_binary(self):
84- # We can search for a binary package name, which returns the DSP.
85+ # We can search for a binary package name, which returns the
86+ # relevant SPN.
87 bpph = self.factory.makeBinaryPackagePublishingHistory()
88 distribution = bpph.distroarchseries.distroseries.distribution
89 vocabulary = DistributionSourcePackageVocabulary(
90 context=distribution)
91 spn = bpph.binarypackagerelease.build.source_package_release.name
92- dsp = self.factory.makeDistributionSourcePackage(
93- sourcepackagename=spn, distribution=distribution)
94 results = vocabulary.searchForTerms(query=bpph.binary_package_name)
95- self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
96+ self.assertTermsEqual(vocabulary.toTerm(spn), results[0])
97
98 def test_searchForTerms_published_multiple_binaries(self):
99- # Searching for a subset of a binary package name returns the DSP
100+ # Searching for a subset of a binary package name returns the SPN
101 # that built the binary package.
102 spn = self.factory.getOrMakeSourcePackageName('xorg')
103 spr = self.factory.makeSourcePackageRelease(sourcepackagename=spn)
104@@ -135,10 +135,7 @@
105 binarypackagename=bpn, build=bpb)
106 bpph = self.factory.makeBinaryPackagePublishingHistory(
107 binarypackagerelease=bpr, distroarchseries=das)
108- dsp = self.factory.makeDistributionSourcePackage(
109- distribution=das.distroseries.distribution,
110- sourcepackagename=spn)
111 vocabulary = DistributionSourcePackageVocabulary(
112 context=das.distroseries.distribution)
113 results = vocabulary.searchForTerms(query='xorg-se')
114- self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
115+ self.assertTermsEqual(vocabulary.toTerm(spn), results[0])
116
117=== modified file 'lib/lp/registry/vocabularies.py'
118--- lib/lp/registry/vocabularies.py 2011-07-13 11:43:42 +0000
119+++ lib/lp/registry/vocabularies.py 2011-07-15 09:31:55 +0000
120@@ -1983,7 +1983,7 @@
121 displayname = 'Select a package'
122 step_title = 'Search'
123
124- def __init__(self, context=None):
125+ def __init__(self, context):
126 self.context = context
127
128 def __contains__(self, obj):
129@@ -1995,9 +1995,9 @@
130 def __len__(self):
131 pass
132
133- def toTerm(self, dsp):
134+ def toTerm(self, spn):
135 """See `IVocabulary`."""
136- # SimpleTerm(value, token=None, title=None)
137+ dsp = self.context.getSourcePackage(spn)
138 if dsp.publishing_history:
139 binaries = dsp.publishing_history[0].getBuiltBinaries()
140 summary = ', '.join(
141@@ -2007,9 +2007,9 @@
142 token = '%s-%s' % (dsp.distribution.name, dsp.name)
143 return SimpleTerm(summary, token, dsp.name)
144
145- def getTerm(self, dsp):
146+ def getTerm(self, spn):
147 """See `IBaseVocabulary`."""
148- return self.toTerm(dsp)
149+ return self.toTerm(spn)
150
151 def getTermByToken(self, token):
152 """See `IVocabularyTokenized`."""
153@@ -2059,5 +2059,4 @@
154 SourcePackageName.name.contains_string(search_term),
155 BinaryPackageName.name.contains_string(
156 search_term))).config(distinct=True)
157- return [
158- self.toTerm(distribution.getSourcePackage(spn)) for spn in spns]
159+ return [self.toTerm(spn) for spn in spns]