~launchpad-pqm/launchpad/devel

11664.3.6 by Edwin Grubbs
Added test and test helper.
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""Helper functions dealing with IServiceUsage."""
5
__metaclass__ = type
6
7
from zope.component import getUtility
8
9
from lp.app.enums import ServiceUsage
11775.3.9 by j.c.sackett
Updated test to use nifty service_usage_helper. Updated service_usage_helper to handle codehosting appropriately on products.
10
from lp.code.enums import BranchType
11664.3.6 by Edwin Grubbs
Added test and test helper.
11
from lp.registry.interfaces.pillar import IPillarNameSet
11775.3.9 by j.c.sackett
Updated test to use nifty service_usage_helper. Updated service_usage_helper to handle codehosting appropriately on products.
12
from lp.registry.interfaces.product import IProduct
14449.5.20 by Curtis Hovey
Do not lose the current interaction.
13
from lp.testing import celebrity_logged_in
11664.3.6 by Edwin Grubbs
Added test and test helper.
14
from lp.testing.factory import LaunchpadObjectFactory
15
16
17
def set_service_usage(pillar_name, **kw):
18
    factory = LaunchpadObjectFactory()
14449.5.20 by Curtis Hovey
Do not lose the current interaction.
19
    with celebrity_logged_in('admin'):
20
        pillar = getUtility(IPillarNameSet)[pillar_name]
21
        for attr, service_usage_name in kw.items():
22
            service_usage = getattr(ServiceUsage, service_usage_name)
23
            if attr == 'bug_tracking_usage':
24
                pillar.official_malone = (
25
                    service_usage == ServiceUsage.LAUNCHPAD)
26
                if service_usage == ServiceUsage.EXTERNAL:
27
                    pillar.bugtracker = factory.makeBugTracker()
11775.3.9 by j.c.sackett
Updated test to use nifty service_usage_helper. Updated service_usage_helper to handle codehosting appropriately on products.
28
14449.5.20 by Curtis Hovey
Do not lose the current interaction.
29
            # if we're setting codehosting on product things get trickier.
30
            elif attr == 'codehosting_usage' and IProduct.providedBy(pillar):
31
                if service_usage == ServiceUsage.LAUNCHPAD:
32
                    branch = factory.makeProductBranch(product=pillar)
33
                    product_series = factory.makeProductSeries(
34
                        product=pillar,
35
                        branch=branch)
36
                    pillar.development_focus = product_series
37
                elif service_usage == ServiceUsage.EXTERNAL:
38
                    branch = factory.makeProductBranch(
39
                        product=pillar,
40
                        branch_type=BranchType.MIRRORED)
41
                    product_series = factory.makeProductSeries(
42
                        product=pillar,
43
                        branch=branch)
44
                    pillar.development_focus = product_series
45
                elif service_usage == ServiceUsage.UNKNOWN:
46
                    branch = factory.makeProductBranch(product=pillar)
47
                    product_series = factory.makeProductSeries(
48
                        product=pillar)
49
                    pillar.development_focus = product_series
50
            else:
51
                setattr(pillar, attr, service_usage)