From 4c62f7bee03b29751fbaabc33ed4d00ef6340ff5 Mon Sep 17 00:00:00 2001 From: Mike Edmunds Date: Thu, 16 May 2024 11:39:48 -0700 Subject: [PATCH] Tests: fix broken inbound test Django SafeMIMEText corner case behaves differently in Python 3.11.9+, 3.12.3+, likely due to https://github.com/python/cpython/pull/116125 --- tests/test_inbound.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_inbound.py b/tests/test_inbound.py index 23e6ed70..40be0873 100644 --- a/tests/test_inbound.py +++ b/tests/test_inbound.py @@ -3,7 +3,6 @@ from email.utils import collapse_rfc2231_value from textwrap import dedent -from django.core.mail import SafeMIMEText from django.test import SimpleTestCase from anymail.exceptions import AnymailDeprecationWarning @@ -245,7 +244,17 @@ def test_parse_raw_mime_8bit_utf8(self): # (This might be a Django bug; plain old MIMEText avoids the problem by using # 'Content-Transfer-Encoding: base64', which parses fine as text or bytes.) # Either way, AnymailInboundMessage should try to sidestep the whole issue. - raw = SafeMIMEText("Unicode ✓", "plain", "utf-8").as_string() + # (This test might no longer be relevant--this might have been a corner case + # in Django's SafeMIME code in Python 2.7 only.) + raw = dedent( + # django.core.mail.message.SafeMIMEText("Unicode ✓", "plain", "utf-8").as_string() + """\ + Content-Type: text/plain; charset="utf-8" + MIME-Version: 1.0 + Content-Transfer-Encoding: 8bit + + Unicode ✓""" + ) msg = AnymailInboundMessage.parse_raw_mime(raw) self.assertEqual(msg.text, "Unicode ✓") # *not* "Unicode \\u2713"