Skip to content

Commit

Permalink
Merge pull request #70 from puttu/recipient-str-fix
Browse files Browse the repository at this point in the history
fix: recipient emails can be provided as unicode strings
  • Loading branch information
richleland committed Feb 28, 2016
2 parents bc1bd23 + 2981025 commit c6dd1e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sparkpost/transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def _get_base64_from_file(self, filename):
def _extractRecipients(self, recipients):
formatted_recipients = []
for recip in recipients:
if isinstance(recip, str):
try:
string_types = basestring
except NameError:
string_types = str # Python 3 doesn't have basestring
if isinstance(recip, string_types):
formatted_recipients.append({'address': {'email': recip}})
else:
formatted_recipients.append(recip)
Expand Down
10 changes: 10 additions & 0 deletions test/test_transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def test_translate_keys_with_recips():
{'address': {'email': 'foobar'}}]


def test_translate_keys_with_unicode_recips():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=[u'unicode_email@example.com',
'str_email@example.com'])
assert results['recipients'] == [
{'address': {'email': 'unicode_email@example.com'}},
{'address': {'email': 'str_email@example.com'}}
]


@responses.activate
def test_success_send():
responses.add(
Expand Down

0 comments on commit c6dd1e9

Please sign in to comment.