1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# Copyright 2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test the Distribution Source Package vocabulary."""
__metaclass__ = type
from canonical.launchpad.webapp.vocabulary import IHugeVocabulary
from canonical.testing.layers import DatabaseFunctionalLayer
from lp.registry.vocabularies import DistributionSourcePackageVocabulary
from lp.testing import TestCaseWithFactory
class TestDistributionSourcePackageVocabulary(TestCaseWithFactory):
"""Test that the DistributionSourcePackageVocabulary behaves as
expected."""
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestDistributionSourcePackageVocabulary, self).setUp()
self.vocabulary = DistributionSourcePackageVocabulary()
def test_provides_ihugevocabulary(self):
self.assertProvides(self.vocabulary, IHugeVocabulary)
def test_toTerm_unbuilt_dsp(self):
# If the source has no built binaries, the term's value contains a
# string to that effect.
dsp = self.factory.makeDistributionSourcePackage(
sourcepackagename='foo')
term = self.vocabulary.toTerm(dsp)
self.assertEqual(dsp.sourcepackagename.name, term.title)
expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
self.assertEqual(expected_token, term.token)
self.assertEqual('Not yet built.', term.value)
def test_toTerm_built_single_binary(self):
# The binary package name appears in the term's value.
bpph = self.factory.makeBinaryPackagePublishingHistory()
spr = bpph.binarypackagerelease.build.source_package_release
dsp = self.factory.makeDistributionSourcePackage(
sourcepackagename=spr.sourcepackagename,
distribution=bpph.distroseries.distribution)
term = self.vocabulary.toTerm(dsp)
expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
self.assertEqual(expected_token, term.token)
self.assertEqual(bpph.binary_package_name, term.value)
def test_toTerm_built_multiple_binary(self):
# All of the binary package names appear in the term's value.
spph = self.factory.makeSourcePackagePublishingHistory()
spr = spph.sourcepackagerelease
das = self.factory.makeDistroArchSeries(
distroseries=spph.distroseries)
expected_names = []
for i in xrange(20):
bpb = self.factory.makeBinaryPackageBuild(
source_package_release=spr, distroarchseries=das)
bpr = self.factory.makeBinaryPackageRelease(build=bpb)
expected_names.append(bpr.name)
self.factory.makeBinaryPackagePublishingHistory(
binarypackagerelease=bpr, distroarchseries=das)
dsp = spr.distrosourcepackage
term = self.vocabulary.toTerm(dsp)
expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
self.assertEqual(expected_token, term.token)
self.assertEqual(', '.join(expected_names), term.value)
def test_searchForTerms_None(self):
# Searching for nothing gets you that.
results = self.vocabulary.searchForTerms()
self.assertIs(None, results)
def assertTermsEqual(self, expected, actual):
# Assert two given terms are equal.
self.assertEqual(expected.token, actual.token)
self.assertEqual(expected.title, actual.title)
self.assertEqual(expected.value, actual.value)
def test_searchForTerms_published_source(self):
# When we search for a source package name that is published, a DSP
# is returned.
spph = self.factory.makeSourcePackagePublishingHistory()
vocabulary = DistributionSourcePackageVocabulary(
context=spph.distroseries.distribution)
results = vocabulary.searchForTerms(query=spph.source_package_name)
dsp = self.factory.makeDistributionSourcePackage(
sourcepackagename=spph.source_package_name,
distribution=spph.distroseries.distribution)
self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
def test_searchForTerms_unpublished_source(self):
# If the source package name isn't published in the distribution,
# we get no results.
spph = self.factory.makeSourcePackagePublishingHistory()
vocabulary = DistributionSourcePackageVocabulary(
context=self.factory.makeDistribution())
results = vocabulary.searchForTerms(query=spph.source_package_name)
self.assertEqual([], list(results))
def test_searchForTerms_unpublished_binary(self):
# If the binary package name isn't published in the distribution,
# we get no results.
bpph = self.factory.makeBinaryPackagePublishingHistory()
vocabulary = DistributionSourcePackageVocabulary(
context=self.factory.makeDistribution())
results = vocabulary.searchForTerms(query=bpph.binary_package_name)
self.assertEqual([], list(results))
def test_searchForTerms_published_binary(self):
# We can search for a binary package name, which returns the DSP.
bpph = self.factory.makeBinaryPackagePublishingHistory()
distribution = bpph.distroarchseries.distroseries.distribution
vocabulary = DistributionSourcePackageVocabulary(
context=distribution)
spn = bpph.binarypackagerelease.build.source_package_release.name
dsp = self.factory.makeDistributionSourcePackage(
sourcepackagename=spn, distribution=distribution)
results = vocabulary.searchForTerms(query=bpph.binary_package_name)
self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
def test_searchForTerms_published_multiple_binaries(self):
# Searching for a subset of a binary package name returns the DSP
# that built the binary package.
spn = self.factory.getOrMakeSourcePackageName('xorg')
spr = self.factory.makeSourcePackageRelease(sourcepackagename=spn)
das = self.factory.makeDistroArchSeries()
spph = self.factory.makeSourcePackagePublishingHistory(
sourcepackagerelease=spr, distroseries=das.distroseries)
for name in ('xorg-common', 'xorg-server', 'xorg-video-intel'):
bpn = self.factory.getOrMakeBinaryPackageName(name)
bpb = self.factory.makeBinaryPackageBuild(
source_package_release=spr, distroarchseries=das)
bpr = self.factory.makeBinaryPackageRelease(
binarypackagename=bpn, build=bpb)
bpph = self.factory.makeBinaryPackagePublishingHistory(
binarypackagerelease=bpr, distroarchseries=das)
dsp = self.factory.makeDistributionSourcePackage(
distribution=das.distroseries.distribution,
sourcepackagename=spn)
vocabulary = DistributionSourcePackageVocabulary(
context=das.distroseries.distribution)
results = vocabulary.searchForTerms(query='xorg-se')
self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
|