MCPcopy
hub / github.com/django/django / test_alternative_alternatives

Method test_alternative_alternatives

tests/mail/tests.py:780–800  ·  view source on GitHub ↗

Alternatives can be attached as either string or bytes and need not use a text/* mimetype.

(self)

Source from the content-addressed store, hash-verified

778 self.assertIn(html_content, msg.message().as_string())
779
780 def test_alternative_alternatives(self):
781 """
782 Alternatives can be attached as either string or bytes
783 and need not use a text/* mimetype.
784 """
785 cases = [
786 # (mimetype, content, expected decoded payload)
787 ("application/x-ccmail-rtf", b"non-text\x07bytes", b"non-text\x07bytes"),
788 ("application/x-ccmail-rtf", "non-text\x07string", b"non-text\x07string"),
789 ("text/x-amp-html", b"text bytes\n", b"text bytes\n"),
790 ("text/x-amp-html", "text string\n", b"text string\n"),
791 ]
792 for mimetype, content, expected in cases:
793 with self.subTest(case=(mimetype, content)):
794 email = EmailMultiAlternatives()
795 email.attach_alternative(content, mimetype)
796 msg = email.message()
797 self.assertEqual(msg.get_content_type(), "multipart/alternative")
798 alternative = msg.get_payload()[0]
799 self.assertEqual(alternative.get_content_type(), mimetype)
800 self.assertEqual(alternative.get_payload(decode=True), expected)
801
802 def test_alternatives_and_attachment_serializable(self):
803 html_content = "<p>This is <strong>html</strong></p>"

Callers

nothing calls this directly

Calls 4

attach_alternativeMethod · 0.95
messageMethod · 0.80
get_content_typeMethod · 0.45

Tested by

no test coverage detected