예제 #1
0
def make_email_event_for_test(domain, schedule_name, user_ids, utcnow=None):
    content = EmailContent(
        subject={'*': 'New messaging API goes live!'},
        message={'*': 'Check out the new API.'},
    )
    schedule = AlertSchedule.create_simple_alert(domain, content)
    broadcast = ImmediateBroadcast.objects.create(
        domain=domain,
        name=schedule_name,
        schedule=schedule,
        recipients=[(ScheduleInstance.RECIPIENT_TYPE_MOBILE_WORKER, user_id)
                    for user_id in user_ids],
    )
    for user_id in user_ids:
        instance = AlertScheduleInstance.create_for_recipient(
            schedule,
            ScheduleInstance.RECIPIENT_TYPE_MOBILE_WORKER,
            user_id,
            move_to_next_event_not_in_the_past=False,
        )
        instance.send_current_event_content_to_recipients()

    subevents = {}
    for event in MessagingEvent.objects.filter(source_id=broadcast.id):
        for subevent in MessagingSubEvent.objects.filter(parent=event):
            handle_email_messaging_subevent(
                {
                    "eventType": "Delivery",
                    "delivery": {
                        "timestamp": "2021-05-27T07:09:42.318Z"
                    }
                }, subevent.id)
            subevents[subevent.recipient_id] = subevent
    return subevents
def get_content(handler, event, translated=True):
    if handler.method == METHOD_SMS:
        check_days_until(event.message)
        if translated:
            return SMSContent(message=event.message)
        else:
            return SMSContent(
                message={'*': get_single_dict_value(event.message)})
    elif handler.method == METHOD_EMAIL:
        check_days_until(event.subject)
        check_days_until(event.message)
        if translated:
            return EmailContent(subject=event.subject, message=event.message)
        else:
            return EmailContent(
                subject={'*': get_single_dict_value(event.subject)},
                message={'*': get_single_dict_value(event.message)},
            )
    elif handler.method == METHOD_SMS_SURVEY:
        if event.callback_timeout_intervals:
            if handler.submit_partial_forms:
                expire_after = sum(event.callback_timeout_intervals)
                reminder_intervals = event.callback_timeout_intervals[:-1]
            else:
                expire_after = SQLXFormsSession.MAX_SESSION_LENGTH
                reminder_intervals = event.callback_timeout_intervals

            submit_partially_completed_forms = handler.submit_partial_forms
            include_case_updates_in_partial_submissions = handler.include_case_side_effects
        else:
            expire_after = SQLXFormsSession.MAX_SESSION_LENGTH
            reminder_intervals = []
            submit_partially_completed_forms = False
            include_case_updates_in_partial_submissions = False

        return SMSSurveyContent(
            form_unique_id=event.form_unique_id,
            expire_after=expire_after,
            reminder_intervals=reminder_intervals,
            submit_partially_completed_forms=submit_partially_completed_forms,
            include_case_updates_in_partial_submissions=
            include_case_updates_in_partial_submissions,
        )
    else:
        raise ValueError("Unexpected method '%s'" % handler.method)
예제 #3
0
 def setUp(self):
     self._translated_rule = self._add_rule(
         SMSContent(message={
             'en': 'Diamonds and Rust',
             'es': 'Diamantes y Óxido',
         }))
     self._untranslated_rule = self._add_rule(
         SMSContent(message={
             '*': 'Joan',
         }))
     self._email_rule = self._add_rule(
         EmailContent(
             subject={'*': 'You just won something'},
             message={'*': 'This is a scam'},
         ))
 def setUp(self):
     self._rules = {
         self.EMAIL_RULE:
         self._add_daily_rule(
             EmailContent(
                 subject={'*': 'You just won something'},
                 message={'*': 'This is a scam'},
             )),
         self.LOCKED_RULE:
         self._add_immediate_rule(
             SMSContent(message={
                 '*': 'Fool That I Am',
             })),
         self.UNTRANSLATED_IMMEDIATE_RULE:
         self._add_immediate_rule(SMSContent(message={
             '*': 'Joni',
         })),
         self.UNTRANSLATED_DAILY_RULE:
         self._add_daily_rule(SMSContent(message={
             '*': 'Joan',
         })),
         self.IMMEDIATE_RULE:
         self._add_immediate_rule(
             SMSContent(message={
                 '*': 'Car on a Hill',
             })),
         self.DAILY_RULE:
         self._add_daily_rule(
             SMSContent(message={
                 'en': 'Diamonds and Rust',
                 'es': 'Diamantes y Óxido',
             })),
         self.WEEKLY_RULE:
         self._add_weekly_rule(
             SMSContent(message={
                 'en': 'It\'s Too Late',
                 'es': 'Es Demasiado Tarde',
             })),
         self.MONTHLY_RULE:
         self._add_monthly_rule(
             SMSContent(message={
                 'en': 'Both Sides Now',
                 'es': 'Ahora Ambos Lados',
             })),
         self.CUSTOM_DAILY_RULE:
         self._add_custom_daily_rule([
             SMSContent(message={'*': 'Just Like This Train'}),
             SMSContent(message={'*': 'Free Man in Paris'}),
         ]),
         self.CUSTOM_IMMEDIATE_RULE:
         self._add_custom_immediate_rule([
             SMSContent(message={
                 'en': 'Paper Bag',
                 'es': 'Bolsa de Papel',
             }),
             SMSContent(message={
                 'en': 'A Mistake',
                 'es': 'Un Error',
             }),
         ]),
         self.CUSTOM_RULE_BOTH_SHEETS:
         self._add_custom_immediate_rule([
             SMSContent(message={
                 'en': "I'm Lucky",
                 'es': "Tengo Suerte",
             }),
             SMSContent(message={
                 '*': 'Down to Zero',
             }),
             SMSContent(message={
                 'en': 'Me Myself I',
                 'es': 'Yo Mí Mismo Yo',
             }),
             SMSContent(message={
                 '*': 'Rosie',
             }),
         ])
     }
     locked_rule = self._get_rule(self.LOCKED_RULE)
     locked_rule.locked_for_editing = True
     locked_rule.save()