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
=== modified file 'lib/lp/registry/tests/test_dsp_vocabularies.py'
--- lib/lp/registry/tests/test_dsp_vocabularies.py 2011-06-24 09:28:46 +0000
+++ lib/lp/registry/tests/test_dsp_vocabularies.py 2011-07-15 09:31:55 +0000
@@ -16,19 +16,18 @@
16 expected."""16 expected."""
17 layer = DatabaseFunctionalLayer17 layer = DatabaseFunctionalLayer
1818
19 def setUp(self):
20 super(TestDistributionSourcePackageVocabulary, self).setUp()
21 self.vocabulary = DistributionSourcePackageVocabulary()
22
23 def test_provides_ihugevocabulary(self):19 def test_provides_ihugevocabulary(self):
24 self.assertProvides(self.vocabulary, IHugeVocabulary)20 vocabulary = DistributionSourcePackageVocabulary(
21 self.factory.makeDistribution())
22 self.assertProvides(vocabulary, IHugeVocabulary)
2523
26 def test_toTerm_unbuilt_dsp(self):24 def test_toTerm_unbuilt_dsp(self):
27 # If the source has no built binaries, the term's value contains a25 # If the source has no built binaries, the term's value contains a
28 # string to that effect.26 # string to that effect.
29 dsp = self.factory.makeDistributionSourcePackage(27 dsp = self.factory.makeDistributionSourcePackage(
30 sourcepackagename='foo')28 sourcepackagename='foo')
31 term = self.vocabulary.toTerm(dsp)29 vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
30 term = vocabulary.toTerm(dsp.name)
32 self.assertEqual(dsp.sourcepackagename.name, term.title)31 self.assertEqual(dsp.sourcepackagename.name, term.title)
33 expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)32 expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
34 self.assertEqual(expected_token, term.token)33 self.assertEqual(expected_token, term.token)
@@ -41,7 +40,8 @@
41 dsp = self.factory.makeDistributionSourcePackage(40 dsp = self.factory.makeDistributionSourcePackage(
42 sourcepackagename=spr.sourcepackagename,41 sourcepackagename=spr.sourcepackagename,
43 distribution=bpph.distroseries.distribution)42 distribution=bpph.distroseries.distribution)
44 term = self.vocabulary.toTerm(dsp)43 vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
44 term = vocabulary.toTerm(spr.sourcepackagename)
45 expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)45 expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
46 self.assertEqual(expected_token, term.token)46 self.assertEqual(expected_token, term.token)
47 self.assertEqual(bpph.binary_package_name, term.value)47 self.assertEqual(bpph.binary_package_name, term.value)
@@ -61,14 +61,17 @@
61 self.factory.makeBinaryPackagePublishingHistory(61 self.factory.makeBinaryPackagePublishingHistory(
62 binarypackagerelease=bpr, distroarchseries=das)62 binarypackagerelease=bpr, distroarchseries=das)
63 dsp = spr.distrosourcepackage63 dsp = spr.distrosourcepackage
64 term = self.vocabulary.toTerm(dsp)64 vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
65 term = vocabulary.toTerm(spr.sourcepackagename)
65 expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)66 expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
66 self.assertEqual(expected_token, term.token)67 self.assertEqual(expected_token, term.token)
67 self.assertEqual(', '.join(expected_names), term.value)68 self.assertEqual(', '.join(expected_names), term.value)
6869
69 def test_searchForTerms_None(self):70 def test_searchForTerms_None(self):
70 # Searching for nothing gets you that.71 # Searching for nothing gets you that.
71 results = self.vocabulary.searchForTerms()72 vocabulary = DistributionSourcePackageVocabulary(
73 self.factory.makeDistribution())
74 results = vocabulary.searchForTerms()
72 self.assertIs(None, results)75 self.assertIs(None, results)
7376
74 def assertTermsEqual(self, expected, actual):77 def assertTermsEqual(self, expected, actual):
@@ -78,16 +81,14 @@
78 self.assertEqual(expected.value, actual.value)81 self.assertEqual(expected.value, actual.value)
7982
80 def test_searchForTerms_published_source(self):83 def test_searchForTerms_published_source(self):
81 # When we search for a source package name that is published, a DSP84 # When we search for a source package name that is published, it is
82 # is returned.85 # returned.
83 spph = self.factory.makeSourcePackagePublishingHistory()86 spph = self.factory.makeSourcePackagePublishingHistory()
84 vocabulary = DistributionSourcePackageVocabulary(87 vocabulary = DistributionSourcePackageVocabulary(
85 context=spph.distroseries.distribution)88 context=spph.distroseries.distribution)
86 results = vocabulary.searchForTerms(query=spph.source_package_name)89 results = vocabulary.searchForTerms(query=spph.source_package_name)
87 dsp = self.factory.makeDistributionSourcePackage(90 self.assertTermsEqual(
88 sourcepackagename=spph.source_package_name,91 vocabulary.toTerm(spph.source_package_name), results[0])
89 distribution=spph.distroseries.distribution)
90 self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
9192
92 def test_searchForTerms_unpublished_source(self):93 def test_searchForTerms_unpublished_source(self):
93 # If the source package name isn't published in the distribution,94 # If the source package name isn't published in the distribution,
@@ -108,19 +109,18 @@
108 self.assertEqual([], list(results))109 self.assertEqual([], list(results))
109110
110 def test_searchForTerms_published_binary(self):111 def test_searchForTerms_published_binary(self):
111 # We can search for a binary package name, which returns the DSP.112 # We can search for a binary package name, which returns the
113 # relevant SPN.
112 bpph = self.factory.makeBinaryPackagePublishingHistory()114 bpph = self.factory.makeBinaryPackagePublishingHistory()
113 distribution = bpph.distroarchseries.distroseries.distribution115 distribution = bpph.distroarchseries.distroseries.distribution
114 vocabulary = DistributionSourcePackageVocabulary(116 vocabulary = DistributionSourcePackageVocabulary(
115 context=distribution)117 context=distribution)
116 spn = bpph.binarypackagerelease.build.source_package_release.name118 spn = bpph.binarypackagerelease.build.source_package_release.name
117 dsp = self.factory.makeDistributionSourcePackage(
118 sourcepackagename=spn, distribution=distribution)
119 results = vocabulary.searchForTerms(query=bpph.binary_package_name)119 results = vocabulary.searchForTerms(query=bpph.binary_package_name)
120 self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])120 self.assertTermsEqual(vocabulary.toTerm(spn), results[0])
121121
122 def test_searchForTerms_published_multiple_binaries(self):122 def test_searchForTerms_published_multiple_binaries(self):
123 # Searching for a subset of a binary package name returns the DSP123 # Searching for a subset of a binary package name returns the SPN
124 # that built the binary package.124 # that built the binary package.
125 spn = self.factory.getOrMakeSourcePackageName('xorg')125 spn = self.factory.getOrMakeSourcePackageName('xorg')
126 spr = self.factory.makeSourcePackageRelease(sourcepackagename=spn)126 spr = self.factory.makeSourcePackageRelease(sourcepackagename=spn)
@@ -135,10 +135,7 @@
135 binarypackagename=bpn, build=bpb)135 binarypackagename=bpn, build=bpb)
136 bpph = self.factory.makeBinaryPackagePublishingHistory(136 bpph = self.factory.makeBinaryPackagePublishingHistory(
137 binarypackagerelease=bpr, distroarchseries=das)137 binarypackagerelease=bpr, distroarchseries=das)
138 dsp = self.factory.makeDistributionSourcePackage(
139 distribution=das.distroseries.distribution,
140 sourcepackagename=spn)
141 vocabulary = DistributionSourcePackageVocabulary(138 vocabulary = DistributionSourcePackageVocabulary(
142 context=das.distroseries.distribution)139 context=das.distroseries.distribution)
143 results = vocabulary.searchForTerms(query='xorg-se')140 results = vocabulary.searchForTerms(query='xorg-se')
144 self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])141 self.assertTermsEqual(vocabulary.toTerm(spn), results[0])
145142
=== modified file 'lib/lp/registry/vocabularies.py'
--- lib/lp/registry/vocabularies.py 2011-07-13 11:43:42 +0000
+++ lib/lp/registry/vocabularies.py 2011-07-15 09:31:55 +0000
@@ -1983,7 +1983,7 @@
1983 displayname = 'Select a package'1983 displayname = 'Select a package'
1984 step_title = 'Search'1984 step_title = 'Search'
19851985
1986 def __init__(self, context=None):1986 def __init__(self, context):
1987 self.context = context1987 self.context = context
19881988
1989 def __contains__(self, obj):1989 def __contains__(self, obj):
@@ -1995,9 +1995,9 @@
1995 def __len__(self):1995 def __len__(self):
1996 pass1996 pass
19971997
1998 def toTerm(self, dsp):1998 def toTerm(self, spn):
1999 """See `IVocabulary`."""1999 """See `IVocabulary`."""
2000 # SimpleTerm(value, token=None, title=None)2000 dsp = self.context.getSourcePackage(spn)
2001 if dsp.publishing_history:2001 if dsp.publishing_history:
2002 binaries = dsp.publishing_history[0].getBuiltBinaries()2002 binaries = dsp.publishing_history[0].getBuiltBinaries()
2003 summary = ', '.join(2003 summary = ', '.join(
@@ -2007,9 +2007,9 @@
2007 token = '%s-%s' % (dsp.distribution.name, dsp.name)2007 token = '%s-%s' % (dsp.distribution.name, dsp.name)
2008 return SimpleTerm(summary, token, dsp.name)2008 return SimpleTerm(summary, token, dsp.name)
20092009
2010 def getTerm(self, dsp):2010 def getTerm(self, spn):
2011 """See `IBaseVocabulary`."""2011 """See `IBaseVocabulary`."""
2012 return self.toTerm(dsp)2012 return self.toTerm(spn)
20132013
2014 def getTermByToken(self, token):2014 def getTermByToken(self, token):
2015 """See `IVocabularyTokenized`."""2015 """See `IVocabularyTokenized`."""
@@ -2059,5 +2059,4 @@
2059 SourcePackageName.name.contains_string(search_term),2059 SourcePackageName.name.contains_string(search_term),
2060 BinaryPackageName.name.contains_string(2060 BinaryPackageName.name.contains_string(
2061 search_term))).config(distinct=True)2061 search_term))).config(distinct=True)
2062 return [2062 return [self.toTerm(spn) for spn in spns]
2063 self.toTerm(distribution.getSourcePackage(spn)) for spn in spns]