~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Brad Crittenden
  • Date: 2011-08-15 21:17:25 UTC
  • mto: This revision was merged to the branch mainline in revision 13715.
  • Revision ID: bac@canonical.com-20110815211725-4wjrz3z3vsi4g83h
Additional test coverage for deferred bug notifications

Show diffs side-by-side

added added

removed removed

Lines of Context:
651
651
 
652
652
    layer = DatabaseFunctionalLayer
653
653
 
 
654
    def setUp(self):
 
655
        super(TestGetDeferredNotifications, self).setUp()
 
656
        self.bns = BugNotificationSet()
 
657
 
654
658
    def test_no_deferred_notifications(self):
655
 
        results = BugNotificationSet().getDeferredNotifications()
656
 
        self.assertEqual([], list(results))
 
659
        results = self.bns.getDeferredNotifications()
 
660
        self.assertEqual(0, results.count())
657
661
 
658
 
    def test_some_deferred_notifications(self):
 
662
    def _make_deferred_notification(self):
659
663
        bug = self.factory.makeBug()
660
 
        bns = BugNotificationSet()
661
664
        empty_recipients = BugNotificationRecipients()
662
665
        message = getUtility(IMessageSet).fromText(
663
666
            'subject', 'a comment.', bug.owner,
664
667
            datecreated=datetime.now(pytz.UTC))
665
 
        bns.addNotification(
 
668
        self.bns.addNotification(
666
669
            bug, False, message, empty_recipients, None, deferred=True)
667
 
        results = bns.getDeferredNotifications()
668
 
        self.assertEqual(1, results.count())
 
670
 
 
671
    def test_one_deferred_notification(self):
 
672
        self._make_deferred_notification()
 
673
        results = self.bns.getDeferredNotifications()
 
674
        self.assertEqual(1, results.count())
 
675
 
 
676
    def test_many_deferred_notification(self):
 
677
        num = 5
 
678
        for i in xrange(num):
 
679
            self._make_deferred_notification()
 
680
        results = self.bns.getDeferredNotifications()
 
681
        self.assertEqual(num, results.count())
 
682
 
 
683
    def test_destroy_notifications(self):
 
684
        self._make_deferred_notification()
 
685
        results = self.bns.getDeferredNotifications()
 
686
        self.assertEqual(1, results.count())
 
687
        notification = results[0]
 
688
        notification.destroySelf()
 
689
        results = self.bns.getDeferredNotifications()
 
690
        self.assertEqual(0, results.count())