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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
|
# Copyright 2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for adapters."""
__metaclass__ = type
from storm.store import Store
from testtools.matchers import Equals
from zope.component import getUtility
from lp.registry.model.pillaraffiliation import IHasAffiliation
from lp.services.worlddata.interfaces.language import ILanguageSet
from lp.testing import (
person_logged_in,
StormStatementRecorder,
TestCaseWithFactory,
)
from lp.testing.layers import (
DatabaseFunctionalLayer,
LaunchpadFunctionalLayer,
)
from lp.testing.matchers import HasQueryCount
class TestPillarAffiliation(TestCaseWithFactory):
layer = LaunchpadFunctionalLayer
def test_distro_badge_icon(self):
# A distro's icon is used for the badge if present.
person = self.factory.makePerson()
icon = self.factory.makeLibraryFileAlias(
filename='smurf.png', content_type='image/png')
distro = self.factory.makeDistribution(
owner=person, name='pting', icon=icon)
[badges] = IHasAffiliation(distro).getAffiliationBadges([person])
self.assertEqual((icon.getURL(), "Pting", "maintainer"), badges[0])
def _check_affiliated_with_distro(self, person, distro, role):
[badges] = IHasAffiliation(distro).getAffiliationBadges([person])
self.assertEqual(
("/@@/distribution-badge", "Pting", role), badges[0])
def test_distro_owner_affiliation(self):
# A person who owns a distro is affiliated.
person = self.factory.makePerson()
distro = self.factory.makeDistribution(owner=person, name='pting')
self._check_affiliated_with_distro(person, distro, 'maintainer')
def test_distro_driver_affiliation(self):
# A person who is a distro driver is affiliated.
person = self.factory.makePerson()
distro = self.factory.makeDistribution(driver=person, name='pting')
self._check_affiliated_with_distro(person, distro, 'driver')
def test_distro_team_driver_affiliation(self):
# A person who is a member of the distro driver team is affiliated.
person = self.factory.makePerson()
team = self.factory.makeTeam(members=[person])
distro = self.factory.makeDistribution(driver=team, name='pting')
self._check_affiliated_with_distro(person, distro, 'driver')
def test_no_distro_security_contact_affiliation(self):
# A person who is the security contact for a distro is not affiliated
# for simple distro affiliation checks.
person = self.factory.makePerson()
distro = self.factory.makeDistribution(security_contact=person)
self.assertEqual(
[], IHasAffiliation(distro).getAffiliationBadges([person])[0])
def test_no_distro_bug_supervisor_affiliation(self):
# A person who is the bug supervisor for a distro is not affiliated
# for simple distro affiliation checks.
person = self.factory.makePerson()
distro = self.factory.makeDistribution(bug_supervisor=person)
self.assertEqual(
[], IHasAffiliation(distro).getAffiliationBadges([person])[0])
def test_product_badge_icon(self):
# A product's icon is used for the badge if present.
person = self.factory.makePerson()
icon = self.factory.makeLibraryFileAlias(
filename='smurf.png', content_type='image/png')
product = self.factory.makeProduct(
owner=person, name='pting', icon=icon)
[badges] = IHasAffiliation(product).getAffiliationBadges([person])
self.assertEqual((icon.getURL(), "Pting", "maintainer"), badges[0])
def test_pillar_badge_icon(self):
# A pillar's icon is used for the badge if the context has no icon.
person = self.factory.makePerson()
icon = self.factory.makeLibraryFileAlias(
filename='smurf.png', content_type='image/png')
product = self.factory.makeProduct(
owner=person, name='pting', icon=icon)
bugtask = self.factory.makeBugTask(target=product)
[badges] = IHasAffiliation(bugtask).getAffiliationBadges([person])
self.assertEqual((icon.getURL(), "Pting", "maintainer"), badges[0])
def _check_affiliated_with_product(self, person, product, role):
[badges] = IHasAffiliation(product).getAffiliationBadges([person])
self.assertEqual(("/@@/product-badge", "Pting", role), badges[0])
def test_product_driver_affiliation(self):
# A person who is the driver for a product is affiliated.
person = self.factory.makePerson()
product = self.factory.makeProduct(driver=person, name='pting')
self._check_affiliated_with_product(person, product, 'driver')
def test_product_team_driver_affiliation(self):
# A person who is a member of the product driver team is affiliated.
person = self.factory.makePerson()
team = self.factory.makeTeam(members=[person])
product = self.factory.makeProduct(driver=team, name='pting')
self._check_affiliated_with_product(person, product, 'driver')
def test_product_group_driver_affiliation(self):
# A person who is the driver for a product's group is affiliated.
person = self.factory.makePerson()
project = self.factory.makeProject(driver=person)
product = self.factory.makeProduct(project=project, name='pting')
self._check_affiliated_with_product(person, product, 'driver')
def test_no_product_security_contact_affiliation(self):
# A person who is the security contact for a product is is not
# affiliated for simple product affiliation checks.
person = self.factory.makePerson()
product = self.factory.makeProduct(security_contact=person)
self.assertEqual(
[], IHasAffiliation(product).getAffiliationBadges([person])[0])
def test_no_product_bug_supervisor_affiliation(self):
# A person who is the bug supervisor for a product is is not
# affiliated for simple product affiliation checks.
person = self.factory.makePerson()
product = self.factory.makeProduct(bug_supervisor=person)
self.assertEqual(
[], IHasAffiliation(product).getAffiliationBadges([person])[0])
def test_product_owner_affiliation(self):
# A person who owns a product is affiliated.
person = self.factory.makePerson()
product = self.factory.makeProduct(owner=person, name='pting')
self._check_affiliated_with_product(person, product, 'maintainer')
def test_distro_affiliation_multiple_people(self):
# A collection of people associated with a distro are affiliated.
people = [self.factory.makePerson() for x in range(3)]
distro = self.factory.makeDistribution(owner=people[0],
driver=people[1],
name='pting')
person_badges = IHasAffiliation(distro).getAffiliationBadges(people)
self.assertEqual(
[("/@@/distribution-badge", "Pting", "maintainer")],
person_badges[0])
self.assertEqual(
[("/@@/distribution-badge", "Pting", "driver")], person_badges[1])
self.assertEqual([], person_badges[2])
def test_product_affiliation_query_count(self):
# Only 2 queries are expected, selects from:
# - Product, Person
person = self.factory.makePerson()
product = self.factory.makeProduct(owner=person, name='pting')
Store.of(product).invalidate()
with StormStatementRecorder() as recorder:
IHasAffiliation(product).getAffiliationBadges([person])
self.assertThat(recorder, HasQueryCount(Equals(2)))
def test_distro_affiliation_query_count(self):
# Only 2 business queries are expected, selects from:
# - Distribution, Person
# plus an additional query to create a PublisherConfig record.
person = self.factory.makePerson()
distro = self.factory.makeDistribution(owner=person, name='pting')
Store.of(distro).invalidate()
with StormStatementRecorder() as recorder:
IHasAffiliation(distro).getAffiliationBadges([person])
self.assertThat(recorder, HasQueryCount(Equals(3)))
class _TestBugTaskorBranchMixin:
def test_distro_security_contact_affiliation(self):
# A person who is the security contact for a distro is affiliated.
person = self.factory.makePerson()
distro = self.factory.makeDistribution(
security_contact=person, name='pting')
self._check_affiliated_with_distro(person, distro, 'security contact')
def test_distro_bug_supervisor_affiliation(self):
# A person who is the bug supervisor for a distro is affiliated.
person = self.factory.makePerson()
distro = self.factory.makeDistribution(
bug_supervisor=person, name='pting')
self._check_affiliated_with_distro(person, distro, 'bug supervisor')
def test_product_security_contact_affiliation(self):
# A person who is the security contact for a distro is affiliated.
person = self.factory.makePerson()
product = self.factory.makeProduct(
security_contact=person, name='pting')
self._check_affiliated_with_product(
person, product, 'security contact')
def test_product_bug_supervisor_affiliation(self):
# A person who is the bug supervisor for a distro is affiliated.
person = self.factory.makePerson()
product = self.factory.makeProduct(
bug_supervisor=person, name='pting')
self._check_affiliated_with_product(person, product, 'bug supervisor')
class TestBugTaskPillarAffiliation(_TestBugTaskorBranchMixin,
TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def test_correct_pillars_are_used(self):
bugtask = self.factory.makeBugTask()
adapter = IHasAffiliation(bugtask)
pillars = [bugtask.pillar for bugtask in bugtask.bug.bugtasks]
self.assertEqual(pillars, adapter.getPillars())
def _check_affiliated_with_distro(self, person, target, role):
bugtask = self.factory.makeBugTask(target=target)
[badges] = IHasAffiliation(bugtask).getAffiliationBadges([person])
self.assertEqual(
("/@@/distribution-badge", "Pting", role), badges[0])
def _check_affiliated_with_product(self, person, target, role):
bugtask = self.factory.makeBugTask(target=target)
[badges] = IHasAffiliation(bugtask).getAffiliationBadges([person])
self.assertEqual(
("/@@/product-badge", "Pting", role), badges[0])
def test_affiliated_with_multiple_bugtasks(self):
# When a bugtask belongs to a bug which has other bugtasks, all such
# bugtasks are checked for affiliation.
person = self.factory.makePerson()
bug = self.factory.makeBug()
expected_affiliations = []
for x in range(3):
bug_supervisor = None
if x == 0:
bug_supervisor = person
product = self.factory.makeProduct(
owner=person, bug_supervisor=bug_supervisor)
self.factory.makeBugTask(bug=bug, target=product)
expected_affiliations.append(
("/@@/product-badge", product.displayname, "maintainer"))
expected_affiliations.append(
("/@@/product-badge", product.displayname, "driver"))
if x == 0:
expected_affiliations.append(
("/@@/product-badge",
product.displayname, "bug supervisor"))
[badges] = IHasAffiliation(
bug.default_bugtask).getAffiliationBadges([person])
self.assertContentEqual(expected_affiliations, badges)
class TestBranchPillarAffiliation(_TestBugTaskorBranchMixin,
TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def test_correct_pillars_are_used(self):
branch = self.factory.makeBranch()
adapter = IHasAffiliation(branch)
self.assertEqual([branch.product], adapter.getPillars())
def test_personal_branches_have_no_pillars(self):
branch = self.factory.makeBranch(product=None)
adapter = IHasAffiliation(branch)
self.assertEqual([], adapter.getPillars())
def test_getBranch(self):
# The branch is the context.
branch = self.factory.makeBranch()
adapter = IHasAffiliation(branch)
self.assertEqual(branch, adapter.getBranch())
def test_branch_trusted_reviewer_affiliation(self):
# A person who is the branch's trusted reviewer is affiliated.
person = self.factory.makePerson()
product = self.factory.makeProduct(name='pting')
self._check_affiliated_with_product(
person, product, 'trusted reviewer')
def _check_affiliated_with_distro(self, person, target, role):
distroseries = self.factory.makeDistroSeries(distribution=target)
sp = self.factory.makeSourcePackage(distroseries=distroseries)
branch = self.factory.makeBranch(sourcepackage=sp)
[badges] = IHasAffiliation(branch).getAffiliationBadges([person])
self.assertEqual(
("/@@/distribution-badge", "Pting", role), badges[0])
def _check_affiliated_with_product(self, person, target, role):
branch = self.factory.makeBranch(product=target)
with person_logged_in(branch.owner):
branch.reviewer = person
[badges] = IHasAffiliation(branch).getAffiliationBadges([person])
self.assertEqual(
("/@@/product-badge", "Pting", role), badges[0])
class CodeReviewVotePillarAffiliationTestCase(TestBranchPillarAffiliation):
layer = DatabaseFunctionalLayer
def makeCodeReviewVote(self, branch):
merge_proposal = self.factory.makeBranchMergeProposal(
target_branch=branch)
reviewer = self.factory.makePerson()
with person_logged_in(merge_proposal.registrant):
vote = merge_proposal.nominateReviewer(
reviewer, merge_proposal.registrant)
return vote
def test_correct_pillars_are_used(self):
branch = self.factory.makeBranch()
vote = self.makeCodeReviewVote(branch)
adapter = IHasAffiliation(vote)
self.assertEqual([branch.product], adapter.getPillars())
def test_getBranch(self):
# The code review vote's target branch is the branch.
branch = self.factory.makeBranch()
vote = self.makeCodeReviewVote(branch)
adapter = IHasAffiliation(vote)
self.assertEqual(branch, adapter.getBranch())
def _check_affiliated_with_distro(self, person, target, role):
distroseries = self.factory.makeDistroSeries(distribution=target)
sp = self.factory.makeSourcePackage(distroseries=distroseries)
branch = self.factory.makeBranch(sourcepackage=sp)
vote = self.makeCodeReviewVote(branch)
[badges] = IHasAffiliation(vote).getAffiliationBadges([person])
self.assertEqual(
("/@@/distribution-badge", "Pting", role), badges[0])
def _check_affiliated_with_product(self, person, target, role):
branch = self.factory.makeBranch(product=target)
with person_logged_in(branch.owner):
branch.reviewer = person
vote = self.makeCodeReviewVote(branch)
[badges] = IHasAffiliation(vote).getAffiliationBadges([person])
self.assertEqual(
("/@@/product-badge", "Pting", role), badges[0])
class TestDistroSeriesPillarAffiliation(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def test_correct_pillars_are_used(self):
series = self.factory.makeDistroSeries()
adapter = IHasAffiliation(series)
self.assertEqual([series.distribution], adapter.getPillars())
def test_driver_affiliation(self):
# A person who is the driver for a distroseries is affiliated.
# Here, the affiliation is with the distribution of the series.
owner = self.factory.makePerson()
driver = self.factory.makePerson()
distribution = self.factory.makeDistribution(
owner=owner, driver=driver, name='pting')
distroseries = self.factory.makeDistroSeries(
registrant=driver, distribution=distribution)
[badges] = IHasAffiliation(
distroseries).getAffiliationBadges([driver])
self.assertEqual(
("/@@/distribution-badge", "Pting", "driver"), badges[0])
def test_distro_driver_affiliation(self):
# A person who is the driver for a distroseries' distro is affiliated.
# Here, the affiliation is with the distribution of the series.
owner = self.factory.makePerson()
driver = self.factory.makePerson()
distribution = self.factory.makeDistribution(
owner=owner, driver=driver, name='pting')
distroseries = self.factory.makeDistroSeries(
registrant=owner, distribution=distribution)
[badges] = IHasAffiliation(
distroseries).getAffiliationBadges([driver])
self.assertEqual(
("/@@/distribution-badge", "Pting", "driver"), badges[0])
class TestProductSeriesPillarAffiliation(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def test_correct_pillars_are_used(self):
series = self.factory.makeProductSeries()
adapter = IHasAffiliation(series)
self.assertEqual([series.product], adapter.getPillars())
def test_driver_affiliation(self):
# A person who is the driver for a productseries is affiliated.
# Here, the affiliation is with the product.
owner = self.factory.makePerson()
driver = self.factory.makePerson()
product = self.factory.makeProduct(
owner=owner, driver=driver, name='pting')
productseries = self.factory.makeProductSeries(
owner=driver, product=product)
[badges] = (
IHasAffiliation(productseries).getAffiliationBadges([driver]))
self.assertEqual(
("/@@/product-badge", "Pting", "driver"), badges[0])
def test_product_driver_affiliation(self):
# A person who is the driver for a productseries' product is
# affiliated. Here, the affiliation is with the product.
owner = self.factory.makePerson()
driver = self.factory.makePerson()
product = self.factory.makeProduct(
owner=owner, driver=driver, name='pting')
productseries = self.factory.makeProductSeries(
owner=owner, product=product)
[badges] = (
IHasAffiliation(productseries).getAffiliationBadges([driver]))
self.assertEqual(
("/@@/product-badge", "Pting", "driver"), badges[0])
def test_product_group_driver_affiliation(self):
# A person who is the driver for a productseries' product's group is
# affiliated. Here, the affiliation is with the product.
owner = self.factory.makePerson()
driver = self.factory.makePerson()
project = self.factory.makeProject(driver=driver)
product = self.factory.makeProduct(
owner=owner, project=project, name='pting')
productseries = self.factory.makeProductSeries(
owner=owner, product=product)
[badges] = (
IHasAffiliation(productseries).getAffiliationBadges([driver]))
self.assertEqual(
("/@@/product-badge", "Pting", "driver"), badges[0])
class TestQuestionPillarAffiliation(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def test_correct_pillars_are_used_for_product(self):
product = self.factory.makeProduct()
question = self.factory.makeQuestion(target=product)
adapter = IHasAffiliation(question)
self.assertEqual([question.product], adapter.getPillars())
def test_correct_pillars_are_used_for_distribution(self):
distribution = self.factory.makeDistribution()
question = self.factory.makeQuestion(target=distribution)
adapter = IHasAffiliation(question)
self.assertEqual([question.distribution], adapter.getPillars())
def test_correct_pillars_are_used_for_distro_sourcepackage(self):
distribution = self.factory.makeDistribution()
distro_sourcepackage = self.factory.makeDistributionSourcePackage(
distribution=distribution)
owner = self.factory.makePerson()
question = self.factory.makeQuestion(
target=distro_sourcepackage, owner=owner)
adapter = IHasAffiliation(question)
self.assertEqual([distribution], adapter.getPillars())
def test_answer_contact_affiliation_for_distro(self):
# A person is affiliated if they are an answer contact for a distro
# target.
answer_contact = self.factory.makePerson()
english = getUtility(ILanguageSet)['en']
answer_contact.addLanguage(english)
distro = self.factory.makeDistribution(owner=answer_contact)
with person_logged_in(answer_contact):
distro.addAnswerContact(answer_contact, answer_contact)
question = self.factory.makeQuestion(target=distro)
[badges] = (
IHasAffiliation(question).getAffiliationBadges([answer_contact]))
self.assertEqual(
("/@@/distribution-badge", distro.displayname,
"maintainer"), badges[0])
self.assertEqual(
("/@@/distribution-badge", distro.displayname,
"driver"), badges[1])
self.assertEqual(
("/@@/distribution-badge", distro.displayname,
"answer contact"), badges[2])
def test_answer_contact_affiliation_for_distro_sourcepackage(self):
# A person is affiliated if they are an answer contact for a dsp
# target.
answer_contact = self.factory.makePerson()
english = getUtility(ILanguageSet)['en']
answer_contact.addLanguage(english)
distribution = self.factory.makeDistribution(owner=answer_contact)
distro_sourcepackage = self.factory.makeDistributionSourcePackage(
distribution=distribution)
with person_logged_in(answer_contact):
distro_sourcepackage.addAnswerContact(
answer_contact, answer_contact)
question = self.factory.makeQuestion(
target=distro_sourcepackage, owner=answer_contact)
[badges] = (
IHasAffiliation(question).getAffiliationBadges([answer_contact]))
self.assertEqual(
("/@@/distribution-badge", distribution.displayname,
"maintainer"), badges[0])
self.assertEqual(
("/@@/distribution-badge", distribution.displayname,
"driver"), badges[1])
self.assertEqual(
("/@@/distribution-badge", distro_sourcepackage.displayname,
"answer contact"), badges[2])
def test_answer_contact_affiliation_for_distro_sourcepackage_distro(self):
# A person is affiliated if they are an answer contact for a dsp
# target's distro.
answer_contact = self.factory.makePerson()
english = getUtility(ILanguageSet)['en']
answer_contact.addLanguage(english)
distribution = self.factory.makeDistribution(owner=answer_contact)
distro_sourcepackage = self.factory.makeDistributionSourcePackage(
distribution=distribution)
with person_logged_in(answer_contact):
distribution.addAnswerContact(answer_contact, answer_contact)
question = self.factory.makeQuestion(
target=distro_sourcepackage, owner=answer_contact)
[badges] = (
IHasAffiliation(question).getAffiliationBadges([answer_contact]))
self.assertEqual(
("/@@/distribution-badge", distribution.displayname,
"maintainer"), badges[0])
self.assertEqual(
("/@@/distribution-badge", distribution.displayname,
"driver"), badges[1])
self.assertEqual(
("/@@/distribution-badge", distribution.displayname,
"answer contact"), badges[2])
def test_answer_contact_affiliation_for_product(self):
# A person is affiliated if they are an answer contact for a product
# target.
answer_contact = self.factory.makePerson()
english = getUtility(ILanguageSet)['en']
answer_contact.addLanguage(english)
product = self.factory.makeProduct()
with person_logged_in(answer_contact):
product.addAnswerContact(answer_contact, answer_contact)
question = self.factory.makeQuestion(target=product)
[badges] = (
IHasAffiliation(question).getAffiliationBadges([answer_contact]))
self.assertEqual(
("/@@/product-badge", product.displayname, "answer contact"),
badges[0])
def test_product_affiliation(self):
# A person is affiliated if they are affiliated with the product.
person = self.factory.makePerson()
product = self.factory.makeProduct(owner=person)
question = self.factory.makeQuestion(target=product)
[badges] = IHasAffiliation(question).getAffiliationBadges([person])
self.assertEqual(
("/@@/product-badge", product.displayname, "maintainer"),
badges[0])
def test_distribution_affiliation(self):
# A person is affiliated if they are affiliated with the distribution.
person = self.factory.makePerson()
distro = self.factory.makeDistribution(owner=person)
question = self.factory.makeQuestion(target=distro)
[badges] = IHasAffiliation(question).getAffiliationBadges([person])
self.assertEqual(
("/@@/distribution-badge", distro.displayname, "maintainer"),
badges[0])
class TestSpecificationPillarAffiliation(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def test_correct_pillars_are_used_for_product(self):
product = self.factory.makeProduct()
specification = self.factory.makeSpecification(product=product)
adapter = IHasAffiliation(specification)
self.assertEqual([specification.product], adapter.getPillars())
def test_correct_pillars_are_used_for_distribution(self):
distro = self.factory.makeDistribution()
specification = self.factory.makeSpecification(distribution=distro)
adapter = IHasAffiliation(specification)
self.assertEqual([specification.distribution], adapter.getPillars())
def test_product_affiliation(self):
# A person is affiliated if they are affiliated with the pillar.
person = self.factory.makePerson()
product = self.factory.makeProduct(owner=person)
specification = self.factory.makeSpecification(product=product)
[badges] = (
IHasAffiliation(specification).getAffiliationBadges([person]))
self.assertEqual(
("/@@/product-badge", product.displayname, "maintainer"),
badges[0])
def test_distribution_affiliation(self):
# A person is affiliated if they are affiliated with the distribution.
person = self.factory.makePerson()
distro = self.factory.makeDistribution(owner=person)
specification = self.factory.makeSpecification(distribution=distro)
[badges] = (
IHasAffiliation(specification).getAffiliationBadges([person]))
self.assertEqual(
("/@@/distribution-badge", distro.displayname, "maintainer"),
badges[0])
|