~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Graham Binns
  • Date: 2011-09-15 16:31:49 UTC
  • mto: This revision was merged to the branch mainline in revision 14019.
  • Revision ID: graham@canonical.com-20110915163149-vac8fyzc697ok6w8
Batched activity now no longer pulls in results that have already been shown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
    )
113
113
from lp.blueprints.interfaces.specification import ISpecificationSet
114
114
from lp.blueprints.interfaces.sprint import ISprintSet
 
115
from lp.bugs.adapters.bugchange import BugTaskStatusChange
115
116
from lp.bugs.interfaces.bug import (
116
117
    CreateBugParams,
117
118
    IBugSet,
1703
1704
 
1704
1705
        return bug
1705
1706
 
1706
 
    def makeBugTask(self, bug=None, target=None, owner=None, publish=True):
 
1707
    def makeBugTask(self, bug=None, target=None, owner=None, publish=True,
 
1708
                    date_created=None):
1707
1709
        """Create and return a bug task.
1708
1710
 
1709
1711
        If the bug is already targeted to the given target, the existing
1713
1715
            one will be created.
1714
1716
        :param target: The `IBugTarget`, to which the bug will be
1715
1717
            targeted to.
 
1718
        :param owner: The `IPerson` who will own the new BugTask.
 
1719
        :param publish: If `target` is an `ISourcePackage`
 
1720
            or `IDistributionSourcePackage`, should a
 
1721
            SourcePackagePublishingHistory entry be made for the
 
1722
            package?
 
1723
        :param date_created: The date on which the BugTask was created.
1716
1724
        """
1717
1725
        if bug is None:
1718
1726
            bug = self.makeBug()
1749
1757
            if prerequisite is None:
1750
1758
                self.makeBugTask(bug, prerequisite_target, publish=publish)
1751
1759
 
1752
 
        return removeSecurityProxy(bug).addTask(owner, target)
 
1760
        task = removeSecurityProxy(bug).addTask(owner, target)
 
1761
        if date_created is not None:
 
1762
            task.datecreated = date_created
 
1763
        return task
1753
1764
 
1754
1765
    def makeBugNomination(self, bug=None, target=None):
1755
1766
        """Create and return a BugNomination.
4261
4272
            target_distroseries, target_pocket,
4262
4273
            package_version=package_version, requester=requester)
4263
4274
 
 
4275
    def makeNoisyBug(
 
4276
        self, bug_age=365, number_of_tasks=100, number_of_comments=100):
 
4277
        """Create a new `Bug` with lots of tasks and comments."""
 
4278
        days = bug_age
 
4279
        bug = self.makeBug(
 
4280
            date_created=datetime.now(UTC) - timedelta(days=days))
 
4281
        for i in range(number_of_tasks):
 
4282
            days = days - i
 
4283
            current_date = datetime.now(UTC) - timedelta(days=days)
 
4284
            task = self.makeBugTask(bug=bug, date_created=current_date)
 
4285
            change = BugTaskStatusChange(
 
4286
                bug_task=task, when=current_date,
 
4287
                person=bug.owner, what_changed='status',
 
4288
                old_value=BugTaskStatus.NEW, new_value=BugTaskStatus.TRIAGED)
 
4289
            bug.addChange(change)
 
4290
            msg = self.makeMessage(
 
4291
                content="Comment on day %i" % days, datecreated=current_date)
 
4292
            bug.linkMessage(msg)
 
4293
        for i in range(number_of_comments):
 
4294
            days = days - i
 
4295
            current_date = datetime.now(UTC) - timedelta(days=days)
 
4296
            msg = self.makeMessage(
 
4297
                content="Comment on day %i" % days, datecreated=current_date)
 
4298
            bug.linkMessage(msg)
 
4299
        return bug
 
4300
 
4264
4301
 
4265
4302
# Some factory methods return simple Python types. We don't add
4266
4303
# security wrappers for them, as well as for objects created by