~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/tests/test_pillaraffiliation.py

[r=gmb][bug=823033] Refactor the vocab term picker entry adapters to
        provide a set based interface,
        processing multiple people in a single call

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    layer = DatabaseFunctionalLayer
26
26
 
27
27
    def _check_affiliated_with_distro(self, person, distro, role):
28
 
        badge = IHasAffiliation(distro).getAffiliationBadge(person)
 
28
        [badge] = IHasAffiliation(distro).getAffiliationBadges([person])
29
29
        self.assertEqual(
30
30
            ("/@@/distribution-badge", "Pting %s" % role), badge)
31
31
 
54
54
        person = self.factory.makePerson()
55
55
        distro = self.factory.makeDistribution(security_contact=person)
56
56
        self.assertIs(
57
 
            None, IHasAffiliation(distro).getAffiliationBadge(person))
 
57
            None, IHasAffiliation(distro).getAffiliationBadges([person])[0])
58
58
 
59
59
    def test_no_distro_bug_supervisor_affiliation(self):
60
60
        # A person who is the bug supervisor for a distro is not affiliated
62
62
        person = self.factory.makePerson()
63
63
        distro = self.factory.makeDistribution(bug_supervisor=person)
64
64
        self.assertIs(
65
 
            None, IHasAffiliation(distro).getAffiliationBadge(person))
 
65
            None, IHasAffiliation(distro).getAffiliationBadges([person])[0])
66
66
 
67
67
    def _check_affiliated_with_product(self, person, product, role):
68
 
        badge = IHasAffiliation(product).getAffiliationBadge(person)
 
68
        [badge] = IHasAffiliation(product).getAffiliationBadges([person])
69
69
        self.assertEqual(
70
70
            ("/@@/product-badge", "Pting %s" % role), badge)
71
71
 
95
95
        person = self.factory.makePerson()
96
96
        product = self.factory.makeProduct(security_contact=person)
97
97
        self.assertIs(
98
 
            None, IHasAffiliation(product).getAffiliationBadge(person))
 
98
            None, IHasAffiliation(product).getAffiliationBadges([person])[0])
99
99
 
100
100
    def test_no_product_bug_supervisor_affiliation(self):
101
101
        # A person who is the bug supervisor for a product is is not
103
103
        person = self.factory.makePerson()
104
104
        product = self.factory.makeProduct(bug_supervisor=person)
105
105
        self.assertIs(
106
 
            None, IHasAffiliation(product).getAffiliationBadge(person))
 
106
            None, IHasAffiliation(product).getAffiliationBadges([person])[0])
107
107
 
108
108
    def test_product_owner_affiliation(self):
109
109
        # A person who owns a product is affiliated.
111
111
        product = self.factory.makeProduct(owner=person, name='pting')
112
112
        self._check_affiliated_with_product(person, product, 'maintainer')
113
113
 
 
114
    def test_distro_affiliation_multiple_people(self):
 
115
        # A collection of people associated with a distro are affiliated.
 
116
        people = [self.factory.makePerson() for x in range(3)]
 
117
        distro = self.factory.makeDistribution(owner=people[0],
 
118
                                               driver=people[1],
 
119
                                               name='pting')
 
120
        badges = IHasAffiliation(distro).getAffiliationBadges(people)
 
121
        self.assertEqual(
 
122
            ("/@@/distribution-badge", "Pting maintainer"), badges[0])
 
123
        self.assertEqual(
 
124
            ("/@@/distribution-badge", "Pting driver"), badges[1])
 
125
        self.assertIs(None, badges[2])
 
126
 
114
127
 
115
128
class _TestBugTaskorBranchMixin:
116
129
 
151
164
 
152
165
    def test_correct_pillar_is_used(self):
153
166
        bugtask = self.factory.makeBugTask()
154
 
        badge = IHasAffiliation(bugtask)
155
 
        self.assertEqual(bugtask.pillar, badge.getPillar())
 
167
        adapter = IHasAffiliation(bugtask)
 
168
        self.assertEqual(bugtask.pillar, adapter.getPillar())
156
169
 
157
170
    def _check_affiliated_with_distro(self, person, target, role):
158
171
        bugtask = self.factory.makeBugTask(target=target)
159
 
        badge = IHasAffiliation(bugtask).getAffiliationBadge(person)
 
172
        [badge] = IHasAffiliation(bugtask).getAffiliationBadges([person])
160
173
        self.assertEqual(
161
174
            ("/@@/distribution-badge", "Pting %s" % role), badge)
162
175
 
163
176
    def _check_affiliated_with_product(self, person, target, role):
164
177
        bugtask = self.factory.makeBugTask(target=target)
165
 
        badge = IHasAffiliation(bugtask).getAffiliationBadge(person)
 
178
        [badge] = IHasAffiliation(bugtask).getAffiliationBadges([person])
166
179
        self.assertEqual(
167
180
            ("/@@/product-badge", "Pting %s" % role), badge)
168
181
 
174
187
        bugtask = self.factory.makeBugTask(target=product)
175
188
        Store.of(bugtask).invalidate()
176
189
        with StormStatementRecorder() as recorder:
177
 
            IHasAffiliation(bugtask).getAffiliationBadge(person)
 
190
            IHasAffiliation(bugtask).getAffiliationBadges([person])
178
191
        self.assertThat(recorder, HasQueryCount(Equals(4)))
179
192
 
180
193
    def test_distro_affiliation_query_count(self):
185
198
        bugtask = self.factory.makeBugTask(target=distro)
186
199
        Store.of(bugtask).invalidate()
187
200
        with StormStatementRecorder() as recorder:
188
 
            IHasAffiliation(bugtask).getAffiliationBadge(person)
 
201
            IHasAffiliation(bugtask).getAffiliationBadges([person])
189
202
        self.assertThat(recorder, HasQueryCount(Equals(4)))
190
203
 
191
204
 
196
209
 
197
210
    def test_correct_pillar_is_used(self):
198
211
        branch = self.factory.makeBranch()
199
 
        badge = IHasAffiliation(branch)
200
 
        self.assertEqual(branch.product, badge.getPillar())
 
212
        adapter = IHasAffiliation(branch)
 
213
        self.assertEqual(branch.product, adapter.getPillar())
201
214
 
202
215
    def _check_affiliated_with_distro(self, person, target, role):
203
216
        distroseries = self.factory.makeDistroSeries(distribution=target)
204
217
        sp = self.factory.makeSourcePackage(distroseries=distroseries)
205
218
        branch = self.factory.makeBranch(sourcepackage=sp)
206
 
        badge = IHasAffiliation(branch).getAffiliationBadge(person)
 
219
        [badge] = IHasAffiliation(branch).getAffiliationBadges([person])
207
220
        self.assertEqual(
208
221
            ("/@@/distribution-badge", "Pting %s" % role), badge)
209
222
 
210
223
    def _check_affiliated_with_product(self, person, target, role):
211
224
        branch = self.factory.makeBranch(product=target)
212
 
        badge = IHasAffiliation(branch).getAffiliationBadge(person)
 
225
        [badge] = IHasAffiliation(branch).getAffiliationBadges([person])
213
226
        self.assertEqual(
214
227
            ("/@@/product-badge", "Pting %s" % role), badge)
215
228
 
220
233
 
221
234
    def test_correct_pillar_is_used(self):
222
235
        series = self.factory.makeDistroSeries()
223
 
        badge = IHasAffiliation(series)
224
 
        self.assertEqual(series.distribution, badge.getPillar())
 
236
        adapter = IHasAffiliation(series)
 
237
        self.assertEqual(series.distribution, adapter.getPillar())
225
238
 
226
239
    def test_driver_affiliation(self):
227
240
        # A person who is the driver for a distroseries is affiliated.
232
245
            owner=owner, driver=driver, name='pting')
233
246
        distroseries = self.factory.makeDistroSeries(
234
247
            registrant=driver, distribution=distribution)
235
 
        badge = IHasAffiliation(distroseries).getAffiliationBadge(driver)
 
248
        [badge] = IHasAffiliation(distroseries).getAffiliationBadges([driver])
236
249
        self.assertEqual(
237
250
            ("/@@/distribution-badge", "Pting driver"), badge)
238
251
 
245
258
            owner=owner, driver=driver, name='pting')
246
259
        distroseries = self.factory.makeDistroSeries(
247
260
            registrant=owner, distribution=distribution)
248
 
        badge = IHasAffiliation(distroseries).getAffiliationBadge(driver)
 
261
        [badge] = IHasAffiliation(distroseries).getAffiliationBadges([driver])
249
262
        self.assertEqual(
250
263
            ("/@@/distribution-badge", "Pting driver"), badge)
251
264
 
256
269
 
257
270
    def test_correct_pillar_is_used(self):
258
271
        series = self.factory.makeProductSeries()
259
 
        badge = IHasAffiliation(series)
260
 
        self.assertEqual(series.product, badge.getPillar())
 
272
        adapter = IHasAffiliation(series)
 
273
        self.assertEqual(series.product, adapter.getPillar())
261
274
 
262
275
    def test_driver_affiliation(self):
263
276
        # A person who is the driver for a productseries is affiliated.
268
281
            owner=owner, driver=driver, name='pting')
269
282
        productseries = self.factory.makeProductSeries(
270
283
            owner=driver, product=product)
271
 
        badge = IHasAffiliation(productseries).getAffiliationBadge(driver)
 
284
        [badge] = (
 
285
            IHasAffiliation(productseries).getAffiliationBadges([driver]))
272
286
        self.assertEqual(
273
287
            ("/@@/product-badge", "Pting driver"), badge)
274
288
 
281
295
            owner=owner, driver=driver, name='pting')
282
296
        productseries = self.factory.makeProductSeries(
283
297
            owner=owner, product=product)
284
 
        badge = IHasAffiliation(productseries).getAffiliationBadge(driver)
 
298
        [badge] = (
 
299
            IHasAffiliation(productseries).getAffiliationBadges([driver]))
285
300
        self.assertEqual(
286
301
            ("/@@/product-badge", "Pting driver"), badge)
287
302
 
295
310
            owner=owner, project=project, name='pting')
296
311
        productseries = self.factory.makeProductSeries(
297
312
            owner=owner, product=product)
298
 
        badge = IHasAffiliation(productseries).getAffiliationBadge(driver)
 
313
        [badge] = (
 
314
            IHasAffiliation(productseries).getAffiliationBadges([driver]))
299
315
        self.assertEqual(
300
316
            ("/@@/product-badge", "Pting driver"), badge)
301
317
 
307
323
    def test_correct_pillar_is_used_for_product(self):
308
324
        product = self.factory.makeProduct()
309
325
        question = self.factory.makeQuestion(target=product)
310
 
        badge = IHasAffiliation(question)
311
 
        self.assertEqual(question.product, badge.getPillar())
 
326
        adapter = IHasAffiliation(question)
 
327
        self.assertEqual(question.product, adapter.getPillar())
312
328
 
313
329
    def test_correct_pillar_is_used_for_distribution(self):
314
330
        distribution = self.factory.makeDistribution()
315
331
        question = self.factory.makeQuestion(target=distribution)
316
 
        badge = IHasAffiliation(question)
317
 
        self.assertEqual(question.distribution, badge.getPillar())
 
332
        adapter = IHasAffiliation(question)
 
333
        self.assertEqual(question.distribution, adapter.getPillar())
318
334
 
319
335
    def test_correct_pillar_is_used_for_distro_sourcepackage(self):
320
336
        distribution = self.factory.makeDistribution()
323
339
        owner = self.factory.makePerson()
324
340
        question = self.factory.makeQuestion(
325
341
            target=distro_sourcepackage, owner=owner)
326
 
        badge = IHasAffiliation(question)
327
 
        self.assertEqual(distribution, badge.getPillar())
 
342
        adapter = IHasAffiliation(question)
 
343
        self.assertEqual(distribution, adapter.getPillar())
328
344
 
329
345
    def test_answer_contact_affiliation_for_distro(self):
330
346
        # A person is affiliated if they are an answer contact for a distro
337
353
        with person_logged_in(answer_contact):
338
354
            distro.addAnswerContact(answer_contact, answer_contact)
339
355
        question = self.factory.makeQuestion(target=distro)
340
 
        badge = IHasAffiliation(question).getAffiliationBadge(answer_contact)
 
356
        [badge] = (
 
357
            IHasAffiliation(question).getAffiliationBadges([answer_contact]))
341
358
        self.assertEqual(
342
359
            ("/@@/distribution-badge", "%s answer contact" %
343
360
                distro.displayname), badge)
357
374
                answer_contact, answer_contact)
358
375
        question = self.factory.makeQuestion(
359
376
            target=distro_sourcepackage, owner=answer_contact)
360
 
        badge = IHasAffiliation(question).getAffiliationBadge(answer_contact)
 
377
        [badge] = (
 
378
            IHasAffiliation(question).getAffiliationBadges([answer_contact]))
361
379
        self.assertEqual(
362
380
            ("/@@/distribution-badge", "%s answer contact" %
363
381
                distro_sourcepackage.displayname), badge)
376
394
            distribution.addAnswerContact(answer_contact, answer_contact)
377
395
        question = self.factory.makeQuestion(
378
396
            target=distro_sourcepackage, owner=answer_contact)
379
 
        badge = IHasAffiliation(question).getAffiliationBadge(answer_contact)
 
397
        [badge] = (
 
398
            IHasAffiliation(question).getAffiliationBadges([answer_contact]))
380
399
        self.assertEqual(
381
400
            ("/@@/distribution-badge", "%s answer contact" %
382
401
                distribution.displayname), badge)
392
411
        with person_logged_in(answer_contact):
393
412
            product.addAnswerContact(answer_contact, answer_contact)
394
413
        question = self.factory.makeQuestion(target=product)
395
 
        badge = IHasAffiliation(question).getAffiliationBadge(answer_contact)
 
414
        [badge] = (
 
415
            IHasAffiliation(question).getAffiliationBadges([answer_contact]))
396
416
        self.assertEqual(
397
417
            ("/@@/product-badge", "%s answer contact" %
398
418
                product.displayname), badge)
402
422
        person = self.factory.makePerson()
403
423
        product = self.factory.makeProduct(owner=person)
404
424
        question = self.factory.makeQuestion(target=product)
405
 
        badge = IHasAffiliation(question).getAffiliationBadge(person)
 
425
        [badge] = IHasAffiliation(question).getAffiliationBadges([person])
406
426
        self.assertEqual(
407
427
            ("/@@/product-badge", "%s maintainer" %
408
428
                product.displayname), badge)
412
432
        person = self.factory.makePerson()
413
433
        distro = self.factory.makeDistribution(owner=person)
414
434
        question = self.factory.makeQuestion(target=distro)
415
 
        badge = IHasAffiliation(question).getAffiliationBadge(person)
 
435
        [badge] = IHasAffiliation(question).getAffiliationBadges([person])
416
436
        self.assertEqual(
417
437
            ("/@@/distribution-badge", "%s maintainer" %
418
438
                distro.displayname), badge)
425
445
    def test_correct_pillar_is_used_for_product(self):
426
446
        product = self.factory.makeProduct()
427
447
        specification = self.factory.makeSpecification(product=product)
428
 
        badge = IHasAffiliation(specification)
429
 
        self.assertEqual(specification.product, badge.getPillar())
 
448
        adapter = IHasAffiliation(specification)
 
449
        self.assertEqual(specification.product, adapter.getPillar())
430
450
 
431
451
    def test_correct_pillar_is_used_for_distribution(self):
432
452
        distro = self.factory.makeDistribution()
433
453
        specification = self.factory.makeSpecification(distribution=distro)
434
 
        badge = IHasAffiliation(specification)
435
 
        self.assertEqual(specification.distribution, badge.getPillar())
 
454
        adapter = IHasAffiliation(specification)
 
455
        self.assertEqual(specification.distribution, adapter.getPillar())
436
456
 
437
457
    def test_product_affiliation(self):
438
458
        # A person is affiliated if they are affiliated with the pillar.
439
459
        person = self.factory.makePerson()
440
460
        product = self.factory.makeProduct(owner=person)
441
461
        specification = self.factory.makeSpecification(product=product)
442
 
        badge = IHasAffiliation(specification).getAffiliationBadge(person)
 
462
        [badge] = (
 
463
            IHasAffiliation(specification).getAffiliationBadges([person]))
443
464
        self.assertEqual(
444
465
            ("/@@/product-badge", "%s maintainer" %
445
466
                product.displayname), badge)
449
470
        person = self.factory.makePerson()
450
471
        distro = self.factory.makeDistribution(owner=person)
451
472
        specification = self.factory.makeSpecification(distribution=distro)
452
 
        badge = IHasAffiliation(specification).getAffiliationBadge(person)
 
473
        [badge] = (
 
474
            IHasAffiliation(specification).getAffiliationBadges([person]))
453
475
        self.assertEqual(
454
476
            ("/@@/distribution-badge", "%s maintainer" %
455
477
                distro.displayname), badge)