21
20
self.factory.makeDistribution())
22
21
self.assertProvides(vocabulary, IHugeVocabulary)
24
def test_toTerm_unbuilt_dsp(self):
25
# If the source has no built binaries, the term's value contains a
26
# string to that effect.
27
dsp = self.factory.makeDistributionSourcePackage(
28
sourcepackagename='foo')
29
vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
30
term = vocabulary.toTerm(dsp.name)
31
self.assertEqual(dsp.sourcepackagename.name, term.title)
32
expected_token = '%s/%s' % (dsp.distribution.name, dsp.name)
33
self.assertEqual(expected_token, term.token)
34
self.assertEqual('Not yet built.', term.value)
36
def test_toTerm_built_single_binary(self):
23
def test_init_IDistribution(self):
24
# When the context is adaptable to IDistribution, it also provides
26
dsp = self.factory.makeDistributionSourcePackage(
27
sourcepackagename='foo')
28
vocabulary = DistributionSourcePackageVocabulary(dsp)
29
self.assertEqual(dsp, vocabulary.context)
30
self.assertEqual(dsp.distribution, vocabulary.distribution)
32
def test_init_dsp_bugtask(self):
33
# A dsp bugtask can be the context
34
dsp = self.factory.makeDistributionSourcePackage(
35
sourcepackagename='foo')
36
bugtask = self.factory.makeBugTask(target=dsp)
37
vocabulary = DistributionSourcePackageVocabulary(bugtask)
38
self.assertEqual(bugtask, vocabulary.context)
39
self.assertEqual(dsp.distribution, vocabulary.distribution)
41
def test_init_dsp_question(self):
42
# A dsp bugtask can be the context
43
dsp = self.factory.makeDistributionSourcePackage(
44
sourcepackagename='foo')
45
question = self.factory.makeQuestion(
46
target=dsp, owner=dsp.distribution.owner)
47
vocabulary = DistributionSourcePackageVocabulary(question)
48
self.assertEqual(question, vocabulary.context)
49
self.assertEqual(dsp.distribution, vocabulary.distribution)
51
def test_init_no_distribution(self):
52
# The distribution is None if the context cannot be adapted to a
54
project = self.factory.makeProduct()
55
vocabulary = DistributionSourcePackageVocabulary(project)
56
self.assertEqual(project, vocabulary.context)
57
self.assertEqual(None, vocabulary.distribution)
59
def test_getDistributionAndPackageName_distro_and_package(self):
60
# getDistributionAndPackageName() returns a tuple of distribution
61
# and package name when the text contains both.
62
new_distro = self.factory.makeDistribution(name='fnord')
63
vocabulary = DistributionSourcePackageVocabulary(None)
64
distribution, package_name = vocabulary.getDistributionAndPackageName(
66
self.assertEqual(new_distro, distribution)
67
self.assertEqual('pting', package_name)
69
def test_getDistributionAndPackageName_default_distro_and_package(self):
70
# getDistributionAndPackageName() returns a tuple of the default
71
# distribution and package name when the text is just a package name.
72
default_distro = self.factory.makeDistribution(name='fnord')
73
vocabulary = DistributionSourcePackageVocabulary(default_distro)
74
distribution, package_name = vocabulary.getDistributionAndPackageName(
76
self.assertEqual(default_distro, distribution)
77
self.assertEqual('pting', package_name)
79
def test_getDistributionAndPackageName_bad_distro_and_package(self):
80
# getDistributionAndPackageName() returns a tuple of the default
81
# distribution and package name when the distro in the text cannot
82
# be matched to a real distro.
83
default_distro = self.factory.makeDistribution(name='fnord')
84
vocabulary = DistributionSourcePackageVocabulary(default_distro)
85
distribution, package_name = vocabulary.getDistributionAndPackageName(
87
self.assertEqual(default_distro, distribution)
88
self.assertEqual('pting', package_name)
90
def test_contains_true(self):
91
# The vocabulary contains DSPs that have SPPH in the distro.
92
spph = self.factory.makeSourcePackagePublishingHistory()
93
dsp = spph.sourcepackagerelease.distrosourcepackage
94
vocabulary = DistributionSourcePackageVocabulary(dsp)
95
self.assertTrue(dsp in vocabulary)
97
def test_contains_false(self):
98
# The vocabulary does not contain DSPs without SPPH.
99
spn = self.factory.makeSourcePackageName(name='foo')
100
dsp = self.factory.makeDistributionSourcePackage(
101
sourcepackagename=spn)
102
vocabulary = DistributionSourcePackageVocabulary(dsp)
103
self.assertFalse(dsp in vocabulary)
105
def test_toTerm_raises_error(self):
106
# An error is raised for DSP/SPNs without publishing history.
107
dsp = self.factory.makeDistributionSourcePackage(
108
sourcepackagename='foo')
109
vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
110
self.assertRaises(LookupError, vocabulary.toTerm, dsp.name)
112
def test_toTerm_none_raises_error(self):
113
# An error is raised for SPN does not exist.
114
vocabulary = DistributionSourcePackageVocabulary(None)
115
self.assertRaises(LookupError, vocabulary.toTerm, 'non-existant')
117
def test_toTerm_spn_and_default_distribution(self):
118
# The vocabulary's distribution is used when only a SPN is passed.
119
spph = self.factory.makeSourcePackagePublishingHistory()
120
dsp = spph.sourcepackagerelease.distrosourcepackage
121
vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
122
term = vocabulary.toTerm(dsp.sourcepackagename)
123
expected_token = '%s/%s' % (dsp.distribution.name, dsp.name)
124
self.assertEqual(expected_token, term.token)
125
self.assertEqual(dsp.sourcepackagename, term.value)
127
def test_toTerm_spn_and_distribution(self):
128
# The distribution is used with the spn if it is passed.
129
spph = self.factory.makeSourcePackagePublishingHistory()
130
dsp = spph.sourcepackagerelease.distrosourcepackage
131
vocabulary = DistributionSourcePackageVocabulary(None)
132
term = vocabulary.toTerm(dsp.sourcepackagename, dsp.distribution)
133
expected_token = '%s/%s' % (dsp.distribution.name, dsp.name)
134
self.assertEqual(expected_token, term.token)
135
self.assertEqual(dsp.sourcepackagename, term.value)
137
def test_toTerm_dsp(self):
138
# The DSP's distribution is used when a DSP is passed.
139
spph = self.factory.makeSourcePackagePublishingHistory()
140
dsp = spph.sourcepackagerelease.distrosourcepackage
141
vocabulary = DistributionSourcePackageVocabulary(dsp)
142
term = vocabulary.toTerm(dsp)
143
expected_token = '%s/%s' % (dsp.distribution.name, dsp.name)
144
self.assertEqual(expected_token, term.token)
145
self.assertEqual(dsp.sourcepackagename, term.value)
147
def test_toTerm_unbuilt_title(self):
148
# The DSP's distribution is used with the spn if it is passed.
149
# Published, but unbuilt packages state the case in the term title.
150
spph = self.factory.makeSourcePackagePublishingHistory()
151
dsp = spph.sourcepackagerelease.distrosourcepackage
152
vocabulary = DistributionSourcePackageVocabulary(dsp)
153
term = vocabulary.toTerm(dsp)
154
self.assertEqual('Not yet built.', term.title)
156
def test_toTerm_built_single_binary_title(self):
37
157
# The binary package name appears in the term's value.
38
158
bpph = self.factory.makeBinaryPackagePublishingHistory()
39
159
spr = bpph.binarypackagerelease.build.source_package_release
63
181
dsp = spr.distrosourcepackage
64
182
vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
65
183
term = vocabulary.toTerm(spr.sourcepackagename)
66
expected_token = '%s/%s' % (dsp.distribution.name, dsp.name)
67
self.assertEqual(expected_token, term.token)
68
self.assertEqual(', '.join(expected_names), term.value)
184
self.assertEqual(', '.join(expected_names), term.title)
186
def test_getTermByToken_error(self):
187
# An error is raised if the token does not match a published DSP.
188
dsp = self.factory.makeDistributionSourcePackage(
189
sourcepackagename='foo')
190
vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
191
token = '%s/%s' % (dsp.distribution.name, dsp.name)
192
self.assertRaises(LookupError, vocabulary.getTermByToken, token)
194
def test_getTermByToken_token(self):
195
# The term is return if it matches a published DSP.
196
spph = self.factory.makeSourcePackagePublishingHistory()
197
dsp = spph.sourcepackagerelease.distrosourcepackage
198
vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
199
token = '%s/%s' % (dsp.distribution.name, dsp.name)
200
term = vocabulary.getTermByToken(token)
201
self.assertEqual(dsp.sourcepackagename, term.value)
203
def test_searchForTerms_without_distribution(self):
204
# An empty result set is return if the vocabulary has no distribution
205
# and the search does not provide distribution information.
206
spph = self.factory.makeSourcePackagePublishingHistory()
207
dsp = spph.sourcepackagerelease.distrosourcepackage
208
vocabulary = DistributionSourcePackageVocabulary(dsp.name)
209
results = vocabulary.searchForTerms(dsp.name)
210
self.assertIs(0, results.count())
70
212
def test_searchForTerms_None(self):
71
213
# Searching for nothing gets you that.
72
214
vocabulary = DistributionSourcePackageVocabulary(
73
215
self.factory.makeDistribution())
74
216
results = vocabulary.searchForTerms()
75
self.assertIs(None, results)
217
self.assertIs(0, results.count())
77
219
def assertTermsEqual(self, expected, actual):
78
220
# Assert two given terms are equal.