9
9
from testtools.matchers import Equals
10
10
from zope.component import getUtility
12
from canonical.testing.layers import DatabaseFunctionalLayer
12
from canonical.testing.layers import (
13
DatabaseFunctionalLayer,
14
LaunchpadFunctionalLayer,
13
16
from lp.registry.model.pillaraffiliation import IHasAffiliation
14
17
from lp.services.worlddata.interfaces.language import ILanguageSet
15
18
from lp.testing import (
23
26
class TestPillarAffiliation(TestCaseWithFactory):
25
layer = DatabaseFunctionalLayer
28
layer = LaunchpadFunctionalLayer
30
def test_distro_badge_icon(self):
31
# A distro's icon is used for the badge if present.
32
person = self.factory.makePerson()
33
icon = self.factory.makeLibraryFileAlias(
34
filename='smurf.png', content_type='image/png')
35
distro = self.factory.makeDistribution(
36
owner=person, name='pting', icon=icon)
37
[badge] = IHasAffiliation(distro).getAffiliationBadges([person])
38
self.assertEqual((icon.getURL(), "Pting maintainer"), badge)
27
40
def _check_affiliated_with_distro(self, person, distro, role):
28
41
[badge] = IHasAffiliation(distro).getAffiliationBadges([person])
30
("/@@/distribution-badge", "Pting %s" % role), badge)
42
self.assertEqual(("/@@/distribution-badge", "Pting %s" % role), badge)
32
44
def test_distro_owner_affiliation(self):
33
45
# A person who owns a distro is affiliated.
65
77
None, IHasAffiliation(distro).getAffiliationBadges([person])[0])
79
def test_product_badge_icon(self):
80
# A product's icon is used for the badge if present.
81
person = self.factory.makePerson()
82
icon = self.factory.makeLibraryFileAlias(
83
filename='smurf.png', content_type='image/png')
84
product = self.factory.makeProduct(
85
owner=person, name='pting', icon=icon)
86
[badge] = IHasAffiliation(product).getAffiliationBadges([person])
87
self.assertEqual((icon.getURL(), "Pting maintainer"), badge)
89
def test_pillar_badge_icon(self):
90
# A pillar's icon is used for the badge if the context has no icon.
91
person = self.factory.makePerson()
92
icon = self.factory.makeLibraryFileAlias(
93
filename='smurf.png', content_type='image/png')
94
product = self.factory.makeProduct(
95
owner=person, name='pting', icon=icon)
96
bugtask = self.factory.makeBugTask(target=product)
97
[badge] = IHasAffiliation(bugtask).getAffiliationBadges([person])
98
self.assertEqual((icon.getURL(), "Pting maintainer"), badge)
67
100
def _check_affiliated_with_product(self, person, product, role):
68
101
[badge] = IHasAffiliation(product).getAffiliationBadges([person])
70
("/@@/product-badge", "Pting %s" % role), badge)
102
self.assertEqual(("/@@/product-badge", "Pting %s" % role), badge)
72
104
def test_product_driver_affiliation(self):
73
105
# A person who is the driver for a product is affiliated.