How to use sparkpost - 10 common examples

To help you get started, we’ve selected a few sparkpost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SparkPost / python-sparkpost / test / test_transmissions.py View on Github external
def test_success_send():
    responses.add(
        responses.POST,
        'https://api.sparkpost.com/api/v1/transmissions',
        status=200,
        content_type='application/json',
        body='{"results": "yay"}'
    )
    sp = SparkPost('fake-key')
    results = sp.transmission.send()
    assert results == 'yay'
github SparkPost / python-sparkpost / test / test_metrics.py View on Github external
def test_fail_domains():
    responses.add(
        responses.GET,
        'https://api.sparkpost.com/api/v1/metrics/domains',
        status=500,
        content_type='application/json',
        body="""
        {"errors": [{"message": "You failed", "description": "More Info"}]}
        """
    )
    with pytest.raises(SparkPostAPIException):
        sp = SparkPost('fake-key')
        sp.metrics.domains.list()
github SparkPost / python-sparkpost / test / test_sending_domains.py View on Github external
def test_success_list():
    responses.add(
        responses.GET,
        base_uri,
        status=200,
        content_type='application/json',
        body='{"results": []}'
    )
    sp = SparkPost('fake-key')
    results = sp.sending_domains.list()
    assert results == []
github SparkPost / python-sparkpost / test / test_suppression_list.py View on Github external
def test_success_delete():
    responses.add(
        responses.DELETE,
        'https://api.sparkpost.com/api/v1/suppression-list/foobar',
        status=204,
        content_type='application/json'
    )
    sp = SparkPost('fake-key')
    results = sp.suppression_list.delete('foobar')
    assert results is True
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_substitution_data():
    email_message = EmailMessage(
        to=[
            {
                "address": "to@example.com",
                "substitution_data": {
                    "key": "value"
                }
            }
        ],
        from_email='test@from.com'
    )
    email_message.template = 'template-id'
    email_message.substitution_data = {"key2": "value2"}
    actual = SparkPostMessage(email_message)

    expected = dict(
        recipients=[
            {
                "address": "to@example.com",
                "substitution_data": {
                    "key": "value"
                }
            }
        ],
        from_email='test@from.com',
        template='template-id',
        substitution_data={"key2": "value2"}
    )

    assert actual == expected
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_content_subtype():
    email_message = EmailMessage(
        to=['to@example.com'],
        from_email='test@from.com',
        body='<p>Testing</p>'
    )
    email_message.content_subtype = 'html'
    actual = SparkPostMessage(email_message)
    expected = dict(
        recipients=['to@example.com'],
        from_email='test@from.com',
        html='<p>Testing</p>'
    )
    assert actual == expected
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def message(**options):
    options.update(base_options)
    email_message = EmailMessage(**options)
    return SparkPostMessage(email_message)
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_campaign():
    email_message = EmailMessage(**base_options)
    email_message.campaign = 'campaign-id'
    actual = SparkPostMessage(email_message)
    expected = dict(
        campaign='campaign-id'
    )
    expected.update(base_expected)
    assert actual == expected
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_transactional():
    email_message = EmailMessage(**base_options)
    import json
    msys_api = json.dumps({'options': {'transactional': True}})
    email_message.extra_headers['X-MSYS-API'] = msys_api

    actual = SparkPostMessage(email_message)
    expected = dict(
        custom_headers={'X-MSYS-API': msys_api},
        transactional=True,
    )
    expected.update(base_expected)
    assert actual == expected
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_template():
    email_message = EmailMessage(
        to=['to@example.com'],
        from_email='test@from.com'
    )
    email_message.template = 'template-id'
    actual = SparkPostMessage(email_message)
    expected = dict(
        recipients=['to@example.com'],
        from_email='test@from.com',
        template='template-id'
    )
    assert actual == expected