67
67
notification_batches,
68
68
notification_comment_batches,
69
process_deferred_notifications,
70
71
from lp.registry.interfaces.person import IPersonSet
71
72
from lp.registry.interfaces.product import IProductSet
601
602
login('test@canonical.com')
602
603
self.layer.switchDbUser(config.malone.bugnotification_dbuser)
603
self.now = datetime.now(pytz.timezone('UTC'))
604
self.now = datetime.now(pytz.UTC)
604
605
self.ten_minutes_ago = self.now - timedelta(minutes=10)
605
606
self.notification_set = getUtility(IBugNotificationSet)
606
607
for notification in self.notification_set.getNotificationsToSend():
1190
1191
for name in names:
1191
1192
template = get_email_template(name, 'bugs')
1192
1193
self.assertTrue(re.search('^-- $', template, re.MULTILINE))
1196
class TestDeferredNotifications(TestCaseWithFactory):
1198
layer = LaunchpadZopelessLayer
1201
super(TestDeferredNotifications, self).setUp()
1202
self.notification_set = getUtility(IBugNotificationSet)
1203
# Ensure there are no outstanding notifications.
1204
for notification in self.notification_set.getNotificationsToSend():
1205
notification.destroySelf()
1206
self.ten_minutes_ago = datetime.now(pytz.UTC) - timedelta(minutes=10)
1208
def _make_deferred_notification(self):
1209
bug = self.factory.makeBug()
1210
empty_recipients = BugNotificationRecipients()
1211
message = getUtility(IMessageSet).fromText(
1212
'subject', 'a comment.', bug.owner,
1213
datecreated=self.ten_minutes_ago)
1214
self.notification_set.addNotification(
1215
bug, False, message, empty_recipients, None, deferred=True)
1217
def test_deferred_notifications(self):
1218
# Create some deferred notifications and show that processing them
1219
# puts then in the state where they are ready to send.
1221
for i in xrange(num):
1222
self._make_deferred_notification()
1223
deferred = self.notification_set.getDeferredNotifications()
1224
self.assertEqual(num, deferred.count())
1225
process_deferred_notifications(deferred)
1226
# Now that are all in the PENDING state.
1227
ready_to_send = self.notification_set.getNotificationsToSend()
1228
self.assertEqual(num, len(ready_to_send))
1229
# And there are no longer any deferred.
1230
deferred = self.notification_set.getDeferredNotifications()
1231
self.assertEqual(0, deferred.count())