Skip to content

Commit 266b3a7

Browse files
authored
Merge pull request #141 from SparkPost/issue138
Validate type of recipients
2 parents 8808080 + a99c5aa commit 266b3a7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

sparkpost/transmissions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from email.utils import parseaddr
55

66
from .base import Resource
7+
from .exceptions import SparkPostException
78

89

910
try:
@@ -137,6 +138,10 @@ def _parse_address(self, address):
137138
return parsed_address
138139

139140
def _extract_recipients(self, recipients):
141+
142+
if not (isinstance(recipients, (list, dict))):
143+
raise SparkPostException('recipients must be a list or dict')
144+
140145
formatted_recipients = []
141146
for recip in recipients:
142147
if isinstance(recip, string_types):

test/test_transmissions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from sparkpost import SparkPost
1111
from sparkpost import Transmissions
12-
from sparkpost.exceptions import SparkPostAPIException
12+
from sparkpost.exceptions import SparkPostAPIException, SparkPostException
1313

1414

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

3131

32+
def test_exceptions_for_recipients():
33+
t = Transmissions('uri', 'key')
34+
with pytest.raises(SparkPostException):
35+
t._translate_keys(recipients='test')
36+
37+
3238
def test_translate_keys_with_unicode_recips():
3339
t = Transmissions('uri', 'key')
3440
results = t._translate_keys(recipients=[u'[email protected]',

0 commit comments

Comments
 (0)