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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# Copyright 2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test the pillar vocabularies."""
__metaclass__ = type
from lp.registry.vocabularies import (
DistributionOrProductOrProjectGroupVocabulary,
DistributionOrProductVocabulary,
PillarVocabularyBase,
)
from lp.testing import (
celebrity_logged_in,
TestCaseWithFactory,
)
from lp.testing.layers import DatabaseFunctionalLayer
class TestPillarVocabularyBase(TestCaseWithFactory):
"""Test that the PillarVocabularyBase behaves as expected."""
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestPillarVocabularyBase, self).setUp()
self.vocabulary = PillarVocabularyBase()
self.product = self.factory.makeProduct(name='orchid-snark')
self.distribution = self.factory.makeDistribution(name='zebra-snark')
self.project_group = self.factory.makeProject(name='apple-snark')
def test_supported_filters(self):
# The vocab supports the correct filters.
self.assertEqual([
PillarVocabularyBase.ALL_FILTER],
self.vocabulary.supportedFilters()
)
def test_Product_toTerm(self):
# Product terms are composed of title, name, and the object.
term = self.vocabulary.toTerm(self.product)
self.assertEqual(self.product.title, term.title)
self.assertEqual(self.product.name, term.token)
self.assertEqual(self.product, term.value)
def test_ProjectGroup_toTerm(self):
# ProductGroup terms are composed of title, name, and the object.
term = self.vocabulary.toTerm(self.project_group)
self.assertEqual(self.project_group.title, term.title)
self.assertEqual(self.project_group.name, term.token)
self.assertEqual(self.project_group, term.value)
def test_getTermByToken(self):
# Tokens are case insentive because the product name is lowercase.
term = self.vocabulary.getTermByToken('ORCHID-SNARK')
self.assertEqual(self.product, term.value)
def test_getTermByToken_LookupError(self):
# getTermByToken() raises a LookupError when no match is found.
self.assertRaises(
LookupError,
self.vocabulary.getTermByToken, 'does-notexist')
def test_ordering(self):
# Results are ordered by rank, with exact matches first.
terms = self.vocabulary.searchForTerms('snark')
result = [term.value for term in terms]
self.assertEqual(
[self.project_group, self.product, self.distribution], result)
class VocabFilterMixin:
def _test_distribution_filter(self):
# Only distributions should be included in the search results.
terms = self.vocabulary.searchForTerms('snark', vocab_filter='DISTRO')
result = [term.value for term in terms]
self.assertEqual([self.distribution], result)
def _test_project_filter(self):
# Only projects should be included in the search results.
terms = self.vocabulary.searchForTerms(
'snark', vocab_filter='PROJECT')
result = [term.value for term in terms]
self.assertEqual([self.product], result)
def _test_projectgroup_filter(self):
# Only project groups should be included in the search results.
terms = self.vocabulary.searchForTerms(
'snark', vocab_filter='PROJECTGROUP')
result = [term.value for term in terms]
self.assertEqual([self.project_group], result)
class TestDistributionOrProductVocabulary(TestCaseWithFactory,
VocabFilterMixin):
"""Test that the ProductVocabulary behaves as expected."""
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestDistributionOrProductVocabulary, self).setUp()
self.vocabulary = DistributionOrProductVocabulary()
self.product = self.factory.makeProduct(name='orchid-snark')
self.distribution = self.factory.makeDistribution(name='zebra-snark')
def test_supported_filters(self):
# The vocab supports the correct filters.
self.assertEqual([
DistributionOrProductVocabulary.ALL_FILTER,
DistributionOrProductVocabulary.PROJECT_FILTER,
DistributionOrProductVocabulary.DISTRO_FILTER,
],
self.vocabulary.supportedFilters()
)
def test_project_filter(self):
self._test_project_filter()
def test_distribution_filter(self):
self._test_distribution_filter()
def test_inactive_products_are_excluded(self):
# Inactive product are not in the vocabulary.
with celebrity_logged_in('registry_experts'):
self.product.active = False
terms = self.vocabulary.searchForTerms('snark')
result = [term.value for term in terms]
self.assertEqual([self.distribution], result)
self.assertFalse(self.product in self.vocabulary)
def test_project_groups_are_excluded(self):
# Project groups are not in the vocabulary.
project_group = self.factory.makeProject(name='apple-snark')
terms = self.vocabulary.searchForTerms('snark')
result = [term.value for term in terms]
self.assertEqual([self.product, self.distribution], result)
self.assertFalse(project_group in self.vocabulary)
class TestDistributionOrProductOrProjectGroupVocabulary(TestCaseWithFactory,
VocabFilterMixin):
"""Test for DistributionOrProductOrProjectGroupVocabulary."""
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestDistributionOrProductOrProjectGroupVocabulary, self).setUp()
self.vocabulary = DistributionOrProductOrProjectGroupVocabulary()
self.product = self.factory.makeProduct(name='orchid-snark')
self.distribution = self.factory.makeDistribution(name='zebra-snark')
self.project_group = self.factory.makeProject(name='apple-snark')
def test_supported_filters(self):
# The vocab supports the correct filters.
self.assertEqual([
DistributionOrProductOrProjectGroupVocabulary.ALL_FILTER,
DistributionOrProductOrProjectGroupVocabulary.PROJECT_FILTER,
DistributionOrProductOrProjectGroupVocabulary.PROJECTGROUP_FILTER,
DistributionOrProductOrProjectGroupVocabulary.DISTRO_FILTER,
],
self.vocabulary.supportedFilters()
)
def test_project_filter(self):
self._test_project_filter()
def test_projectgroup_filter(self):
self._test_projectgroup_filter()
def test_distribution_filter(self):
self._test_distribution_filter()
def test_contains_all_pillars_active(self):
# All active products, project groups and distributions are included.
self.assertTrue(self.product in self.vocabulary)
self.assertTrue(self.distribution in self.vocabulary)
self.assertTrue(self.project_group in self.vocabulary)
def test_inactive_products_are_excluded(self):
# Inactive product are not in the vocabulary.
with celebrity_logged_in('registry_experts'):
self.product.active = False
terms = self.vocabulary.searchForTerms('snark')
result = [term.value for term in terms]
self.assertEqual([self.project_group, self.distribution], result)
self.assertFalse(self.product in self.vocabulary)
def test_inactive_product_groups_are_excluded(self):
# Inactive project groups are not in the vocabulary.
with celebrity_logged_in('registry_experts'):
self.project_group.active = False
terms = self.vocabulary.searchForTerms('snark')
result = [term.value for term in terms]
self.assertEqual([self.product, self.distribution], result)
self.assertFalse(self.project_group in self.vocabulary)
|