Merge lp:~salgado/launchpad/refactor-blueprints-tests into lp:launchpad
- refactor-blueprints-tests
- Merge into devel
Proposed by
Guilherme Salgado
Status: | Merged |
---|---|
Merged at revision: | 11998 |
Proposed branch: | lp:~salgado/launchpad/refactor-blueprints-tests |
Merge into: | lp:launchpad |
Diff against target: |
368 lines (+180/-169) 2 files modified
lib/lp/blueprints/tests/test_hasspecifications.py (+180/-0) lib/lp/blueprints/tests/test_webservice.py (+0/-169) |
To merge this branch: | bzr merge lp:~salgado/launchpad/refactor-blueprints-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Henning Eggers (community) | code | Approve | |
Review via email: mp+42139@code.launchpad.net |
Commit message
[r=henninge]
Description of the change
Some of the webservice tests for blueprints that were created in my previous
branch were thoroughly testing model code because it was not tested anywhere.
This branch moves such tests to another file and make them exercise the model
code directly rather than through the webservice.
To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote : | # |
On Mon, 2010-11-29 at 16:59 +0000, Henning Eggers wrote:
> Review: Approve code
> Thanks for this clean-up. Please consider using assertContentEqual instead of "sorted" in assertNamesOfSp
Oops, I took your r=me on IRC as "I've no remarks, go ahead and land
it", so I didn't do that change. But I'll make sure to include it in my
next branch.
Thanks for the review!
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'lib/lp/blueprints/tests/test_hasspecifications.py' |
2 | --- lib/lp/blueprints/tests/test_hasspecifications.py 1970-01-01 00:00:00 +0000 |
3 | +++ lib/lp/blueprints/tests/test_hasspecifications.py 2010-11-29 16:23:11 +0000 |
4 | @@ -0,0 +1,180 @@ |
5 | +# Copyright 2010 Canonical Ltd. This software is licensed under the |
6 | +# GNU Affero General Public License version 3 (see the file LICENSE). |
7 | + |
8 | +"""Unit tests for objects implementing IHasSpecifications.""" |
9 | + |
10 | +__metaclass__ = type |
11 | + |
12 | + |
13 | +from canonical.testing.layers import DatabaseFunctionalLayer |
14 | +from lp.blueprints.interfaces.specification import ( |
15 | + SpecificationDefinitionStatus, |
16 | + ) |
17 | +from lp.testing import TestCaseWithFactory |
18 | + |
19 | + |
20 | +class HasSpecificationsTests(TestCaseWithFactory): |
21 | + |
22 | + layer = DatabaseFunctionalLayer |
23 | + |
24 | + def assertNamesOfSpecificationsAre(self, expected_names, specifications): |
25 | + names = [s.name for s in specifications] |
26 | + self.assertEqual(sorted(expected_names), sorted(names)) |
27 | + |
28 | + def test_product_all_specifications(self): |
29 | + product = self.factory.makeProduct() |
30 | + self.factory.makeSpecification(product=product, name="spec1") |
31 | + self.factory.makeSpecification(product=product, name="spec2") |
32 | + self.assertNamesOfSpecificationsAre( |
33 | + ["spec1", "spec2"], product.all_specifications) |
34 | + |
35 | + def test_product_valid_specifications(self): |
36 | + product = self.factory.makeProduct() |
37 | + self.factory.makeSpecification(product=product, name="spec1") |
38 | + self.factory.makeSpecification( |
39 | + product=product, name="spec2", |
40 | + status=SpecificationDefinitionStatus.OBSOLETE) |
41 | + self.assertNamesOfSpecificationsAre( |
42 | + ["spec1"], product.valid_specifications) |
43 | + |
44 | + def test_distribution_all_specifications(self): |
45 | + distribution = self.factory.makeDistribution() |
46 | + self.factory.makeSpecification( |
47 | + distribution=distribution, name="spec1") |
48 | + self.factory.makeSpecification( |
49 | + distribution=distribution, name="spec2") |
50 | + self.assertNamesOfSpecificationsAre( |
51 | + ["spec1", "spec2"], distribution.all_specifications) |
52 | + |
53 | + def test_distribution_valid_specifications(self): |
54 | + distribution = self.factory.makeDistribution() |
55 | + self.factory.makeSpecification( |
56 | + distribution=distribution, name="spec1") |
57 | + self.factory.makeSpecification( |
58 | + distribution=distribution, name="spec2", |
59 | + status=SpecificationDefinitionStatus.OBSOLETE) |
60 | + self.assertNamesOfSpecificationsAre( |
61 | + ["spec1"], distribution.valid_specifications) |
62 | + |
63 | + def test_distroseries_all_specifications(self): |
64 | + distroseries = self.factory.makeDistroSeries(name='maudlin') |
65 | + distribution = distroseries.distribution |
66 | + self.factory.makeSpecification( |
67 | + distribution=distribution, name="spec1", |
68 | + goal=distroseries) |
69 | + self.factory.makeSpecification( |
70 | + distribution=distribution, name="spec2", |
71 | + goal=distroseries) |
72 | + self.factory.makeSpecification( |
73 | + distribution=distribution, name="spec3") |
74 | + self.assertNamesOfSpecificationsAre( |
75 | + ["spec1", "spec2"], |
76 | + distroseries.all_specifications) |
77 | + |
78 | + # XXX: salgado, 2010-11-25, bug=681432: Test disabled because |
79 | + # DistroSeries.valid_specifications is broken. |
80 | + def disabled_test_distroseries_valid_specifications(self): |
81 | + distroseries = self.factory.makeDistroSeries(name='maudlin') |
82 | + distribution = distroseries.distribution |
83 | + self.factory.makeSpecification( |
84 | + distribution=distribution, name="spec1", |
85 | + goal=distroseries) |
86 | + self.factory.makeSpecification( |
87 | + distribution=distribution, name="spec2", |
88 | + goal=distroseries) |
89 | + self.factory.makeSpecification( |
90 | + distribution=distribution, name="spec3", |
91 | + goal=distroseries, |
92 | + status=SpecificationDefinitionStatus.OBSOLETE) |
93 | + self.factory.makeSpecification( |
94 | + distribution=distribution, name="spec4") |
95 | + self.assertNamesOfSpecificationsAre( |
96 | + ["spec1", "spec2"], |
97 | + distroseries.valid_specifications) |
98 | + |
99 | + def test_productseries_all_specifications(self): |
100 | + product = self.factory.makeProduct() |
101 | + productseries = self.factory.makeProductSeries( |
102 | + product=product, name="fooix-dev") |
103 | + self.factory.makeSpecification( |
104 | + product=product, name="spec1", goal=productseries) |
105 | + self.factory.makeSpecification( |
106 | + product=product, name="spec2", goal=productseries) |
107 | + self.factory.makeSpecification(product=product, name="spec3") |
108 | + self.assertNamesOfSpecificationsAre( |
109 | + ["spec1", "spec2"], productseries.all_specifications) |
110 | + |
111 | + def test_productseries_valid_specifications(self): |
112 | + product = self.factory.makeProduct() |
113 | + productseries = self.factory.makeProductSeries( |
114 | + product=product, name="fooix-dev") |
115 | + self.factory.makeSpecification( |
116 | + product=product, name="spec1", goal=productseries) |
117 | + self.factory.makeSpecification( |
118 | + product=product, name="spec2", goal=productseries) |
119 | + self.factory.makeSpecification( |
120 | + product=product, name="spec3", goal=productseries, |
121 | + status=SpecificationDefinitionStatus.OBSOLETE) |
122 | + self.factory.makeSpecification(product=product, name="spec4") |
123 | + self.assertNamesOfSpecificationsAre( |
124 | + ["spec1", "spec2"], productseries.valid_specifications) |
125 | + |
126 | + def test_projectgroup_all_specifications(self): |
127 | + projectgroup = self.factory.makeProject() |
128 | + other_projectgroup = self.factory.makeProject() |
129 | + product1 = self.factory.makeProduct(project=projectgroup) |
130 | + product2 = self.factory.makeProduct(project=projectgroup) |
131 | + product3 = self.factory.makeProduct(project=other_projectgroup) |
132 | + self.factory.makeSpecification( |
133 | + product=product1, name="spec1") |
134 | + self.factory.makeSpecification( |
135 | + product=product2, name="spec2", |
136 | + status=SpecificationDefinitionStatus.OBSOLETE) |
137 | + self.factory.makeSpecification( |
138 | + product=product3, name="spec3") |
139 | + self.assertNamesOfSpecificationsAre( |
140 | + ["spec1", "spec2"], |
141 | + projectgroup.all_specifications) |
142 | + |
143 | + def test_projectgroup_valid_specifications(self): |
144 | + projectgroup = self.factory.makeProject() |
145 | + other_projectgroup = self.factory.makeProject() |
146 | + product1 = self.factory.makeProduct(project=projectgroup) |
147 | + product2 = self.factory.makeProduct(project=projectgroup) |
148 | + product3 = self.factory.makeProduct(project=other_projectgroup) |
149 | + self.factory.makeSpecification( |
150 | + product=product1, name="spec1") |
151 | + self.factory.makeSpecification( |
152 | + product=product2, name="spec2", |
153 | + status=SpecificationDefinitionStatus.OBSOLETE) |
154 | + self.factory.makeSpecification( |
155 | + product=product3, name="spec3") |
156 | + self.assertNamesOfSpecificationsAre( |
157 | + ["spec1", "spec2"], |
158 | + projectgroup.valid_specifications) |
159 | + |
160 | + def test_person_all_specifications(self): |
161 | + person = self.factory.makePerson(name="james-w") |
162 | + product = self.factory.makeProduct() |
163 | + self.factory.makeSpecification( |
164 | + product=product, name="spec1", drafter=person) |
165 | + self.factory.makeSpecification( |
166 | + product=product, name="spec2", approver=person, |
167 | + status=SpecificationDefinitionStatus.OBSOLETE) |
168 | + self.factory.makeSpecification( |
169 | + product=product, name="spec3") |
170 | + self.assertNamesOfSpecificationsAre( |
171 | + ["spec1", "spec2"], person.all_specifications) |
172 | + |
173 | + def test_person_valid_specifications(self): |
174 | + person = self.factory.makePerson(name="james-w") |
175 | + product = self.factory.makeProduct() |
176 | + self.factory.makeSpecification( |
177 | + product=product, name="spec1", drafter=person) |
178 | + self.factory.makeSpecification( |
179 | + product=product, name="spec2", approver=person, |
180 | + status=SpecificationDefinitionStatus.OBSOLETE) |
181 | + self.factory.makeSpecification( |
182 | + product=product, name="spec3") |
183 | + self.assertNamesOfSpecificationsAre( |
184 | + ["spec1"], person.valid_specifications) |
185 | |
186 | === modified file 'lib/lp/blueprints/tests/test_webservice.py' |
187 | --- lib/lp/blueprints/tests/test_webservice.py 2010-11-26 18:04:53 +0000 |
188 | +++ lib/lp/blueprints/tests/test_webservice.py 2010-11-29 16:23:11 +0000 |
189 | @@ -214,26 +214,6 @@ |
190 | self.assertNamesOfSpecificationsAre( |
191 | ["spec1", "spec2"], product_on_webservice.all_specifications) |
192 | |
193 | - def test_product_valid_specifications(self): |
194 | - product = self.factory.makeProduct() |
195 | - self.factory.makeSpecification(product=product, name="spec1") |
196 | - self.factory.makeSpecification( |
197 | - product=product, name="spec2", |
198 | - status=SpecificationDefinitionStatus.OBSOLETE) |
199 | - product_on_webservice = self.getPillarOnWebservice(product) |
200 | - self.assertNamesOfSpecificationsAre( |
201 | - ["spec1"], product_on_webservice.valid_specifications) |
202 | - |
203 | - def test_distribution_all_specifications(self): |
204 | - distribution = self.factory.makeDistribution() |
205 | - self.factory.makeSpecification( |
206 | - distribution=distribution, name="spec1") |
207 | - self.factory.makeSpecification( |
208 | - distribution=distribution, name="spec2") |
209 | - distro_on_webservice = self.getPillarOnWebservice(distribution) |
210 | - self.assertNamesOfSpecificationsAre( |
211 | - ["spec1", "spec2"], distro_on_webservice.all_specifications) |
212 | - |
213 | def test_distribution_valid_specifications(self): |
214 | distribution = self.factory.makeDistribution() |
215 | self.factory.makeSpecification( |
216 | @@ -244,152 +224,3 @@ |
217 | distro_on_webservice = self.getPillarOnWebservice(distribution) |
218 | self.assertNamesOfSpecificationsAre( |
219 | ["spec1"], distro_on_webservice.valid_specifications) |
220 | - |
221 | - def test_distroseries_all_specifications(self): |
222 | - distribution = self.factory.makeDistribution() |
223 | - distroseries = self.factory.makeDistroSeries( |
224 | - name='maudlin', distribution=distribution) |
225 | - self.factory.makeSpecification( |
226 | - distribution=distribution, name="spec1", |
227 | - goal=distroseries) |
228 | - self.factory.makeSpecification( |
229 | - distribution=distribution, name="spec2", |
230 | - goal=distroseries) |
231 | - self.factory.makeSpecification( |
232 | - distribution=distribution, name="spec3") |
233 | - distro_on_webservice = self.getPillarOnWebservice(distribution) |
234 | - distroseries_on_webservice = distro_on_webservice.getSeries( |
235 | - name_or_version="maudlin") |
236 | - self.assertNamesOfSpecificationsAre( |
237 | - ["spec1", "spec2"], |
238 | - distroseries_on_webservice.all_specifications) |
239 | - |
240 | - # XXX: salgado, 2010-11-25, bug=681432: Test disabled because |
241 | - # DistroSeries.valid_specifications is broken. |
242 | - def disabled_test_distroseries_valid_specifications(self): |
243 | - distribution = self.factory.makeDistribution() |
244 | - distroseries = self.factory.makeDistroSeries( |
245 | - name='maudlin', distribution=distribution) |
246 | - self.factory.makeSpecification( |
247 | - distribution=distribution, name="spec1", |
248 | - goal=distroseries) |
249 | - self.factory.makeSpecification( |
250 | - distribution=distribution, name="spec2", |
251 | - goal=distroseries) |
252 | - self.factory.makeSpecification( |
253 | - distribution=distribution, name="spec3", |
254 | - goal=distroseries, |
255 | - status=SpecificationDefinitionStatus.OBSOLETE) |
256 | - self.factory.makeSpecification( |
257 | - distribution=distribution, name="spec4") |
258 | - distro_on_webservice = self.getPillarOnWebservice(distribution) |
259 | - distroseries_on_webservice = distro_on_webservice.getSeries( |
260 | - name_or_version="maudlin") |
261 | - self.assertNamesOfSpecificationsAre( |
262 | - ["spec1", "spec2"], |
263 | - distroseries_on_webservice.valid_specifications) |
264 | - |
265 | - def test_productseries_all_specifications(self): |
266 | - product = self.factory.makeProduct() |
267 | - productseries = self.factory.makeProductSeries( |
268 | - product=product, name="fooix-dev") |
269 | - self.factory.makeSpecification( |
270 | - product=product, name="spec1", goal=productseries) |
271 | - self.factory.makeSpecification( |
272 | - product=product, name="spec2", goal=productseries) |
273 | - self.factory.makeSpecification(product=product, name="spec3") |
274 | - product_on_webservice = self.getPillarOnWebservice(product) |
275 | - series_on_webservice = product_on_webservice.getSeries( |
276 | - name="fooix-dev") |
277 | - self.assertNamesOfSpecificationsAre( |
278 | - ["spec1", "spec2"], series_on_webservice.all_specifications) |
279 | - |
280 | - def test_productseries_valid_specifications(self): |
281 | - product = self.factory.makeProduct() |
282 | - productseries = self.factory.makeProductSeries( |
283 | - product=product, name="fooix-dev") |
284 | - self.factory.makeSpecification( |
285 | - product=product, name="spec1", goal=productseries) |
286 | - self.factory.makeSpecification( |
287 | - product=product, name="spec2", goal=productseries) |
288 | - self.factory.makeSpecification( |
289 | - product=product, name="spec3", goal=productseries, |
290 | - status=SpecificationDefinitionStatus.OBSOLETE) |
291 | - self.factory.makeSpecification(product=product, name="spec4") |
292 | - product_on_webservice = self.getPillarOnWebservice(product) |
293 | - series_on_webservice = product_on_webservice.getSeries( |
294 | - name="fooix-dev") |
295 | - # Should this be different to the results for distroseries? |
296 | - self.assertNamesOfSpecificationsAre( |
297 | - ["spec1", "spec2"], |
298 | - series_on_webservice.valid_specifications) |
299 | - |
300 | - def test_projectgroup_all_specifications(self): |
301 | - projectgroup = self.factory.makeProject() |
302 | - other_projectgroup = self.factory.makeProject() |
303 | - product1 = self.factory.makeProduct(project=projectgroup) |
304 | - product2 = self.factory.makeProduct(project=projectgroup) |
305 | - product3 = self.factory.makeProduct(project=other_projectgroup) |
306 | - self.factory.makeSpecification( |
307 | - product=product1, name="spec1") |
308 | - self.factory.makeSpecification( |
309 | - product=product2, name="spec2", |
310 | - status=SpecificationDefinitionStatus.OBSOLETE) |
311 | - self.factory.makeSpecification( |
312 | - product=product3, name="spec3") |
313 | - projectgroup_on_webservice = self.getPillarOnWebservice(projectgroup) |
314 | - # Should this be different to the results for distroseries? |
315 | - self.assertNamesOfSpecificationsAre( |
316 | - ["spec1", "spec2"], |
317 | - projectgroup_on_webservice.all_specifications) |
318 | - |
319 | - def test_projectgroup_valid_specifications(self): |
320 | - projectgroup = self.factory.makeProject() |
321 | - other_projectgroup = self.factory.makeProject() |
322 | - product1 = self.factory.makeProduct(project=projectgroup) |
323 | - product2 = self.factory.makeProduct(project=projectgroup) |
324 | - product3 = self.factory.makeProduct(project=other_projectgroup) |
325 | - self.factory.makeSpecification( |
326 | - product=product1, name="spec1") |
327 | - self.factory.makeSpecification( |
328 | - product=product2, name="spec2", |
329 | - status=SpecificationDefinitionStatus.OBSOLETE) |
330 | - self.factory.makeSpecification( |
331 | - product=product3, name="spec3") |
332 | - projectgroup_on_webservice = self.getPillarOnWebservice(projectgroup) |
333 | - # Should this be different to the results for distroseries? |
334 | - self.assertNamesOfSpecificationsAre( |
335 | - ["spec1", "spec2"], |
336 | - projectgroup_on_webservice.valid_specifications) |
337 | - |
338 | - def test_person_all_specifications(self): |
339 | - person = self.factory.makePerson(name="james-w") |
340 | - product = self.factory.makeProduct() |
341 | - self.factory.makeSpecification( |
342 | - product=product, name="spec1", drafter=person) |
343 | - self.factory.makeSpecification( |
344 | - product=product, name="spec2", approver=person, |
345 | - status=SpecificationDefinitionStatus.OBSOLETE) |
346 | - self.factory.makeSpecification( |
347 | - product=product, name="spec3") |
348 | - launchpadlib = self.getLaunchpadlib() |
349 | - person_on_webservice = launchpadlib.load( |
350 | - str(launchpadlib._root_uri) + '/~james-w') |
351 | - self.assertNamesOfSpecificationsAre( |
352 | - ["spec1", "spec2"], person_on_webservice.all_specifications) |
353 | - |
354 | - def test_person_valid_specifications(self): |
355 | - person = self.factory.makePerson(name="james-w") |
356 | - product = self.factory.makeProduct() |
357 | - self.factory.makeSpecification( |
358 | - product=product, name="spec1", drafter=person) |
359 | - self.factory.makeSpecification( |
360 | - product=product, name="spec2", approver=person, |
361 | - status=SpecificationDefinitionStatus.OBSOLETE) |
362 | - self.factory.makeSpecification( |
363 | - product=product, name="spec3") |
364 | - launchpadlib = self.getLaunchpadlib() |
365 | - person_on_webservice = launchpadlib.load( |
366 | - str(launchpadlib._root_uri) + '/~james-w') |
367 | - self.assertNamesOfSpecificationsAre( |
368 | - ["spec1"], person_on_webservice.valid_specifications) |
Thanks for this clean-up. Please consider using assertContentEqual instead of "sorted" in assertNamesOfSp ecificationsAre .
Cheers, Henning