Skip to content

Commit

Permalink
Merge pull request #335 from mehronkugler/fix/334_unicode_values_in_s…
Browse files Browse the repository at this point in the history
…ubstitution_helper

Permit unicode string values with Substitution helper
  • Loading branch information
thinkingserious authored Aug 31, 2017
2 parents f6d9852 + 7f1734c commit fae1edb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sendgrid/helpers/mail/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,15 @@ def key(self):

@key.setter
def key(self, value):
self._key = str(value)
self._key = value

@property
def value(self):
return self._value

@value.setter
def value(self, value):
self._value = str(value)
self._value = value

def get(self):
substitution = {}
Expand Down
59 changes: 59 additions & 0 deletions test/test_mail.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import json

from sendgrid.helpers.mail import (
Expand Down Expand Up @@ -408,3 +409,61 @@ def test_kitchenSink(self):
json.dumps(mail.get(), sort_keys=True),
json.dumps(expected_result, sort_keys=True)
)

def test_unicode_values_in_substitutions_helper(self):

""" Test that the Substitutions helper accepts unicode values """

self.maxDiff = None

"""Minimum required to send an email"""
mail = Mail()

mail.from_email = Email("[email protected]")

mail.subject = "Testing unicode substitutions with the SendGrid Python Library"

personalization = Personalization()
personalization.add_to(Email("[email protected]"))
personalization.add_substitution(Substitution("%city%", u"Αθήνα"))
mail.add_personalization(personalization)

mail.add_content(Content("text/plain", "some text here"))
mail.add_content(
Content(
"text/html",
"<html><body>some text here</body></html>"))

expected_result = {
"content": [
{
"type": "text/plain",
"value": "some text here"
},
{
"type": "text/html",
"value": "<html><body>some text here</body></html>"
}
],
"from": {
"email": "[email protected]"
},
"personalizations": [
{
"substitutions": {
"%city%": u"Αθήνα"
},
"to": [
{
"email": "[email protected]"
}
]
}
],
"subject": "Testing unicode substitutions with the SendGrid Python Library",
}

self.assertEqual(
json.dumps(mail.get(), sort_keys=True),
json.dumps(expected_result, sort_keys=True)
)

0 comments on commit fae1edb

Please sign in to comment.