|
| 1 | +# -*- coding: utf-8 -*- |
1 | 2 | import json
|
2 | 3 |
|
3 | 4 | from sendgrid.helpers.mail import (
|
@@ -408,3 +409,61 @@ def test_kitchenSink(self):
|
408 | 409 | json.dumps(mail.get(), sort_keys=True),
|
409 | 410 | json.dumps(expected_result, sort_keys=True)
|
410 | 411 | )
|
| 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 | + |
| 450 | + }, |
| 451 | + "personalizations": [ |
| 452 | + { |
| 453 | + "substitutions": { |
| 454 | + "%city%": u"Αθήνα" |
| 455 | + }, |
| 456 | + "to": [ |
| 457 | + { |
| 458 | + |
| 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