~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/tests/test_bugtask.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-19 20:31:43 UTC
  • mfrom: (13445.1.10 bug777874)
  • Revision ID: launchpad@pqm.canonical.com-20110719203143-uwkz5us2ewbgx50v
[r=gmb][bug=777874] enable autocompletion of "New" bugtasks that
        affect more than one person. Feature-flagged by project/distro.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
from testtools.matchers import Equals
11
11
from zope.component import getUtility
12
12
from zope.interface import providedBy
 
13
from zope.security.proxy import removeSecurityProxy
13
14
 
14
15
from canonical.database.sqlbase import flush_database_updates
15
16
from canonical.launchpad.searchbuilder import (
52
53
from lp.registry.interfaces.projectgroup import IProjectGroupSet
53
54
from lp.testing import (
54
55
    ANONYMOUS,
 
56
    EventRecorder,
 
57
    feature_flags,
55
58
    login,
56
59
    login_person,
57
60
    logout,
58
61
    normalize_whitespace,
59
62
    person_logged_in,
 
63
    set_feature_flag,
60
64
    StormStatementRecorder,
61
65
    TestCase,
62
66
    TestCaseWithFactory,
1445
1449
            self.generic_task.sourcepackagename = source_package_name
1446
1450
            self.assertEqual(
1447
1451
                source_package_name, self.series_task.sourcepackagename)
 
1452
 
 
1453
# START TEMPORARY BIT FOR BUGTASK AUTOCONFIRM FEATURE FLAG.
 
1454
# When feature flag code is removed, delete these tests (up to "# END
 
1455
# TEMPORARY BIT FOR BUGTASK AUTOCONFIRM FEATURE FLAG.")
 
1456
 
 
1457
 
 
1458
class TestAutoConfirmBugTasksFlagForProduct(TestCaseWithFactory):
 
1459
    """Tests for auto-confirming bug tasks."""
 
1460
    # Tests for _checkAutoconfirmFeatureFlag.
 
1461
 
 
1462
    layer = DatabaseFunctionalLayer
 
1463
 
 
1464
    def makeTarget(self):
 
1465
        return self.factory.makeProduct()
 
1466
 
 
1467
    flag = u'bugs.autoconfirm.enabled_product_names'
 
1468
    alt_flag = u'bugs.autoconfirm.enabled_distribution_names'
 
1469
 
 
1470
    def test_False(self):
 
1471
        # With no feature flags turned on, we do not auto-confirm.
 
1472
        bug_task = self.factory.makeBugTask(target=self.makeTarget())
 
1473
        self.assertFalse(
 
1474
            removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
 
1475
 
 
1476
    def test_flag_False(self):
 
1477
        bug_task = self.factory.makeBugTask(target=self.makeTarget())
 
1478
        with feature_flags():
 
1479
            set_feature_flag(self.flag, u'   ')
 
1480
            self.assertFalse(
 
1481
                removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
 
1482
 
 
1483
    def test_explicit_flag(self):
 
1484
        bug_task = self.factory.makeBugTask(target=self.makeTarget())
 
1485
        with feature_flags():
 
1486
            set_feature_flag(self.flag, bug_task.pillar.name)
 
1487
            self.assertTrue(
 
1488
                removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
 
1489
 
 
1490
    def test_explicit_flag_of_many(self):
 
1491
        bug_task = self.factory.makeBugTask(target=self.makeTarget())
 
1492
        with feature_flags():
 
1493
            set_feature_flag(
 
1494
                self.flag, u'  foo bar  ' + bug_task.pillar.name + '    baz ')
 
1495
            self.assertTrue(
 
1496
                removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
 
1497
 
 
1498
    def test_match_all_flag(self):
 
1499
        bug_task = self.factory.makeBugTask(target=self.makeTarget())
 
1500
        with feature_flags():
 
1501
            set_feature_flag(self.flag, u'*')
 
1502
            self.assertTrue(
 
1503
                removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
 
1504
 
 
1505
    def test_alt_flag_does_not_affect(self):
 
1506
        bug_task = self.factory.makeBugTask(target=self.makeTarget())
 
1507
        with feature_flags():
 
1508
            set_feature_flag(self.alt_flag, bug_task.pillar.name)
 
1509
            self.assertFalse(
 
1510
                removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
 
1511
 
 
1512
 
 
1513
class TestAutoConfirmBugTasksFlagForProductSeries(
 
1514
    TestAutoConfirmBugTasksFlagForProduct):
 
1515
    """Tests for auto-confirming bug tasks."""
 
1516
 
 
1517
    def makeTarget(self):
 
1518
        return self.factory.makeProductSeries()
 
1519
 
 
1520
 
 
1521
class TestAutoConfirmBugTasksFlagForDistribution(
 
1522
    TestAutoConfirmBugTasksFlagForProduct):
 
1523
    """Tests for auto-confirming bug tasks."""
 
1524
 
 
1525
    flag = TestAutoConfirmBugTasksFlagForProduct.alt_flag
 
1526
    alt_flag = TestAutoConfirmBugTasksFlagForProduct.flag
 
1527
 
 
1528
    def makeTarget(self):
 
1529
        return self.factory.makeDistribution()
 
1530
 
 
1531
 
 
1532
class TestAutoConfirmBugTasksFlagForDistributionSeries(
 
1533
    TestAutoConfirmBugTasksFlagForDistribution):
 
1534
    """Tests for auto-confirming bug tasks."""
 
1535
 
 
1536
    def makeTarget(self):
 
1537
        return self.factory.makeDistroSeries()
 
1538
 
 
1539
 
 
1540
class TestAutoConfirmBugTasksFlagForDistributionSourcePackage(
 
1541
    TestAutoConfirmBugTasksFlagForDistribution):
 
1542
    """Tests for auto-confirming bug tasks."""
 
1543
 
 
1544
    def makeTarget(self):
 
1545
        return self.factory.makeDistributionSourcePackage()
 
1546
 
 
1547
 
 
1548
class TestAutoConfirmBugTasksTransitionToTarget(TestCaseWithFactory):
 
1549
    """Tests for auto-confirming bug tasks."""
 
1550
    # Tests for making sure that switching a task from one project that
 
1551
    # does not auto-confirm to another that does performs the auto-confirm
 
1552
    # correctly, if appropriate.  This is only necessary for as long as a
 
1553
    # project may not participate in auto-confirm.
 
1554
 
 
1555
    layer = DatabaseFunctionalLayer
 
1556
 
 
1557
    def test_no_transitionToTarget(self):
 
1558
        # We can change the target.  If the normal bug conditions do not
 
1559
        # hold, there will be no transition.
 
1560
        person = self.factory.makePerson()
 
1561
        autoconfirm_product = self.factory.makeProduct(owner=person)
 
1562
        no_autoconfirm_product = self.factory.makeProduct(owner=person)
 
1563
        with feature_flags():
 
1564
            set_feature_flag(u'bugs.autoconfirm.enabled_product_names',
 
1565
                             autoconfirm_product.name)
 
1566
            bug_task = self.factory.makeBugTask(
 
1567
                target=no_autoconfirm_product, owner=person)
 
1568
            with person_logged_in(person):
 
1569
                bug_task.maybeConfirm()
 
1570
                self.assertEqual(BugTaskStatus.NEW, bug_task.status)
 
1571
                bug_task.transitionToTarget(autoconfirm_product)
 
1572
                self.assertEqual(BugTaskStatus.NEW, bug_task.status)
 
1573
 
 
1574
    def test_transitionToTarget(self):
 
1575
        # If the conditions *do* hold, though, we will auto-confirm.
 
1576
        person = self.factory.makePerson()
 
1577
        another_person = self.factory.makePerson()
 
1578
        autoconfirm_product = self.factory.makeProduct(owner=person)
 
1579
        no_autoconfirm_product = self.factory.makeProduct(owner=person)
 
1580
        with feature_flags():
 
1581
            set_feature_flag(u'bugs.autoconfirm.enabled_product_names',
 
1582
                             autoconfirm_product.name)
 
1583
            bug_task = self.factory.makeBugTask(
 
1584
                target=no_autoconfirm_product, owner=person)
 
1585
            with person_logged_in(another_person):
 
1586
                bug_task.bug.markUserAffected(another_person)
 
1587
            with person_logged_in(person):
 
1588
                bug_task.maybeConfirm()
 
1589
                self.assertEqual(BugTaskStatus.NEW, bug_task.status)
 
1590
                bug_task.transitionToTarget(autoconfirm_product)
 
1591
                self.assertEqual(BugTaskStatus.CONFIRMED, bug_task.status)
 
1592
# END TEMPORARY BIT FOR BUGTASK AUTOCONFIRM FEATURE FLAG.
 
1593
 
 
1594
 
 
1595
class TestAutoConfirmBugTasks(TestCaseWithFactory):
 
1596
    """Tests for auto-confirming bug tasks."""
 
1597
    # Tests for maybeConfirm
 
1598
 
 
1599
    layer = DatabaseFunctionalLayer
 
1600
 
 
1601
    def test_auto_confirm(self):
 
1602
        # A typical new bugtask auto-confirms.
 
1603
        # When feature flag code is removed, remove the next two lines and
 
1604
        # dedent the rest.
 
1605
        with feature_flags():
 
1606
            set_feature_flag(u'bugs.autoconfirm.enabled_product_names', u'*')
 
1607
            bug_task = self.factory.makeBugTask()
 
1608
            self.assertEqual(BugTaskStatus.NEW, bug_task.status)
 
1609
            with EventRecorder() as recorder:
 
1610
                bug_task.maybeConfirm()
 
1611
                self.assertEqual(BugTaskStatus.CONFIRMED, bug_task.status)
 
1612
                self.assertEqual(1, len(recorder.events))
 
1613
                event = recorder.events[0]
 
1614
                self.assertEqual(getUtility(ILaunchpadCelebrities).janitor,
 
1615
                                 event.user)
 
1616
                self.assertEqual(['status'], event.edited_fields)
 
1617
                self.assertEqual(BugTaskStatus.NEW,
 
1618
                                 event.object_before_modification.status)
 
1619
                self.assertEqual(bug_task, event.object)
 
1620
 
 
1621
    def test_do_not_confirm_bugwatch_tasks(self):
 
1622
        # A bugwatch bugtask does not auto-confirm.
 
1623
        # When feature flag code is removed, remove the next two lines and
 
1624
        # dedent the rest.
 
1625
        with feature_flags():
 
1626
            set_feature_flag(u'bugs.autoconfirm.enabled_product_names', u'*')
 
1627
            product = self.factory.makeProduct()
 
1628
            with person_logged_in(product.owner):
 
1629
                bug = self.factory.makeBug(
 
1630
                    product=product, owner=product.owner)
 
1631
                bug_task = bug.getBugTask(product)
 
1632
                watch = self.factory.makeBugWatch(bug=bug)
 
1633
                bug_task.bugwatch = watch
 
1634
            self.assertEqual(BugTaskStatus.NEW, bug_task.status)
 
1635
            with EventRecorder() as recorder:
 
1636
                bug_task.maybeConfirm()
 
1637
                self.assertEqual(BugTaskStatus.NEW, bug_task.status)
 
1638
                self.assertEqual(0, len(recorder.events))
 
1639
 
 
1640
    def test_only_confirm_new_tasks(self):
 
1641
        # A non-new bugtask does not auto-confirm.
 
1642
        # When feature flag code is removed, remove the next two lines and
 
1643
        # dedent the rest.
 
1644
        with feature_flags():
 
1645
            set_feature_flag(u'bugs.autoconfirm.enabled_product_names', u'*')
 
1646
            bug_task = self.factory.makeBugTask()
 
1647
            removeSecurityProxy(bug_task).transitionToStatus(
 
1648
                BugTaskStatus.CONFIRMED, bug_task.bug.owner)
 
1649
            self.assertEqual(BugTaskStatus.CONFIRMED, bug_task.status)
 
1650
            with EventRecorder() as recorder:
 
1651
                bug_task.maybeConfirm()
 
1652
                self.assertEqual(BugTaskStatus.CONFIRMED, bug_task.status)
 
1653
                self.assertEqual(0, len(recorder.events))