27
27
from lp.app.enums import ServiceUsage
28
28
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
29
from lp.bugs.enum import BugAutoConfirmReason
30
29
from lp.bugs.interfaces.bug import IBugSet
31
30
from lp.bugs.interfaces.bugtarget import IBugTarget
32
31
from lp.bugs.interfaces.bugtask import (
1565
1564
bug_task = self.factory.makeBugTask(
1566
1565
target=no_autoconfirm_product, owner=person)
1567
1566
with person_logged_in(person):
1568
bug_task.maybeConfirm(
1569
BugAutoConfirmReason.AFFECTS_MULTIPLE_USERS)
1567
bug_task.maybeConfirm()
1570
1568
self.assertEqual(BugTaskStatus.NEW, bug_task.status)
1571
1569
bug_task.transitionToTarget(autoconfirm_product)
1572
1570
self.assertEqual(BugTaskStatus.NEW, bug_task.status)
1585
1583
with person_logged_in(another_person):
1586
1584
bug_task.bug.markUserAffected(another_person)
1587
1585
with person_logged_in(person):
1588
bug_task.maybeConfirm(
1589
reason=BugAutoConfirmReason.AFFECTS_MULTIPLE_USERS)
1586
bug_task.maybeConfirm()
1590
1587
self.assertEqual(BugTaskStatus.NEW, bug_task.status)
1591
1588
bug_task.transitionToTarget(autoconfirm_product)
1592
1589
self.assertEqual(BugTaskStatus.CONFIRMED, bug_task.status)
1612
1609
self.assertEqual(BugTaskStatus.NEW, bug_task.status)
1613
1610
original_comment_count = bug.messages.count()
1614
1611
with EventRecorder() as recorder:
1615
bug_task.maybeConfirm(
1616
reason=BugAutoConfirmReason.AFFECTS_MULTIPLE_USERS)
1612
bug_task.maybeConfirm()
1617
1613
self.assertEqual(BugTaskStatus.CONFIRMED, bug_task.status)
1618
1614
self.assertEqual(2, len(recorder.events))
1619
1615
msg_event, mod_event = recorder.events
1630
1626
u"Auto-confirmed because the bug affects multiple users.",
1631
1627
bug.messages[-1].text_contents)
1633
def test_auto_confirm_duplicates(self):
1634
# A typical new bugtask auto-confirms. This time with it
1635
# auto-confirms due to having duplicates.
1636
with feature_flags():
1637
set_feature_flag(u'bugs.autoconfirm.enabled_product_names', u'*')
1638
bug_task = self.factory.makeBugTask()
1640
self.assertEqual(BugTaskStatus.NEW, bug_task.status)
1641
original_comment_count = bug.messages.count()
1642
with EventRecorder() as recorder:
1643
bug_task.maybeConfirm(
1644
reason=BugAutoConfirmReason.HAS_DUPLICATE)
1645
self.assertEqual(BugTaskStatus.CONFIRMED, bug_task.status)
1646
self.assertEqual(2, len(recorder.events))
1647
msg_event, mod_event = recorder.events
1648
self.assertEqual(getUtility(ILaunchpadCelebrities).janitor,
1650
self.assertEqual(['status'], mod_event.edited_fields)
1651
self.assertEqual(BugTaskStatus.NEW,
1652
mod_event.object_before_modification.status)
1653
self.assertEqual(bug_task, mod_event.object)
1654
# A new comment is recorded.
1656
original_comment_count + 1, bug.messages.count())
1658
u"Auto-confirmed because the bug has a duplicate bug.",
1659
bug.messages[-1].text_contents)
1661
1629
def test_do_not_confirm_bugwatch_tasks(self):
1662
1630
# A bugwatch bugtask does not auto-confirm.
1663
1631
# When feature flag code is removed, remove the next two lines and
1673
1641
bug_task.bugwatch = watch
1674
1642
self.assertEqual(BugTaskStatus.NEW, bug_task.status)
1675
1643
with EventRecorder() as recorder:
1676
bug_task.maybeConfirm(
1677
reason=BugAutoConfirmReason.AFFECTS_MULTIPLE_USERS)
1644
bug_task.maybeConfirm()
1678
1645
self.assertEqual(BugTaskStatus.NEW, bug_task.status)
1679
1646
self.assertEqual(0, len(recorder.events))
1689
1656
BugTaskStatus.CONFIRMED, bug_task.bug.owner)
1690
1657
self.assertEqual(BugTaskStatus.CONFIRMED, bug_task.status)
1691
1658
with EventRecorder() as recorder:
1692
bug_task.maybeConfirm(
1693
reason=BugAutoConfirmReason.AFFECTS_MULTIPLE_USERS)
1659
bug_task.maybeConfirm()
1694
1660
self.assertEqual(BugTaskStatus.CONFIRMED, bug_task.status)
1695
1661
self.assertEqual(0, len(recorder.events))