Пример #1
0
 def test_notification_delete(self):
     """Open Notifications are deleted when a new report is received."""
     for notif in self._generate_notifications():
         trigger(notif)  # saves to database.
     report = self.make_report(site=self.facility, timestamp=self.recently)
     notifs = self._generate_notifications()
     self.assertEquals(len(notifs), 0)
     self.assertEquals(Notification.objects.count(), 0)
Пример #2
0
 def test_update_notification(self):
     """Notification is updated with up-to-date information."""
     for notif in self._generate_notifications():
         trigger(notif)  # saves to database.
     notif_pre = Notification.objects.get()
     report = self.make_report(site=self.facility, timestamp=self.past)
     for notif in self._generate_notifications():
         trigger(notif)
     notif_post = Notification.objects.get()
     self.assertEquals(notif_pre.id, notif_post.id)
     self.assertNotEquals(notif_pre.text, notif_post.text)
Пример #3
0
    def test_alert_visibility(self):
        """New notifications should be visible to all users."""
        user2 = self.create_user()
        for notif in self._generate_notifications():
            trigger(notif)  # saves to database & creates Visibility objects.
        notif = Notification.objects.get()

        self.assertEquals(NotificationVisibility.objects.filter(
                user=self.user, notif=notif).count(), 1)
        self.assertEquals(NotificationVisibility.objects.filter(
                user=user2, notif=notif).count(), 1)
        self.assertEquals(NotificationVisibility.objects.count(), 2)
Пример #4
0
def trigger_alerts(report, response):
    report_activity = report.reportcomment_set.filter(
        date__gte=datetime.now() - settings.COMMUNICATOR_RESPONSE_WINDOW
    )

    inquiring_users = set()
    tagged_users = set()
    commenting_users = set()

    for c in report_activity:
        if c.comment_type == ReportComment.INQUIRY_TYPE:
            user_id = (json.loads(c.extra_info) if c.extra_info else {}).get('user_id')
            try:
                user = User.objects.get(id=user_id)
                inquiring_users.add(user)
            except User.DoesNotExist:
                pass

        tagged_users = tagged_users.union(ct.user for ct in c.contact_tags.all())
        #commenting_users.add() # figure out later

    def notifs():
        for u in inquiring_users:
            yield mk_response_alert(u, report, response, 'sender')
        for u in tagged_users - inquiring_users:
            yield mk_response_alert(u, report, response, 'tagged')
        for u in commenting_users - tagged_users - inquiring_users:
            yield mk_response_alert(u, report, response, 'commenter')
    for notif in notifs():
        msg = trigger(notif)
        logging.debug(msg)
Пример #5
0
def trigger_alerts(comment):
    for c in comment.contact_tags.all():
        if c.user:
            notif = mk_tagged_alert(c.user, comment)
            msg = trigger(notif)
            logging.debug(msg)