-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #335 from mehronkugler/fix/334_unicode_values_in_s…
…ubstitution_helper Permit unicode string values with Substitution helper
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
import json | ||
|
||
from sendgrid.helpers.mail import ( | ||
|
@@ -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) | ||
) |