Ejemplo n.º 1
0
def test_create_valid_template():
    data = sample_template_data()
    template = Template(**data)
    assert template.id is None
    template.create()
    assert template.id is not None
    for key, value in data.items():
        assert getattr(template, key) == value
Ejemplo n.º 2
0
def sample_template(request, connection):
    template = Template(**sample_template_data())
    template.create()

    # Currently DotMailer's API doesn't support deletion of templates so
    # no rollback finalizer to add here.

    return template
Ejemplo n.º 3
0
def test_update_valid_template(connection):
    """
    Test to confirm that using the API we can successful create a
    template in the user's account.

    NOTE: You can not t
    :param connection:
    :return:
    """

    # First create a template which we can later update
    template = Template(
        name='Test',
        subject='test',
        from_name='*****@*****.**',
        html_content='<div>Hello, world!<a href="http://$UNSUB$"> Unsubscribe from this newsletter</a></div>',
        plain_text_content='Hello, world! $UNSUB$'
    )
    template.create()

    assert template.id is not None, 'Template has an ID value'
    template_id = template.id

    template.name = 'New name'
    template.update()

    updated_template = Template.get_by_id(template_id)
    assert updated_template.name == 'New name'
Ejemplo n.º 4
0
def test_create_valid_template(connection):
    """
    Test to confirm that using the API we can successful create a
    template in the user's account.

    :param connection:
    :return:
    """
    test_template = Template(
        name='Test',
        subject='test',
        from_name='*****@*****.**',
        html_content='<div>Hello, world!<a href="http://$UNSUB$"> Unsubscribe from this newsletter</a></div>',
        plain_text_content='Hello, world! $UNSUB$'
    )
    test_template.create()

    assert test_template.id is not None, 'Template has an ID value'
Ejemplo n.º 5
0
def test_get_all(connection):
    """

    :param connection:
    :return:
    """
    templates = Template.get_all()
    for template in templates:
        assert template.id is not None
Ejemplo n.º 6
0
def test_create_missing_parameter(connection, null_parameter):
    """
    Test to confirm that if we try to submit a template via the API that the 
    error response from the API creates an appopriate exception.

    :param connection: 
    :param null_parameter: 
    :return: 
    """
    test_data = dict(
        name='Test',
        subject='test',
        from_name='*****@*****.**',
        html_content='<div>Hello, world!<a href="http://$UNSUB$"> Unsubscribe from this newsletter</a></div>',
        plain_text_content='Hello, world! $UNSUB$'
    )
    test_data[null_parameter] = None
    with pytest.raises(ErrorTemplateInvalid,
                       message='Expecting invalid template exception'):
        test_template = Template(**test_data)
        test_template.create()
Ejemplo n.º 7
0
def test_update_valid_template(sample_template):
    """
    Test to confirm that we can successfully update a template.

    :return:
    """
    new_data = {
        'name': 'New update template test name',
        'subject': 'New subject value',
        'from_name': 'New from name',
        'html_content': 'Hello, %s' % sample_template.html_content,
        'plain_text_content': 'Hello, %s' % sample_template.plain_text_content
    }
    sample_template._update_values(new_data)
    sample_template.update()

    t = Template.get_by_id(sample_template.id)
    for key, value in new_data.items():
        assert getattr(t, key) == value
Ejemplo n.º 8
0
def test_get_by_valid_id(sample_template):
    id = sample_template.id

    template_response = Template.get_by_id(sample_template.id)

    assert sample_template == template_response
Ejemplo n.º 9
0
def test_create_required_keys(template_data, error_msg):
    with pytest.raises(KeyError, message=error_msg) as e:
        template = Template(**template_data)
        template.create()
    assert e.value.message == error_msg
Ejemplo n.º 10
0
def test_create_invalid_template(template_data, error_msg):
    template = Template(**template_data)
    with pytest.raises(ErrorTemplateInvalid, message=error_msg) as e:
        template.create()
    assert e.value.message == error_msg