コード例 #1
0
 def main(self):
     manager = PersonNotificationManager(self.txn, self.logger)
     unsent_notifications = manager.sendNotifications()
     manager.purgeNotifications(unsent_notifications)
コード例 #2
0
class TestPersonNotificationManager(TestCaseWithFactory):
    """Tests for the PersonNotificationManager use in scripts."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestPersonNotificationManager, self).setUp()
        logging.basicConfig(level=logging.CRITICAL)
        logger = logging.getLogger()
        self.manager = PersonNotificationManager(transaction, logger)
        self.notification_set = getUtility(IPersonNotificationSet)

    def tearDown(self):
        super(TestPersonNotificationManager, self).tearDown()
        reset_logging()

    def test_sendNotifications_sent(self):
        user = self.factory.makePerson()
        notification = self.notification_set.addNotification(
            user, 'subject', 'body')
        unsent = self.manager.sendNotifications()
        self.assertEqual(None, unsent)
        self.failIf(notification.date_emailed is None)

    def test_sendNotifications_unsent(self):
        user = self.factory.makePerson()
        notification = self.notification_set.addNotification(
            user, 'subject', 'body')
        user.setPreferredEmail(None)
        unsent = self.manager.sendNotifications()
        self.assertEqual([notification], unsent)
        self.assertEqual(None, notification.date_emailed)

    def test_sendNotifications_sent_to_team_admins(self):
        team = self.factory.makeTeam()
        self.assertIs(None, team.preferredemail)
        notification = self.notification_set.addNotification(
            team, 'subject', 'body')
        unsent = self.manager.sendNotifications()
        self.assertEqual(None, unsent)
        self.failIf(notification.date_emailed is None)

    def test_purgeNotifications_old(self):
        user = self.factory.makePerson()
        notification = self.notification_set.addNotification(
            user, 'subject', 'body')
        age = timedelta(
            days=int(config.person_notification.retained_days) + 1)
        naked_notification = removeSecurityProxy(notification)
        naked_notification.date_created = (
            datetime.now(pytz.timezone('UTC')) - age)
        self.manager.purgeNotifications()
        notifcations = self.notification_set.getNotificationsToSend()
        self.assertEqual(0, notifcations.count())

    def test_purgeNotifications_extra(self):
        user = self.factory.makePerson()
        notification = self.notification_set.addNotification(
            user, 'subject', 'body')
        user.setPreferredEmail(None)
        self.manager.purgeNotifications(extra_notifications=[notification])
        notifcations = self.notification_set.getNotificationsToSend()
        self.assertEqual(0, notifcations.count())
コード例 #3
0
 def setUp(self):
     super(TestPersonNotificationManager, self).setUp()
     logging.basicConfig(level=logging.CRITICAL)
     logger = logging.getLogger()
     self.manager = PersonNotificationManager(transaction, logger)
     self.notification_set = getUtility(IPersonNotificationSet)
コード例 #4
0
 def main(self):
     manager = PersonNotificationManager(self.txn, self.logger)
     unsent_notifications = manager.sendNotifications()
     manager.purgeNotifications(unsent_notifications)