def test_handle_non_addressed_events(): app = Comet() app.register_parser('real_time_source', json) app.register_parser('real_time_source2', json) app.register_real_time_source('real_time_source') app.register_real_time_source('real_time_source2') app.set_config('real_time_source', {'alerts': { 'alert search name': { 'escalate_cadence': timedelta(minutes=45), 'template': 'alerts_template' } }}) app.set_config('real_time_source2', {'alerts': { 'alert search name': { 'escalate_cadence': timedelta(minutes=45), 'template': 'alerts_template' } }}) escalator = mock.Mock() escalator2 = mock.Mock() app.register_escalator('real_time_source', func=escalator) app.register_escalator('real_time_source2', func=escalator2) already_processed_user = '******' # already processed real time event - needs escalation app.data_store.add_record( EventRecord(id=2, received_at=datetime.utcnow() - timedelta(hours=1), source_type='real_time_source', owner=already_processed_user, processed_at=datetime.utcnow() - timedelta(hours=1), sent_at=datetime.utcnow() - timedelta(hours=1), data={'search_name': 'alert search name', 'name': 'needs escalation'}, fingerprint='f2')) # already processed real time event - still early for escalation # the event sent 35 min ago. app.data_store.add_record( EventRecord(id=3, received_at=datetime.utcnow() - timedelta(hours=1), source_type='real_time_source2', owner=already_processed_user, processed_at=datetime.utcnow() - timedelta(minutes=35), sent_at=datetime.utcnow() - timedelta(minutes=35), data={'search_name': 'alert search name', 'name': 'doesnt need escalation'}, fingerprint='f3')) app.handle_non_addressed_events() assert escalator.call_count == 1 assert escalator2.call_count == 0
def test_handle_non_addressed_events(): app = Comet() @app.register_parser('real_time_source') def parse_message(message): data = json.loads(message) return data, {} @app.register_parser('real_time_source2') def parse_message(message): data = json.loads(message) return data, {} @app.register_config_provider('real_time_source') def register_conf(event): return {"escalate_cadence": timedelta(minutes=45)} @app.register_config_provider('real_time_source2') def register_conf(event): return {"escalate_cadence": timedelta(minutes=45)} app.register_real_time_source('real_time_source') app.register_real_time_source('real_time_source2') escalator = mock.Mock() escalator2 = mock.Mock() app.register_escalator('real_time_source', func=escalator) app.register_escalator('real_time_source2', func=escalator2) already_processed_user = '******' # already processed real time event - needs escalation app.data_store.add_record( EventRecord(id=2, received_at=datetime.utcnow() - timedelta(hours=1), source_type='real_time_source', owner=already_processed_user, processed_at=datetime.utcnow() - timedelta(hours=1), sent_at=datetime.utcnow() - timedelta(hours=1), data={ 'search_name': 'alert search name', 'name': 'needs escalation' }, fingerprint='f2')) # already processed real time event - still early for escalation # the event sent 35 min ago. app.data_store.add_record( EventRecord(id=3, received_at=datetime.utcnow() - timedelta(hours=1), source_type='real_time_source2', owner=already_processed_user, processed_at=datetime.utcnow() - timedelta(minutes=35), sent_at=datetime.utcnow() - timedelta(minutes=35), data={ 'search_name': 'alert search name', 'name': 'doesnt need escalation' }, fingerprint='f3')) app.handle_non_addressed_events() assert escalator.call_count == 1 assert escalator2.call_count == 0