~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[r=wallyworld][no-qa] Rollback branch
        bug-subscribers-after-private-475775 due to a misinterpretation
        of the required functionality

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from storm.store import Store
7
7
from testtools.testcase import ExpectedException
8
8
from zope.component import getUtility
9
 
from zope.security.proxy import removeSecurityProxy
10
9
 
11
10
from canonical.testing.layers import DatabaseFunctionalLayer
12
11
from lp.bugs.enum import (
435
434
            info = bug.getSubscriptionInfo(BugNotificationLevel.METADATA)
436
435
        self.assertEqual(BugNotificationLevel.METADATA, info.level)
437
436
 
 
437
    def test_setPrivate_subscribes_person_who_makes_bug_private(self):
 
438
        # When setPrivate(True) is called on a bug, the person who is
 
439
        # marking the bug private is subscribed to the bug.
 
440
        bug = self.factory.makeBug()
 
441
        person = self.factory.makePerson()
 
442
        with person_logged_in(person):
 
443
            bug.setPrivate(True, person)
 
444
            self.assertTrue(bug.personIsDirectSubscriber(person))
 
445
 
 
446
    def test_setPrivate_does_not_subscribe_member_of_subscribed_team(self):
 
447
        # When setPrivate(True) is called on a bug, the person who is
 
448
        # marking the bug private will not be subscribed if they're
 
449
        # already a member of a team which is a direct subscriber.
 
450
        bug = self.factory.makeBug()
 
451
        team = self.factory.makeTeam()
 
452
        person = team.teamowner
 
453
        with person_logged_in(person):
 
454
            bug.subscribe(team, person)
 
455
            bug.setPrivate(True, person)
 
456
            self.assertFalse(bug.personIsDirectSubscriber(person))
 
457
 
438
458
    def test_getVisibleLinkedBranches_doesnt_rtn_inaccessible_branches(self):
439
459
        # If a Bug has branches linked to it that the current user
440
460
        # cannot access, those branches will not be returned in its
465
485
        self.assertNotIn(private_branch, linked_branches)
466
486
 
467
487
 
468
 
class TestBugPrivateAndSecurityRelatedUpdates(TestCaseWithFactory):
469
 
 
470
 
    layer = DatabaseFunctionalLayer
471
 
 
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))
480
 
 
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))
492
 
 
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(
498
 
            owner=bug_owner,
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(
506
 
            owner=owner_a,
507
 
            security_contact=security_contact_a,
508
 
            bug_supervisor=bug_supervisor_a,
509
 
            driver=driver_a)
510
 
        owner_b = self.factory.makePerson(name='ownerb')
511
 
        security_contact_b = self.factory.makePerson(name='securitycontactb')
512
 
        product_b = self.factory.makeProduct(
513
 
            owner=owner_b,
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)
522
 
 
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:
526
 
        # - the bug reporter
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
530
 
 
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))
536
 
 
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,
549
 
                 bugtask_a.owner,
550
 
                 default_bugtask.pillar.owner,
551
 
                 bug_owner, bugtask_b.pillar.owner, who)),
552
 
            subscribers
553
 
        )
554
 
 
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:
558
 
        # - the bug reporter
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
562
 
 
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))
568
 
 
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,
581
 
                 bug_owner, who)),
582
 
            subscribers
583
 
        )
584
 
 
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:
588
 
        # - the bug reporter
589
 
        # - the bugtask pillar security contacts (if set)
590
 
        # - and bug/pillar owners, drivers if they are already subscribed
591
 
 
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))
598
 
 
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,
611
 
                 bug_owner)),
612
 
            subscribers
613
 
        )
614
 
 
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.
618
 
 
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))
624
 
 
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)
635
 
 
636
 
    def test_setPillarOwnerSubscribedIfNoBugSupervisor(self):
637
 
        # The pillar owner is subscribed if the bug supervisor is not set.
638
 
 
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)),
649
 
            subscribers
650
 
        )
651
 
 
652
 
    def test_setPillarOwnerSubscribedIfNoSecurityContact(self):
653
 
        # The pillar owner is subscribed if the security contact is not set.
654
 
 
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)),
665
 
            subscribers
666
 
        )
667
 
 
668
 
 
669
488
class TestBugAutoConfirmation(TestCaseWithFactory):
670
489
    """Tests for auto confirming bugs"""
671
490