Skip to content

Commit

Permalink
Merge pull request #97 from SparkPost/ISSUE-92
Browse files Browse the repository at this point in the history
Fix preview resource to properly pass sub data
  • Loading branch information
richleland committed Mar 30, 2016
2 parents 411c565 + b25b519 commit 89d9f13
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sparkpost/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ def preview(self, template_id, substitution_data, draft=None):
params = {}
if draft is not None:
params['draft'] = str(draft).lower()
data = json.dumps({'substitution_data': substitution_data})
results = self.request('POST',
uri,
params=params,
data=json.dumps(substitution_data))
data=data)
return results
8 changes: 8 additions & 0 deletions test/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
try:
from urllib.parse import urlparse
except:
from urlparse import urlparse

import pytest
import responses

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


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


Expand Down
9 changes: 9 additions & 0 deletions test/test_transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def test_translate_keys_for_email_parsing():
]


def test_translate_keys_for_from_email():
t = Transmissions('uri', 'key')
results = t._translate_keys(from_email='Testing <testing@example.com>')
assert results['content']['from'] == {
'name': 'Testing',
'email': 'testing@example.com'
}


def test_translate_keys_with_cc():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=['primary@example.com'],
Expand Down

0 comments on commit 89d9f13

Please sign in to comment.