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 2
2
import copy
3
3
import json
4
4
from email .utils import parseaddr
5
+ import types
5
6
6
7
from .base import Resource
8
+ from .exceptions import SparkPostException
7
9
8
10
9
11
try :
@@ -137,6 +139,10 @@ def _parse_address(self, address):
137
139
return parsed_address
138
140
139
141
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
+
140
146
formatted_recipients = []
141
147
for recip in recipients :
142
148
if isinstance (recip , string_types ):
Original file line number Diff line number Diff line change 9
9
10
10
from sparkpost import SparkPost
11
11
from sparkpost import Transmissions
12
- from sparkpost .exceptions import SparkPostAPIException
12
+ from sparkpost .exceptions import SparkPostAPIException , SparkPostException
13
13
14
14
15
15
def test_translate_keys_with_list ():
@@ -28,6 +28,14 @@ def test_translate_keys_with_recips():
28
28
{'key' : 'value' },
29
29
{'address' : {'email' : 'foobar' }}]
30
30
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
+
31
39
32
40
def test_translate_keys_with_unicode_recips ():
33
41
t = Transmissions ('uri' , 'key' )
You can’t perform that action at this time.
0 commit comments