Skip to content

Commit

Permalink
Merge pull request #141 from SparkPost/issue138
Browse files Browse the repository at this point in the history
Validate type of recipients
  • Loading branch information
rajumsys committed Mar 7, 2017
2 parents 8808080 + a99c5aa commit 266b3a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 266b3a7

Please sign in to comment.