652
652
layer = DatabaseFunctionalLayer
655
super(TestGetDeferredNotifications, self).setUp()
656
self.bns = BugNotificationSet()
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())
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))
668
self.bns.addNotification(
666
669
bug, False, message, empty_recipients, None, deferred=True)
667
results = bns.getDeferredNotifications()
668
self.assertEqual(1, results.count())
671
def test_one_deferred_notification(self):
672
self._make_deferred_notification()
673
results = self.bns.getDeferredNotifications()
674
self.assertEqual(1, results.count())
676
def test_many_deferred_notification(self):
678
for i in xrange(num):
679
self._make_deferred_notification()
680
results = self.bns.getDeferredNotifications()
681
self.assertEqual(num, results.count())
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())