def test_publish_event(self):
        role = self.create_user()
        email = '*****@*****.**'
        label = 'So public'
        recipient = self.create_user(foreign_id='rolex', email=email)
        update_role(recipient)
        collection = self.create_collection(foreign_id='NoNoNo', label=label)
        event = Events.PUBLISH_COLLECTION
        publish(event,
                role.id,
                params={'collection': collection},
                channels=[Notification.GLOBAL])
        db.session.commit()

        notifications = Notification.all().all()
        assert 1 == len(notifications), notifications
        not0 = notifications[0]
        assert not0._event == event.name, not0._event
        assert not0.params['collection'] == collection.id, not0.params

        with mail.record_messages() as outbox:
            assert len(outbox) == 0, outbox
            generate_digest()
            assert len(outbox) == 1, outbox
            msg = outbox[0]
            assert email in msg.recipients, msg.recipients
            assert label in msg.html, msg.html
Exemplo n.º 2
0
    def test_publish_event(self):
        role = self.create_user()
        email = '*****@*****.**'
        label = 'So public'
        recipient = self.create_user(foreign_id='rolex',
                                     email=email)
        update_role(recipient)
        collection = self.create_collection(foreign_id='NoNoNo', label=label)
        event = Events.PUBLISH_COLLECTION
        publish(event, role.id,
                params={'collection': collection},
                channels=[Notification.GLOBAL])
        db.session.commit()

        notifications = Notification.all().all()
        assert 1 == len(notifications), notifications
        not0 = notifications[0]
        assert not0._event == event.name, not0._event
        assert not0.params['collection'] == str(collection.id), not0.params

        with mail.record_messages() as outbox:
            assert len(outbox) == 0, outbox
            generate_digest()
            assert len(outbox) == 1, outbox
            msg = outbox[0]
            assert email in msg.recipients, msg.recipients
            assert label in msg.html, msg.html
Exemplo n.º 3
0
    def test_notify_no_email(self):
        data = {'query': {}, 'custom_label': 'Test Alert'}
        assert self.role_no_email.email is None, self.role_no_email.email
        alert = Alert.create(data, self.role_no_email)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.commit()

        notcount = Notification.all().count()
        assert notcount == 0, notcount
    def test_notify_entity(self):
        data = {'query_text': 'kwazulu', 'label': 'Test Alert'}
        alert = Alert.create(data, self.role_email.id)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 2, notcount
Exemplo n.º 5
0
    def test_notify_entity(self):
        data = {'query': 'kwazulu'}
        alert = Alert.create(data, self.role_email.id)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 2, notcount
Exemplo n.º 6
0
    def test_publish_event(self):
        event = Events.PUBLISH_COLLECTION
        role = self.create_user()
        collection = self.create_collection(foreign_id='NoNoNo')
        publish(event, role.id, params={'collection': collection})
        db.session.commit()

        notifications = Notification.all().all()
        assert 1 == len(notifications), notifications
        not0 = notifications[0]
        assert not0._event == event.name, not0._event
        assert not0.params['collection'] == collection.id, not0.params
Exemplo n.º 7
0
    def test_notify(self):
        data = {'query_text': '', 'label': 'Test Alert'}
        alert = Alert.create(data, self.role_email)
        alert.notified_at = datetime.utcnow() + timedelta(hours=72)
        db.session.commit()

        notcount = Notification.all().count()
        assert notcount == 0, notcount

        db.session.refresh(alert)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 3, notcount

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 3, notcount
Exemplo n.º 8
0
    def test_notify(self):
        data = {'query': 'fruit'}
        alert = Alert.create(data, self.role_email.id)
        alert.notified_at = datetime.utcnow() + timedelta(hours=72)
        db.session.commit()

        notcount = Notification.all().count()
        assert notcount == 0, notcount

        db.session.refresh(alert)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 1, notcount

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 1, notcount
Exemplo n.º 9
0
    def test_notify(self):
        data = {'query': 'Kashmir'}
        failed_alert = Alert.create(data, self.role_no_email.id)
        failed_alert.notified_at = datetime.utcnow() - timedelta(hours=72)

        alert = Alert.create(data, self.role_email.id)
        alert.notified_at = datetime.utcnow() + timedelta(hours=72)
        db.session.commit()

        notcount = Notification.all().count()
        assert notcount == 0, notcount

        db.session.refresh(alert)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 1, notcount

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 1, notcount