def test_create_content_for_notification_allows_additional_personalisation(
    sample_template_with_placeholders, ):
    template = Template.query.get(sample_template_with_placeholders.id)
    create_content_for_notification(template, {
        "name": "Bobby",
        "Additional placeholder": "Data"
    })
示例#2
0
def test_create_content_for_notification_fails_with_missing_personalisation(
        sample_template_with_placeholders):
    template = SerialisedTemplate.from_id_and_service_id(
        sample_template_with_placeholders.id,
        sample_template_with_placeholders.service_id)
    with pytest.raises(BadRequestError):
        create_content_for_notification(template, None)
def test_create_content_for_notification_allows_additional_personalisation(
        sample_template_with_placeholders):
    template = Template.query.get(sample_template_with_placeholders.id)
    create_content_for_notification(template, {
        'name': 'Bobby',
        'Additional placeholder': 'Data'
    })
示例#4
0
def test_create_content_for_notification_allows_additional_personalisation(
        sample_template_with_placeholders):
    template = SerialisedTemplate.from_id_and_service_id(
        sample_template_with_placeholders.id,
        sample_template_with_placeholders.service_id)
    create_content_for_notification(template, {
        'name': 'Bobby',
        'Additional placeholder': 'Data'
    })
示例#5
0
def validate_template(template_id,
                      personalisation,
                      service,
                      notification_type,
                      check_char_count=True):
    try:
        template = SerialisedTemplate.from_id_and_service_id(
            template_id, service.id)
    except NoResultFound:
        message = 'Template not found'
        raise BadRequestError(message=message, fields=[{'template': message}])

    check_template_is_for_notification_type(notification_type,
                                            template.template_type)
    check_template_is_active(template)

    template_with_content = create_content_for_notification(
        template, personalisation)

    check_notification_content_is_not_empty(template_with_content)

    # validating the template in post_notifications happens before the file is uploaded for doc download,
    # which means the length of the message can be exceeded because it's including the file.
    # The document download feature is only available through the api.
    if check_char_count:
        check_is_message_too_long(template_with_content)

    return template, template_with_content
示例#6
0
def test_create_content_for_notification_with_placeholders_passes(sample_template_with_placeholders):
    template = SerialisedTemplate.from_id_and_service_id(
        sample_template_with_placeholders.id, sample_template_with_placeholders.service_id
    )
    content = create_content_for_notification(template, {'name': 'Bobby'})
    assert content.content == template.content
    assert 'Bobby' in str(content)
示例#7
0
def test_check_notification_content_is_not_empty_passes(notify_api, mocker, sample_service):
    template_id = create_template(sample_service, content="Content is not empty").id
    template = SerialisedTemplate.from_id_and_service_id(
        template_id=template_id,
        service_id=sample_service.id
    )
    template_with_content = create_content_for_notification(template, {})
    assert check_notification_content_is_not_empty(template_with_content) is None
示例#8
0
def validate_template(template_id, personalisation, service,
                      notification_type):
    template = check_template_exists_by_id_and_service(template_id, service)
    check_template_is_for_notification_type(notification_type,
                                            template.template_type)
    check_template_is_active(template)

    template_with_content = create_content_for_notification(
        template, personalisation)
    if template.template_type == SMS_TYPE:
        check_sms_content_char_count(template_with_content.content_count)

    return template, template_with_content
示例#9
0
def test_check_notification_content_is_not_empty_fails(
    notify_api, mocker, sample_service, template_content, notification_values
):
    template_id = create_template(sample_service, content=template_content).id
    template = SerialisedTemplate.from_id_and_service_id(
        template_id=template_id,
        service_id=sample_service.id
    )
    template_with_content = create_content_for_notification(template, notification_values)
    with pytest.raises(BadRequestError) as e:
        check_notification_content_is_not_empty(template_with_content)
    assert e.value.status_code == 400
    assert e.value.message == 'Your message is empty.'
    assert e.value.fields == []
def __validate_template(form, service, notification_type):
    try:
        template = templates_dao.dao_get_template_by_id_and_service_id(
            template_id=form["template_id"], service_id=service.id
        )
    except NoResultFound:
        message = "Template not found"
        raise BadRequestError(message=message, fields=[{"template": message}])

    check_template_is_for_notification_type(notification_type, template.template_type)
    check_template_is_active(template)
    template_with_content = create_content_for_notification(template, form.get("personalisation", {}))
    if template.template_type == SMS_TYPE:
        check_sms_content_char_count(template_with_content.content_count)
    return template, template_with_content
示例#11
0
def validate_template(template_id, personalisation, service,
                      notification_type):
    try:
        template = templates_dao.dao_get_template_by_id_and_service_id(
            template_id=template_id, service_id=service.id)
    except NoResultFound:
        message = 'Template not found'
        raise BadRequestError(message=message, fields=[{'template': message}])

    check_template_is_for_notification_type(notification_type,
                                            template.template_type)
    check_template_is_active(template)
    template_with_content = create_content_for_notification(
        template, personalisation)
    if template.template_type == SMS_TYPE:
        check_sms_content_char_count(template_with_content.content_count)
    return template, template_with_content
示例#12
0
def validate_template(template_id, personalisation, service, notification_type):

    try:
        template = SerialisedTemplate.from_id_and_service_id(template_id, service.id)
    except NoResultFound:
        message = 'Template not found'
        raise BadRequestError(message=message,
                              fields=[{'template': message}])

    check_template_is_for_notification_type(notification_type, template.template_type)
    check_template_is_active(template)

    template_with_content = create_content_for_notification(template, personalisation)

    check_notification_content_is_not_empty(template_with_content)

    check_content_char_count(template_with_content)

    return template, template_with_content
def test_create_content_for_notification_with_placeholders_passes(sample_template_with_placeholders):
    template = Template.query.get(sample_template_with_placeholders.id)
    content = create_content_for_notification(template, {'name': 'Bobby'})
    assert content.content == template.content
    assert 'Bobby' in str(content)
def test_create_content_for_notification_fails_with_missing_personalisation(sample_template_with_placeholders):
    template = Template.query.get(sample_template_with_placeholders.id)
    with pytest.raises(BadRequestError):
        create_content_for_notification(template, None)
def test_create_content_for_notification_passes(sample_email_template):
    template = Template.query.get(sample_email_template.id)
    content = create_content_for_notification(template, None)
    assert str(content) == template.content
def test_create_content_for_notification_passes(sample_email_template):
    template = Template.query.get(sample_email_template.id)
    content = create_content_for_notification(template, None)
    assert str(content) == template.content
def test_create_content_for_notification_with_placeholders_passes(
    sample_template_with_placeholders, ):
    template = Template.query.get(sample_template_with_placeholders.id)
    content = create_content_for_notification(template, {"name": "Bobby"})
    assert content.content == template.content
    assert "Bobby" in str(content)
def test_create_content_for_notification_with_placeholders_passes(sample_template_with_placeholders):
    template = Template.query.get(sample_template_with_placeholders.id)
    content = create_content_for_notification(template, {'name': 'Bobby'})
    assert content.content == template.content
    assert 'Bobby' in str(content)
def test_create_content_for_notification_fails_with_missing_personalisation(sample_template_with_placeholders):
    template = Template.query.get(sample_template_with_placeholders.id)
    with pytest.raises(BadRequestError):
        create_content_for_notification(template, None)
def test_create_content_for_notification_fails_with_additional_personalisation(sample_template_with_placeholders):
    template = Template.query.get(sample_template_with_placeholders.id)
    with pytest.raises(BadRequestError) as e:
        create_content_for_notification(template, {'name': 'Bobby', 'Additional placeholder': 'Data'})
    assert e.value.message == 'Template personalisation not needed for template: Additional placeholder'
示例#21
0
def test_create_content_for_notification_passes(sample_email_template):
    template = SerialisedTemplate.from_id_and_service_id(
        sample_email_template.id, sample_email_template.service_id)
    content = create_content_for_notification(template, None)
    assert str(content) == template.content + '\n'