634
639
self.assertEqual(set([self_sub]), set(subscriptions))
642
class TestGetStructuralSubscriptions(TestCaseWithFactory):
644
layer = DatabaseFunctionalLayer
646
def make_product_with_bug(self):
647
product = self.factory.makeProduct()
648
bug = self.factory.makeBug(product=product)
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))
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))
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()
673
subscriber1 = self.factory.makePerson()
674
subscriber2 = self.factory.makePerson()
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)
681
bug = self.factory.makeBug(product=product1)
682
bug.addTask(actor, product2)
684
subscriptions = get_structural_subscriptions(bug, None)
685
self.assertIsInstance(subscriptions, RESULT_SETS)
686
self.assertContentEqual(
687
[subscription1, subscription2], subscriptions)
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()
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)
701
bug = self.factory.makeBug(product=product1)
702
bug.addTask(actor, product2)
704
subscriptions = get_structural_subscriptions(bug, None)
705
self.assertIsInstance(subscriptions, RESULT_SETS)
706
self.assertContentEqual([subscription1], subscriptions)
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))
723
def test_get_structural_subscriptions_exclude(self):
724
# Subscriptions for any of the given excluded subscribers are not
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]))
637
735
class TestGetStructuralSubscribers(TestCaseWithFactory):
639
737
layer = DatabaseFunctionalLayer