Example #1
0
def test_check_service_sms_sender_id_where_service_id_is_not_found(sample_service, fake_uuid):
    sms_sender = create_service_sms_sender(service=sample_service, sms_sender='123456')
    with pytest.raises(BadRequestError) as e:
        check_service_sms_sender_id(fake_uuid, sms_sender.id, SMS_TYPE)
    assert e.value.status_code == 400
    assert e.value.message == 'sms_sender_id {} does not exist in database for service id {}' \
        .format(sms_sender.id, fake_uuid)
def test_check_service_sms_sender_id_where_sms_sender_is_not_found(
        sample_service, fake_uuid):
    with pytest.raises(BadRequestError) as e:
        check_service_sms_sender_id(sample_service.id, fake_uuid, SMS_TYPE)
    assert e.value.status_code == 400
    assert e.value.message == "sms_sender_id {} does not exist in database for service id {}".format(
        fake_uuid, sample_service.id)
Example #3
0
def get_reply_to_text(notification_type, form, template, form_field=None):
    reply_to = None
    if notification_type == EMAIL_TYPE:
        service_email_reply_to_id = form.get(form_field or "email_reply_to_id")
        reply_to = (
            check_service_email_reply_to_id(
                str(authenticated_service.id),
                service_email_reply_to_id,
                notification_type,
            )
            or template.get_reply_to_text()
        )

    elif notification_type == SMS_TYPE:
        service_sms_sender_id = form.get(form_field or "sms_sender_id")
        sms_sender_id = check_service_sms_sender_id(str(authenticated_service.id), service_sms_sender_id, notification_type)
        if sms_sender_id:
            reply_to = try_validate_and_format_phone_number(sms_sender_id)
        else:
            reply_to = template.get_reply_to_text()

    elif notification_type == LETTER_TYPE:
        reply_to = template.get_reply_to_text()

    return reply_to
Example #4
0
def validate_sender_id(template, reply_to_id):
    notification_type = template.template_type

    if notification_type == EMAIL_TYPE:
        service_email_reply_to_id = reply_to_id
        check_service_email_reply_to_id(
            str(authenticated_service.id),
            service_email_reply_to_id,
            notification_type,
        )
        return service_email_reply_to_id
    elif notification_type == SMS_TYPE:
        service_sms_sender_id = reply_to_id
        check_service_sms_sender_id(
            str(authenticated_service.id),
            service_sms_sender_id,
            notification_type,
        )
        return service_sms_sender_id
    else:
        raise NotImplementedError("validate_sender_id only handles emails and text messages")
Example #5
0
def test_check_service_sms_sender_id_where_sms_sender_id_is_found(sample_service):
    sms_sender = create_service_sms_sender(service=sample_service, sms_sender='123456')
    assert check_service_sms_sender_id(sample_service.id, sms_sender.id, SMS_TYPE) == '123456'
Example #6
0
def test_check_service_sms_sender_id_where_sms_sender_id_is_none(notification_type):
    assert check_service_sms_sender_id(None, None, notification_type) is None