File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 22import copy
33import json
44from email .utils import parseaddr
5+ import types
56
67from .base import Resource
8+ from .exceptions import SparkPostException
79
810
911try :
@@ -137,6 +139,10 @@ def _parse_address(self, address):
137139 return parsed_address
138140
139141 def _extract_recipients (self , recipients ):
142+
143+ if not (isinstance (recipients , types .ListType ) or isinstance (recipients , types .DictType )):
144+ raise SparkPostException ('recipients must be a list or dict' )
145+
140146 formatted_recipients = []
141147 for recip in recipients :
142148 if isinstance (recip , string_types ):
Original file line number Diff line number Diff line change 99
1010from sparkpost import SparkPost
1111from sparkpost import Transmissions
12- from sparkpost .exceptions import SparkPostAPIException
12+ from sparkpost .exceptions import SparkPostAPIException , SparkPostException
1313
1414
1515def test_translate_keys_with_list ():
@@ -28,6 +28,14 @@ def test_translate_keys_with_recips():
2828 {'key' : 'value' },
2929 {'address' : {'email' : 'foobar' }}]
3030
31+ results = t ._translate_keys (recipients = [{'address' : {'name' : 'foo' , 'email' : 'bar' }}])
32+ assert results ['recipients' ] == [{'address' : {'name' : 'foo' , 'email' : 'bar' }}]
33+
34+ def test_exceptions_for_recipients ():
35+ t = Transmissions ('uri' , 'key' )
36+ with pytest .raises (SparkPostException ):
37+ results = t ._translate_keys (recipients = 'test' )
38+
3139
3240def test_translate_keys_with_unicode_recips ():
3341 t = Transmissions ('uri' , 'key' )
You can’t perform that action at this time.
0 commit comments