MCPcopy
hub / github.com/django/django / test_encoding

Method test_encoding

tests/mail/tests.py:834–849  ·  view source on GitHub ↗

Regression for #12791 - Encode body correctly with other encodings than utf-8

(self)

Source from the content-addressed store, hash-verified

832 self.assertIn("@xn--p8s937b>", message["Message-ID"])
833
834 def test_encoding(self):
835 """
836 Regression for #12791 - Encode body correctly with other encodings
837 than utf-8
838 """
839 email = EmailMessage(body="Firstname Sürname is a great guy.\n")
840 email.encoding = "iso-8859-1"
841 message = email.message()
842 self.assertEqual(message["Content-Type"], 'text/plain; charset="iso-8859-1"')
843
844 # Check that body is actually encoded with iso-8859-1.
845 msg_bytes = message.as_bytes()
846 self.assertEqual(message["Content-Transfer-Encoding"], "8bit")
847 self.assertIn(b"Firstname S\xfc", msg_bytes)
848 parsed = message_from_bytes(msg_bytes)
849 self.assertEqual(parsed.get_content(), "Firstname Sürname is a great guy.\n")
850
851 def test_encoding_alternatives(self):
852 """

Callers

nothing calls this directly

Calls 4

messageMethod · 0.95
EmailMessageClass · 0.90
message_from_bytesFunction · 0.85
as_bytesMethod · 0.80

Tested by

no test coverage detected