From 4fc4115912f5552b4f17e715ba5e051334685c36 Mon Sep 17 00:00:00 2001 From: Rich Leland Date: Tue, 29 Mar 2016 17:20:17 -0400 Subject: [PATCH 1/2] Fix preview resource to properly pass sub data --- sparkpost/templates.py | 3 ++- test/test_templates.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sparkpost/templates.py b/sparkpost/templates.py index 770de8e..92e05f8 100644 --- a/sparkpost/templates.py +++ b/sparkpost/templates.py @@ -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 diff --git a/test/test_templates.py b/test/test_templates.py index 7442060..e0dc663 100644 --- a/test/test_templates.py +++ b/test/test_templates.py @@ -1,3 +1,8 @@ +try: + from urllib.parse import urlparse +except: + from urlparse import urlparse + import pytest import responses @@ -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 == {} @@ -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 == {} From b25b51909bd83ed401ac2c7fc53a545af39f0a17 Mon Sep 17 00:00:00 2001 From: Rich Leland Date: Tue, 29 Mar 2016 17:31:06 -0400 Subject: [PATCH 2/2] Add test for from_email parsing --- test/test_transmissions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_transmissions.py b/test/test_transmissions.py index 4b5fcc9..163ad85 100644 --- a/test/test_transmissions.py +++ b/test/test_transmissions.py @@ -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 ') + 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'],