diff options
| author | nessita <124304+nessita@users.noreply.github.com> | 2025-04-24 10:11:16 -0300 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2025-04-24 10:12:32 -0300 |
| commit | 90fa9f4cc090d07bc59717120cc1a5a3a84e1acb (patch) | |
| tree | 119808c17a67c0db36d69fa73bbf3f5f924fcacb /tests/mail/tests.py | |
| parent | 7d80f70988d96b39bd613c755b91bdf7355c1d71 (diff) | |
[5.2.x] Fixed #36309 -- Made email alternatives and attachments pickleable.
Regression in aba0e541caaa086f183197eaaca0ac20a730bbe4 and in
d5bebc1c26d4c0ec9eaa057aefc5b38649c0ba3b.
Thanks Florent Messa for the report, and Jake Howard and Claude
Paroz for the review.
Backport of 0596263c3136bc26cffa670e5322bd0aa56c4d34 from main.
Diffstat (limited to 'tests/mail/tests.py')
| -rw-r--r-- | tests/mail/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/mail/tests.py b/tests/mail/tests.py index fe76974862..833b688741 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -1,5 +1,6 @@ import mimetypes import os +import pickle import shutil import socket import sys @@ -652,6 +653,23 @@ class MailTests(MailTestsMixin, SimpleTestCase): self.assertIn(html_content, msg.message().as_string()) + def test_alternatives_and_attachment_serializable(self): + html_content = "<p>This is <strong>html</strong></p>" + mime_type = "text/html" + + msg = EmailMultiAlternatives(alternatives=[(html_content, mime_type)]) + msg.attach("test.txt", "This is plain text.", "plain/text") + + # Alternatives and attachments can be serialized. + restored = pickle.loads(pickle.dumps(msg)) + + self.assertEqual(restored.subject, msg.subject) + self.assertEqual(restored.body, msg.body) + self.assertEqual(restored.from_email, msg.from_email) + self.assertEqual(restored.to, msg.to) + self.assertEqual(restored.alternatives, msg.alternatives) + self.assertEqual(restored.attachments, msg.attachments) + def test_none_body(self): msg = EmailMessage("subject", None, "from@example.com", ["to@example.com"]) self.assertEqual(msg.body, "") |
