def _add_custom_immediate_rule(self, content_list): event_and_content_objects = [(AlertEvent(minutes_to_wait=i * 10), content) for i, content in enumerate(content_list)] schedule = AlertSchedule.create_custom_alert( self.domain, event_and_content_objects) return self._add_rule(alert_schedule_id=schedule.schedule_id)
def test_sms_content(self): from corehq.messaging.scheduling.models import AlertSchedule, SMSContent, AlertEvent from corehq.messaging.scheduling.scheduling_partitioned.dbaccessors import \ delete_alert_schedule_instances_for_schedule schedule = AlertSchedule.create_simple_alert(self.domain, SMSContent()) schedule.set_custom_alert( [ (AlertEvent(minutes_to_wait=5), SMSContent()), (AlertEvent(minutes_to_wait=15), SMSContent()), ] ) self.addCleanup(lambda: delete_alert_schedule_instances_for_schedule(AlertScheduleInstance, schedule.schedule_id)) self._dump_and_load(Counter({AlertSchedule: 1, AlertEvent: 2, SMSContent: 2}))
def get_event(handler, event): if handler.event_interpretation == EVENT_AS_OFFSET: return AlertEvent(minutes_to_wait=((event.day_num * 1440) + (event.fire_time.hour * 60) + event.fire_time.minute)) else: raise ValueError("Unexpected event_interpretation '%s'" % handler.event_interpretation)