~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/tests/test_structuralsubscription.py

  • Committer: Raphael Badin
  • Date: 2012-01-06 08:27:55 UTC
  • mfrom: (14513.5.4 builder-history-lfa)
  • mto: This revision was merged to the branch mainline in revision 14654.
  • Revision ID: raphael.badin@canonical.com-20120106082755-95a0eh6nakv5hj3b
Merge devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from lp.bugs.model.structuralsubscription import (
28
28
    get_structural_subscribers,
29
29
    get_structural_subscription_targets,
 
30
    get_structural_subscriptions,
30
31
    get_structural_subscriptions_for_bug,
31
32
    )
 
33
from lp.services.database.decoratedresultset import DecoratedResultSet
32
34
from lp.testing import (
33
35
    anonymous_logged_in,
34
36
    login_person,
42
44
    )
43
45
 
44
46
 
 
47
RESULT_SETS = ResultSet, EmptyResultSet, DecoratedResultSet
 
48
 
 
49
 
45
50
class TestStructuralSubscription(TestCaseWithFactory):
46
51
 
47
52
    layer = DatabaseFunctionalLayer
634
639
        self.assertEqual(set([self_sub]), set(subscriptions))
635
640
 
636
641
 
 
642
class TestGetStructuralSubscriptions(TestCaseWithFactory):
 
643
 
 
644
    layer = DatabaseFunctionalLayer
 
645
 
 
646
    def make_product_with_bug(self):
 
647
        product = self.factory.makeProduct()
 
648
        bug = self.factory.makeBug(product=product)
 
649
        return product, bug
 
650
 
 
651
    def test_get_structural_subscriptions_no_subscriptions(self):
 
652
        # If there are no subscriptions for any of the bug's targets then no
 
653
        # subscriptions will be returned by get_structural_subscriptions().
 
654
        product, bug = self.make_product_with_bug()
 
655
        subscriptions = get_structural_subscriptions(bug, None)
 
656
        self.assertIsInstance(subscriptions, RESULT_SETS)
 
657
        self.assertEqual([], list(subscriptions))
 
658
 
 
659
    def test_get_structural_subscriptions_single_target(self):
 
660
        # Subscriptions for any of the bug's targets are returned.
 
661
        subscriber = self.factory.makePerson()
 
662
        login_person(subscriber)
 
663
        product, bug = self.make_product_with_bug()
 
664
        subscription = product.addBugSubscription(subscriber, subscriber)
 
665
        self.assertContentEqual(
 
666
            [subscription], get_structural_subscriptions(bug, None))
 
667
 
 
668
    def test_get_structural_subscriptions_multiple_targets(self):
 
669
        # Subscriptions for any of the bug's targets are returned.
 
670
        actor = self.factory.makePerson()
 
671
        login_person(actor)
 
672
 
 
673
        subscriber1 = self.factory.makePerson()
 
674
        subscriber2 = self.factory.makePerson()
 
675
 
 
676
        product1 = self.factory.makeProduct(owner=actor)
 
677
        subscription1 = product1.addBugSubscription(subscriber1, subscriber1)
 
678
        product2 = self.factory.makeProduct(owner=actor)
 
679
        subscription2 = product2.addBugSubscription(subscriber2, subscriber2)
 
680
 
 
681
        bug = self.factory.makeBug(product=product1)
 
682
        bug.addTask(actor, product2)
 
683
 
 
684
        subscriptions = get_structural_subscriptions(bug, None)
 
685
        self.assertIsInstance(subscriptions, RESULT_SETS)
 
686
        self.assertContentEqual(
 
687
            [subscription1, subscription2], subscriptions)
 
688
 
 
689
    def test_get_structural_subscriptions_multiple_targets_2(self):
 
690
        # Only the first of multiple subscriptions for a person is returned
 
691
        # when they have multiple matching subscriptions.
 
692
        actor = self.factory.makePerson()
 
693
        login_person(actor)
 
694
 
 
695
        subscriber = self.factory.makePerson()
 
696
        product1 = self.factory.makeProduct(owner=actor)
 
697
        subscription1 = product1.addBugSubscription(subscriber, subscriber)
 
698
        product2 = self.factory.makeProduct(owner=actor)
 
699
        product2.addBugSubscription(subscriber, subscriber)
 
700
 
 
701
        bug = self.factory.makeBug(product=product1)
 
702
        bug.addTask(actor, product2)
 
703
 
 
704
        subscriptions = get_structural_subscriptions(bug, None)
 
705
        self.assertIsInstance(subscriptions, RESULT_SETS)
 
706
        self.assertContentEqual([subscription1], subscriptions)
 
707
 
 
708
    def test_get_structural_subscriptions_level(self):
 
709
        # get_structural_subscriptions() respects the given level.
 
710
        subscriber = self.factory.makePerson()
 
711
        login_person(subscriber)
 
712
        product, bug = self.make_product_with_bug()
 
713
        subscription = product.addBugSubscription(subscriber, subscriber)
 
714
        filter = subscription.bug_filters.one()
 
715
        filter.bug_notification_level = BugNotificationLevel.METADATA
 
716
        self.assertContentEqual(
 
717
            [subscription], get_structural_subscriptions(
 
718
                bug, BugNotificationLevel.METADATA))
 
719
        self.assertContentEqual(
 
720
            [], get_structural_subscriptions(
 
721
                bug, BugNotificationLevel.COMMENTS))
 
722
 
 
723
    def test_get_structural_subscriptions_exclude(self):
 
724
        # Subscriptions for any of the given excluded subscribers are not
 
725
        # returned.
 
726
        subscriber = self.factory.makePerson()
 
727
        login_person(subscriber)
 
728
        product, bug = self.make_product_with_bug()
 
729
        product.addBugSubscription(subscriber, subscriber)
 
730
        self.assertContentEqual(
 
731
            [], get_structural_subscriptions(
 
732
                bug, None, exclude=[subscriber]))
 
733
 
 
734
 
637
735
class TestGetStructuralSubscribers(TestCaseWithFactory):
638
736
 
639
737
    layer = DatabaseFunctionalLayer
648
746
        # subscribers will be returned by get_structural_subscribers().
649
747
        product, bug = self.make_product_with_bug()
650
748
        subscribers = get_structural_subscribers(bug, None, None, None)
651
 
        self.assertIsInstance(subscribers, (ResultSet, EmptyResultSet))
 
749
        self.assertIsInstance(subscribers, RESULT_SETS)
652
750
        self.assertEqual([], list(subscribers))
653
751
 
654
752
    def test_getStructuralSubscribers_single_target(self):
678
776
        bug.addTask(actor, product2)
679
777
 
680
778
        subscribers = get_structural_subscribers(bug, None, None, None)
681
 
        self.assertIsInstance(subscribers, ResultSet)
 
779
        self.assertIsInstance(subscribers, RESULT_SETS)
682
780
        self.assertEqual(set([subscriber1, subscriber2]), set(subscribers))
683
781
 
684
782
    def test_getStructuralSubscribers_recipients(self):