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() res = get_notifications(self.role_email) notcount = res.get('hits').get('total').get('value') 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() res = get_notifications(self.role_email) notcount = res.get('hits').get('total').get('value') assert notcount == 1, res.get('hits') check_alerts() res = get_notifications(self.role_email) notcount = res.get('hits').get('total').get('value') assert notcount == 1, res.get('hits')
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
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() with mail.record_messages() as outbox: check_alerts() assert len(outbox) == 0, outbox
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
def periodic(self): db.session.remove() if self.hourly.check(): self.hourly.update() log.info("Running hourly tasks...") index_collections() if self.daily.check(): self.daily.update() log.info("Running daily tasks...") check_alerts() generate_digest()
def periodic(self): db.session.remove() if self.hourly.check(): self.hourly.update() log.info("Running hourly tasks...") self.cleanup_jobs() compute_collections() check_alerts() if self.daily.check(): self.daily.update() log.info("Running daily tasks...") generate_digest() update_roles()
def run_often(self): log.info("Self-check...") self.cleanup_jobs() compute_collections() if self.hourly.check(): self.hourly.update() log.info("Running hourly tasks...") check_alerts() if self.daily.check(): self.daily.update() log.info("Running daily tasks...") generate_digest() update_roles()
def periodic(self): with app.app_context(): db.session.remove() if self.often.check(): self.often.update() log.info("Self-check...") self.cleanup_jobs() compute_collections() if self.daily.check(): self.daily.update() log.info("Running daily tasks...") check_alerts() generate_digest() update_roles() delete_expired_exports()
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
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
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() with mail.record_messages() as outbox: check_alerts() assert len(outbox) == 0, outbox db.session.refresh(alert) alert.notified_at = datetime.utcnow() - timedelta(hours=72) db.session.add(alert) db.session.commit() with mail.record_messages() as outbox: check_alerts() assert len(outbox) == 1, outbox msg = outbox[0] assert 'Test Alert' in msg.subject, msg assert '*****@*****.**' in msg.recipients, msg with mail.record_messages() as outbox: check_alerts() assert len(outbox) == 0, outbox
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
def daily(): check_alerts() generate_digest()
def background(): index_collections() check_alerts()
def hourly(): update_collections() check_alerts()
def hourly(): index_collections() check_alerts()
def daily_tasks(): log.info("Running daily tasks...") check_alerts() generate_digest()