Skip to content

Commit 89d9f13

Browse files
committed
Merge pull request #97 from SparkPost/ISSUE-92
Fix preview resource to properly pass sub data
2 parents 411c565 + b25b519 commit 89d9f13

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

sparkpost/templates.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ def preview(self, template_id, substitution_data, draft=None):
175175
params = {}
176176
if draft is not None:
177177
params['draft'] = str(draft).lower()
178+
data = json.dumps({'substitution_data': substitution_data})
178179
results = self.request('POST',
179180
uri,
180181
params=params,
181-
data=json.dumps(substitution_data))
182+
data=data)
182183
return results

test/test_templates.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
try:
2+
from urllib.parse import urlparse
3+
except:
4+
from urlparse import urlparse
5+
16
import pytest
27
import responses
38

@@ -175,6 +180,7 @@ def test_success_preview():
175180
)
176181
sp = SparkPost('fake-key')
177182
results = sp.templates.preview('foobar', {})
183+
assert responses.calls[0].request.body == '{"substitution_data": {}}'
178184
assert results == {}
179185

180186

@@ -190,6 +196,8 @@ def test_success_preview_with_draft():
190196
)
191197
sp = SparkPost('fake-key')
192198
results = sp.templates.preview('foobar', {}, True)
199+
parsed = urlparse(responses.calls[0].request.url)
200+
assert parsed.query == 'draft=true'
193201
assert results == {}
194202

195203

test/test_transmissions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ def test_translate_keys_for_email_parsing():
4949
]
5050

5151

52+
def test_translate_keys_for_from_email():
53+
t = Transmissions('uri', 'key')
54+
results = t._translate_keys(from_email='Testing <[email protected]>')
55+
assert results['content']['from'] == {
56+
'name': 'Testing',
57+
'email': '[email protected]'
58+
}
59+
60+
5261
def test_translate_keys_with_cc():
5362
t = Transmissions('uri', 'key')
5463
results = t._translate_keys(recipients=['[email protected]'],

0 commit comments

Comments
 (0)