465
485
self.assertNotIn(private_branch, linked_branches)
468
class TestBugPrivateAndSecurityRelatedUpdates(TestCaseWithFactory):
470
layer = DatabaseFunctionalLayer
472
def test_setPrivate_subscribes_person_who_makes_bug_private(self):
473
# When setPrivate(True) is called on a bug, the person who is
474
# marking the bug private is subscribed to the bug.
475
bug = self.factory.makeBug()
476
person = self.factory.makePerson()
477
with person_logged_in(person):
478
bug.setPrivate(True, person)
479
self.assertTrue(bug.personIsDirectSubscriber(person))
481
def test_setPrivate_does_not_subscribe_member_of_subscribed_team(self):
482
# When setPrivate(True) is called on a bug, the person who is
483
# marking the bug private will not be subscribed if they're
484
# already a member of a team which is a direct subscriber.
485
bug = self.factory.makeBug()
486
team = self.factory.makeTeam()
487
person = team.teamowner
488
with person_logged_in(person):
489
bug.subscribe(team, person)
490
bug.setPrivate(True, person)
491
self.assertFalse(bug.personIsDirectSubscriber(person))
493
def createBugTasksAndSubscribers(self, private_security_related=False):
494
# Used with the various setPrivateAndSecurityRelated tests to create
495
# a bug and add some initial subscribers.
496
bug_owner = self.factory.makePerson(name='bugowner')
497
bug = self.factory.makeBug(
499
private=private_security_related,
500
security_related=private_security_related)
501
owner_a = self.factory.makePerson(name='ownera')
502
security_contact_a = self.factory.makePerson(name='securitycontacta')
503
bug_supervisor_a = self.factory.makePerson(name='bugsupervisora')
504
driver_a = self.factory.makePerson(name='drivera')
505
product_a = self.factory.makeProduct(
507
security_contact=security_contact_a,
508
bug_supervisor=bug_supervisor_a,
510
owner_b = self.factory.makePerson(name='ownerb')
511
security_contact_b = self.factory.makePerson(name='securitycontactb')
512
product_b = self.factory.makeProduct(
514
security_contact=security_contact_b)
515
bugtask_a = self.factory.makeBugTask(bug=bug, target=product_a)
516
bugtask_b = self.factory.makeBugTask(bug=bug, target=product_b)
517
naked_bugtask_a = removeSecurityProxy(bugtask_a)
518
naked_bugtask_b = removeSecurityProxy(bugtask_b)
519
naked_default_bugtask = removeSecurityProxy(bug.default_bugtask)
520
return (bug, bug_owner, naked_bugtask_a, naked_bugtask_b,
521
naked_default_bugtask)
523
def test_setPrivateTrueAndSecurityRelatedTrue(self):
524
# When a bug is marked as private=true and security_related=true, the
525
# only direct subscribers should be:
527
# - the bugtask pillar security contacts (if set)
528
# - the person changing the state
529
# - and bug/pillar owners, drivers if they are already subscribed
531
(bug, bug_owner, bugtask_a, bugtask_b, default_bugtask) = (
532
self.createBugTasksAndSubscribers())
533
initial_subscribers = set(
534
(self.factory.makePerson(), bugtask_a.owner, bug_owner,
535
bugtask_a.pillar.security_contact, bugtask_a.pillar.driver))
537
with person_logged_in(bug_owner):
538
for subscriber in initial_subscribers:
539
bug.subscribe(subscriber, bug_owner)
540
who = self.factory.makePerson()
541
bug.setPrivacyAndSecurityRelated(
542
private=True, security_related=True, who=who)
543
subscribers = bug.getDirectSubscribers()
544
self.assertContentEqual(
545
set((bugtask_a.pillar.security_contact,
546
bugtask_a.pillar.bug_supervisor,
547
bugtask_a.pillar.driver,
548
bugtask_b.pillar.security_contact,
550
default_bugtask.pillar.owner,
551
bug_owner, bugtask_b.pillar.owner, who)),
555
def test_setPrivateTrueAndSecurityRelatedFalse(self):
556
# When a bug is marked as private=true and security_related=false, the
557
# only direct subscribers should be:
559
# - the bugtask pillar bug supervisors (if set)
560
# - the person changing the state
561
# - and bug/pillar owners, drivers if they are already subscribed
563
(bug, bug_owner, bugtask_a, bugtask_b, default_bugtask) = (
564
self.createBugTasksAndSubscribers())
565
initial_subscribers = set(
566
(self.factory.makePerson(), bug_owner,
567
bugtask_a.pillar.security_contact, bugtask_a.pillar.driver))
569
with person_logged_in(bug_owner):
570
for subscriber in initial_subscribers:
571
bug.subscribe(subscriber, bug_owner)
572
who = self.factory.makePerson()
573
bug.setPrivacyAndSecurityRelated(
574
private=True, security_related=False, who=who)
575
subscribers = bug.getDirectSubscribers()
576
self.assertContentEqual(
577
set((bugtask_a.pillar.bug_supervisor,
578
bugtask_a.pillar.driver,
579
bugtask_b.pillar.owner,
580
default_bugtask.pillar.owner,
585
def test_setPrivateFalseAndSecurityRelatedTrue(self):
586
# When a bug is marked as private=false and security_related=true, the
587
# only direct subscribers should be:
589
# - the bugtask pillar security contacts (if set)
590
# - and bug/pillar owners, drivers if they are already subscribed
592
(bug, bug_owner, bugtask_a, bugtask_b, default_bugtask) = (
593
self.createBugTasksAndSubscribers())
594
initial_subscribers = set(
595
(self.factory.makePerson(), bug_owner,
596
bugtask_a.pillar.security_contact, bugtask_a.pillar.driver,
597
bugtask_a.pillar.bug_supervisor))
599
with person_logged_in(bug_owner):
600
for subscriber in initial_subscribers:
601
bug.subscribe(subscriber, bug_owner)
602
who = self.factory.makePerson()
603
bug.setPrivacyAndSecurityRelated(
604
private=False, security_related=True, who=who)
605
subscribers = bug.getDirectSubscribers()
606
self.assertContentEqual(
607
set((bugtask_a.pillar.security_contact,
608
bugtask_a.pillar.driver,
609
bugtask_b.pillar.security_contact,
610
default_bugtask.pillar.owner,
615
def test_setPrivateFalseAndSecurityRelatedFalse(self):
616
# When a bug is marked as private=false and security_related=false,
617
# any existing subscriptions are left alone.
619
(bug, bug_owner, bugtask_a, bugtask_b, default_bugtask) = (
620
self.createBugTasksAndSubscribers(private_security_related=True))
621
initial_subscribers = set(
622
(self.factory.makePerson(), bug_owner,
623
bugtask_a.pillar.security_contact, bugtask_a.pillar.driver))
625
with person_logged_in(bug_owner):
626
for subscriber in initial_subscribers:
627
bug.subscribe(subscriber, bug_owner)
628
who = self.factory.makePerson()
629
expected_direct_subscribers = set(bug.getDirectSubscribers())
630
bug.setPrivacyAndSecurityRelated(
631
private=False, security_related=False, who=who)
632
subscribers = bug.getDirectSubscribers()
633
for subscriber in expected_direct_subscribers:
634
self.assertTrue(subscriber in subscribers)
636
def test_setPillarOwnerSubscribedIfNoBugSupervisor(self):
637
# The pillar owner is subscribed if the bug supervisor is not set.
639
bug_owner = self.factory.makePerson(name='bugowner')
640
bug = self.factory.makeBug(owner=bug_owner)
641
with person_logged_in(bug_owner):
642
who = self.factory.makePerson()
643
bug.setPrivacyAndSecurityRelated(
644
private=True, security_related=False, who=who)
645
subscribers = bug.getDirectSubscribers()
646
naked_bugtask = removeSecurityProxy(bug.default_bugtask)
647
self.assertContentEqual(
648
set((naked_bugtask.pillar.owner, bug_owner, who)),
652
def test_setPillarOwnerSubscribedIfNoSecurityContact(self):
653
# The pillar owner is subscribed if the security contact is not set.
655
bug_owner = self.factory.makePerson(name='bugowner')
656
bug = self.factory.makeBug(owner=bug_owner)
657
with person_logged_in(bug_owner):
658
who = self.factory.makePerson()
659
bug.setPrivacyAndSecurityRelated(
660
private=False, security_related=True, who=who)
661
subscribers = bug.getDirectSubscribers()
662
naked_bugtask = removeSecurityProxy(bug.default_bugtask)
663
self.assertContentEqual(
664
set((naked_bugtask.pillar.owner, bug_owner)),
669
488
class TestBugAutoConfirmation(TestCaseWithFactory):
670
489
"""Tests for auto confirming bugs"""