25
25
layer = DatabaseFunctionalLayer
27
27
def _check_affiliated_with_distro(self, person, distro, role):
28
badge = IHasAffiliation(distro).getAffiliationBadge(person)
28
[badge] = IHasAffiliation(distro).getAffiliationBadges([person])
30
30
("/@@/distribution-badge", "Pting %s" % role), badge)
54
54
person = self.factory.makePerson()
55
55
distro = self.factory.makeDistribution(security_contact=person)
57
None, IHasAffiliation(distro).getAffiliationBadge(person))
57
None, IHasAffiliation(distro).getAffiliationBadges([person])[0])
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)
65
None, IHasAffiliation(distro).getAffiliationBadge(person))
65
None, IHasAffiliation(distro).getAffiliationBadges([person])[0])
67
67
def _check_affiliated_with_product(self, person, product, role):
68
badge = IHasAffiliation(product).getAffiliationBadge(person)
68
[badge] = IHasAffiliation(product).getAffiliationBadges([person])
70
70
("/@@/product-badge", "Pting %s" % role), badge)
95
95
person = self.factory.makePerson()
96
96
product = self.factory.makeProduct(security_contact=person)
98
None, IHasAffiliation(product).getAffiliationBadge(person))
98
None, IHasAffiliation(product).getAffiliationBadges([person])[0])
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)
106
None, IHasAffiliation(product).getAffiliationBadge(person))
106
None, IHasAffiliation(product).getAffiliationBadges([person])[0])
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')
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],
120
badges = IHasAffiliation(distro).getAffiliationBadges(people)
122
("/@@/distribution-badge", "Pting maintainer"), badges[0])
124
("/@@/distribution-badge", "Pting driver"), badges[1])
125
self.assertIs(None, badges[2])
115
128
class _TestBugTaskorBranchMixin:
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())
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)
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)
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)))
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)))
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())
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)
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)
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())
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)
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)
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())
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)
285
IHasAffiliation(productseries).getAffiliationBadges([driver]))
272
286
self.assertEqual(
273
287
("/@@/product-badge", "Pting driver"), badge)
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)
299
IHasAffiliation(productseries).getAffiliationBadges([driver]))
285
300
self.assertEqual(
286
301
("/@@/product-badge", "Pting driver"), badge)
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)
314
IHasAffiliation(productseries).getAffiliationBadges([driver]))
299
315
self.assertEqual(
300
316
("/@@/product-badge", "Pting driver"), badge)
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())
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())
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())
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)
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)
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)
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)
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())
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())
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)
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)
474
IHasAffiliation(specification).getAffiliationBadges([person]))
453
475
self.assertEqual(
454
476
("/@@/distribution-badge", "%s maintainer" %
455
477
distro.displayname), badge)