Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
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()
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 == []
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
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
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
def message(**options):
options.update(base_options)
email_message = EmailMessage(**options)
return SparkPostMessage(email_message)
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
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
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