1445
1449
self.generic_task.sourcepackagename = source_package_name
1446
1450
self.assertEqual(
1447
1451
source_package_name, self.series_task.sourcepackagename)
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.")
1458
class TestAutoConfirmBugTasksFlagForProduct(TestCaseWithFactory):
1459
"""Tests for auto-confirming bug tasks."""
1460
# Tests for _checkAutoconfirmFeatureFlag.
1462
layer = DatabaseFunctionalLayer
1464
def makeTarget(self):
1465
return self.factory.makeProduct()
1467
flag = u'bugs.autoconfirm.enabled_product_names'
1468
alt_flag = u'bugs.autoconfirm.enabled_distribution_names'
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())
1474
removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
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' ')
1481
removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
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)
1488
removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
1490
def test_explicit_flag_of_many(self):
1491
bug_task = self.factory.makeBugTask(target=self.makeTarget())
1492
with feature_flags():
1494
self.flag, u' foo bar ' + bug_task.pillar.name + ' baz ')
1496
removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
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'*')
1503
removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
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)
1510
removeSecurityProxy(bug_task)._checkAutoconfirmFeatureFlag())
1513
class TestAutoConfirmBugTasksFlagForProductSeries(
1514
TestAutoConfirmBugTasksFlagForProduct):
1515
"""Tests for auto-confirming bug tasks."""
1517
def makeTarget(self):
1518
return self.factory.makeProductSeries()
1521
class TestAutoConfirmBugTasksFlagForDistribution(
1522
TestAutoConfirmBugTasksFlagForProduct):
1523
"""Tests for auto-confirming bug tasks."""
1525
flag = TestAutoConfirmBugTasksFlagForProduct.alt_flag
1526
alt_flag = TestAutoConfirmBugTasksFlagForProduct.flag
1528
def makeTarget(self):
1529
return self.factory.makeDistribution()
1532
class TestAutoConfirmBugTasksFlagForDistributionSeries(
1533
TestAutoConfirmBugTasksFlagForDistribution):
1534
"""Tests for auto-confirming bug tasks."""
1536
def makeTarget(self):
1537
return self.factory.makeDistroSeries()
1540
class TestAutoConfirmBugTasksFlagForDistributionSourcePackage(
1541
TestAutoConfirmBugTasksFlagForDistribution):
1542
"""Tests for auto-confirming bug tasks."""
1544
def makeTarget(self):
1545
return self.factory.makeDistributionSourcePackage()
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.
1555
layer = DatabaseFunctionalLayer
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)
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.
1595
class TestAutoConfirmBugTasks(TestCaseWithFactory):
1596
"""Tests for auto-confirming bug tasks."""
1597
# Tests for maybeConfirm
1599
layer = DatabaseFunctionalLayer
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
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,
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)
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
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))
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
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))