~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[r=stevenk][bug=823644] Fix badge icon bug for person affiliation
 functionaility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from testtools.matchers import Equals
10
10
from zope.component import getUtility
11
11
 
12
 
from canonical.testing.layers import DatabaseFunctionalLayer
 
12
from canonical.testing.layers import (
 
13
    DatabaseFunctionalLayer,
 
14
    LaunchpadFunctionalLayer,
 
15
    )
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 (
22
25
 
23
26
class TestPillarAffiliation(TestCaseWithFactory):
24
27
 
25
 
    layer = DatabaseFunctionalLayer
 
28
    layer = LaunchpadFunctionalLayer
 
29
 
 
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)
26
39
 
27
40
    def _check_affiliated_with_distro(self, person, distro, role):
28
41
        [badge] = IHasAffiliation(distro).getAffiliationBadges([person])
29
 
        self.assertEqual(
30
 
            ("/@@/distribution-badge", "Pting %s" % role), badge)
 
42
        self.assertEqual(("/@@/distribution-badge", "Pting %s" % role), badge)
31
43
 
32
44
    def test_distro_owner_affiliation(self):
33
45
        # A person who owns a distro is affiliated.
64
76
        self.assertIs(
65
77
            None, IHasAffiliation(distro).getAffiliationBadges([person])[0])
66
78
 
 
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)
 
88
 
 
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)
 
99
 
67
100
    def _check_affiliated_with_product(self, person, product, role):
68
101
        [badge] = IHasAffiliation(product).getAffiliationBadges([person])
69
 
        self.assertEqual(
70
 
            ("/@@/product-badge", "Pting %s" % role), badge)
 
102
        self.assertEqual(("/@@/product-badge", "Pting %s" % role), badge)
71
103
 
72
104
    def test_product_driver_affiliation(self):
73
105
        # A person who is the driver for a product is affiliated.