Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sparkpost/transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from email.utils import parseaddr

from .base import Resource
from .exceptions import SparkPostException


try:
Expand Down Expand Up @@ -137,6 +138,10 @@ def _parse_address(self, address):
return parsed_address

def _extract_recipients(self, recipients):

if not (isinstance(recipients, (list, dict))):
raise SparkPostException('recipients must be a list or dict')

formatted_recipients = []
for recip in recipients:
if isinstance(recip, string_types):
Expand Down
8 changes: 7 additions & 1 deletion test/test_transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from sparkpost import SparkPost
from sparkpost import Transmissions
from sparkpost.exceptions import SparkPostAPIException
from sparkpost.exceptions import SparkPostAPIException, SparkPostException


def test_translate_keys_with_list():
Expand All @@ -29,6 +29,12 @@ def test_translate_keys_with_recips():
{'address': {'email': 'foobar'}}]


def test_exceptions_for_recipients():
t = Transmissions('uri', 'key')
with pytest.raises(SparkPostException):
t._translate_keys(recipients='test')


def test_translate_keys_with_unicode_recips():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=[u'unicode_email@example.com',
Expand Down