Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sparkpost/transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ def send(self, **kwargs):
"""

payload = self._translate_keys(**kwargs)
results = self.request('POST', self.uri, data=json.dumps(payload))
data = json.dumps(payload, ensure_ascii=False).encode('utf-8')
results = self.request('POST', self.uri, data=data)
return results

def _fetch_get(self, transmission_id):
Expand Down
48 changes: 48 additions & 0 deletions test/test_transmissions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
import base64
import json
import os
Expand Down Expand Up @@ -339,3 +340,50 @@ def test_fail_delete():
with pytest.raises(SparkPostAPIException):
sp = SparkPost('fake-key')
sp.transmission.delete('foobar')


@responses.activate
def test_json_serialize_with_a_non_ascii_unicode_from_substitution_data():
responses.add(
responses.POST,
'https://api.sparkpost.com/api/v1/transmissions',
status=200,
content_type='application/json',
body='{"results": "yay"}'
)
sp = SparkPost('fake-key')
results = sp.transmission.send(recipients=[{
'address': {'email': 'unicode_email@example.com'},
'substitution_data': {'name': u'João'}
}])
assert results == 'yay'

results = sp.transmission.send(recipients=[{
'address': {'email': 'unicode_email@example.com'},
'substitution_data': {'name': u'😄'}
}])
assert results == 'yay'

results = sp.transmission.send(recipients=[{
'address': {'email': 'unicode_email@example.com'},
'substitution_data': {'name': u'漢字'}
}])
assert results == 'yay'


@responses.activate
def test_json_serialize_with_a_non_ascii_unicode_from_body():
responses.add(
responses.POST,
'https://api.sparkpost.com/api/v1/transmissions',
status=200,
content_type='application/json',
body='{"results": "yay"}'
)
sp = SparkPost('fake-key')
results = sp.transmission.send(recipients=[{
'address': {'email': 'unicode_email@example.com'},
'substitution_data': {'name': u'João 漢字'},
'text': u'Hello!!! 😄 my name is {{ name }}'
}])
assert results == 'yay'