~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/factory.py

[r=wgrant][ui=huwshimi][bug=878605] We don't want to support
 multi-tenanted private bugs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
    CreateBugParams,
117
117
    IBugSet,
118
118
    )
 
119
from lp.bugs.interfaces.bugtarget import ISeriesBugTarget
119
120
from lp.bugs.interfaces.bugtask import BugTaskStatus
120
121
from lp.bugs.interfaces.bugtracker import (
121
122
    BugTrackerType,
175
176
    DistroSeriesDifferenceStatus,
176
177
    DistroSeriesDifferenceType,
177
178
    )
178
 
from lp.registry.interfaces.distribution import IDistributionSet
 
179
from lp.registry.interfaces.distribution import (
 
180
    IDistribution,
 
181
    IDistributionSet,
 
182
    )
179
183
from lp.registry.interfaces.distributionmirror import (
180
184
    MirrorContent,
181
185
    MirrorSpeed,
219
223
    PollSecrecy,
220
224
    )
221
225
from lp.registry.interfaces.product import (
 
226
    IProduct,
222
227
    IProductSet,
223
228
    License,
224
229
    )
1704
1709
 
1705
1710
        return bug
1706
1711
 
1707
 
    def makeBugTask(self, bug=None, target=None, owner=None, publish=True):
 
1712
    def makeBugTask(self, bug=None, target=None, owner=None, publish=True,
 
1713
                    private=False):
1708
1714
        """Create and return a bug task.
1709
1715
 
1710
1716
        If the bug is already targeted to the given target, the existing
1711
1717
        bug task is returned.
1712
1718
 
 
1719
        Private (and soon all) bugs cannot affect multiple projects
 
1720
        so we ensure that if a bug has not been specified and one is
 
1721
        created, it is for the same pillar as that of the specified target.
 
1722
 
1713
1723
        :param bug: The `IBug` the bug tasks should be part of. If None,
1714
1724
            one will be created.
1715
1725
        :param target: The `IBugTarget`, to which the bug will be
1716
1726
            targeted to.
 
1727
        :param private: If a bug is not specified, the privacy state to use
 
1728
            when creating the bug for the bug task..
1717
1729
        """
1718
 
        if bug is None:
1719
 
            bug = self.makeBug()
 
1730
 
 
1731
        # Find and return the existing target if one exists.
 
1732
        if bug is not None and target is not None:
 
1733
            existing_bugtask = bug.getBugTask(target)
 
1734
            if existing_bugtask is not None:
 
1735
                return existing_bugtask
 
1736
 
 
1737
        # If we are adding a task to an existing bug, and no target is
 
1738
        # is specified, we use the same pillar as already exists to ensure
 
1739
        # that we don't end up with a bug affecting multiple projects.
1720
1740
        if target is None:
1721
 
            target = self.makeProduct()
1722
 
        existing_bugtask = bug.getBugTask(target)
1723
 
        if existing_bugtask is not None:
1724
 
            return existing_bugtask
1725
 
 
1726
 
        if owner is None:
1727
 
            owner = self.makePerson()
 
1741
            default_bugtask = bug and removeSecurityProxy(bug.default_bugtask)
 
1742
            if default_bugtask is not None:
 
1743
                existing_pillar = default_bugtask.pillar
 
1744
                if IProduct.providedBy(existing_pillar):
 
1745
                    target = self.makeProductSeries(product=existing_pillar)
 
1746
                elif IDistribution.providedBy(existing_pillar):
 
1747
                    target = self.makeDistroSeries(
 
1748
                        distribution=existing_pillar)
 
1749
            if target is None:
 
1750
                target = self.makeProduct()
1728
1751
 
1729
1752
        prerequisite_target = None
1730
1753
        if IProductSeries.providedBy(target):
1746
1769
                    distroseries=target.distribution.currentseries,
1747
1770
                    sourcepackagename=target.sourcepackagename)
1748
1771
        if prerequisite_target is not None:
1749
 
            prerequisite = bug.getBugTask(prerequisite_target)
 
1772
            prerequisite = bug and bug.getBugTask(prerequisite_target)
1750
1773
            if prerequisite is None:
1751
 
                self.makeBugTask(bug, prerequisite_target, publish=publish)
1752
 
 
 
1774
                prerequisite = self.makeBugTask(
 
1775
                    bug, prerequisite_target, publish=publish)
 
1776
                bug = prerequisite.bug
 
1777
 
 
1778
        # Private (and soon all) bugs cannot affect multiple projects
 
1779
        # so we ensure that if a bug has not been specified and one is
 
1780
        # created, it is for the same pillar as that of the specified target.
 
1781
        result_bug_task = None
 
1782
        if bug is None and private:
 
1783
            product = distribution = sourcepackagename = None
 
1784
            pillar = target.pillar
 
1785
            if IProduct.providedBy(pillar):
 
1786
                product = pillar
 
1787
            elif IDistribution.providedBy(pillar):
 
1788
                distribution = pillar
 
1789
            if (IDistributionSourcePackage.providedBy(target)
 
1790
                or ISourcePackage.providedBy(target)):
 
1791
                    sourcepackagename = target.sourcepackagename
 
1792
            bug = self.makeBug(
 
1793
                private=private, product=product, distribution=distribution,
 
1794
                sourcepackagename=sourcepackagename)
 
1795
            if not ISeriesBugTarget.providedBy(target):
 
1796
                result_bug_task = bug.default_bugtask
 
1797
        # We keep the existing behaviour for public bugs because
 
1798
        # test_bugtask_search breaks spectacularly otherwise. Almost all other
 
1799
        # tests pass.
 
1800
        if bug is None:
 
1801
            bug = self.makeBug()
 
1802
 
 
1803
        if result_bug_task is not None:
 
1804
            return result_bug_task
 
1805
        if owner is None:
 
1806
            owner = self.makePerson()
1753
1807
        return removeSecurityProxy(bug).addTask(owner, target)
1754
1808
 
1755
1809
    def makeBugNomination(self, bug=None, target=None):