Skip to content

Commit fae1edb

Browse files
Merge pull request #335 from mehronkugler/fix/334_unicode_values_in_substitution_helper
Permit unicode string values with Substitution helper
2 parents f6d9852 + 7f1734c commit fae1edb

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

sendgrid/helpers/mail/mail.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ def key(self):
384384

385385
@key.setter
386386
def key(self, value):
387-
self._key = str(value)
387+
self._key = value
388388

389389
@property
390390
def value(self):
391391
return self._value
392392

393393
@value.setter
394394
def value(self, value):
395-
self._value = str(value)
395+
self._value = value
396396

397397
def get(self):
398398
substitution = {}

test/test_mail.py

+59
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
import json
23

34
from sendgrid.helpers.mail import (
@@ -408,3 +409,61 @@ def test_kitchenSink(self):
408409
json.dumps(mail.get(), sort_keys=True),
409410
json.dumps(expected_result, sort_keys=True)
410411
)
412+
413+
def test_unicode_values_in_substitutions_helper(self):
414+
415+
""" Test that the Substitutions helper accepts unicode values """
416+
417+
self.maxDiff = None
418+
419+
"""Minimum required to send an email"""
420+
mail = Mail()
421+
422+
mail.from_email = Email("[email protected]")
423+
424+
mail.subject = "Testing unicode substitutions with the SendGrid Python Library"
425+
426+
personalization = Personalization()
427+
personalization.add_to(Email("[email protected]"))
428+
personalization.add_substitution(Substitution("%city%", u"Αθήνα"))
429+
mail.add_personalization(personalization)
430+
431+
mail.add_content(Content("text/plain", "some text here"))
432+
mail.add_content(
433+
Content(
434+
"text/html",
435+
"<html><body>some text here</body></html>"))
436+
437+
expected_result = {
438+
"content": [
439+
{
440+
"type": "text/plain",
441+
"value": "some text here"
442+
},
443+
{
444+
"type": "text/html",
445+
"value": "<html><body>some text here</body></html>"
446+
}
447+
],
448+
"from": {
449+
"email": "[email protected]"
450+
},
451+
"personalizations": [
452+
{
453+
"substitutions": {
454+
"%city%": u"Αθήνα"
455+
},
456+
"to": [
457+
{
458+
"email": "[email protected]"
459+
}
460+
]
461+
}
462+
],
463+
"subject": "Testing unicode substitutions with the SendGrid Python Library",
464+
}
465+
466+
self.assertEqual(
467+
json.dumps(mail.get(), sort_keys=True),
468+
json.dumps(expected_result, sort_keys=True)
469+
)

0 commit comments

Comments
 (0)