Drop Python 3.3-specific tests

This commit is contained in:
medmunds
2018-05-15 11:36:00 -07:00
parent 0e99bcf42e
commit d3ac4a1542
3 changed files with 2 additions and 29 deletions

View File

@@ -4,7 +4,6 @@ from __future__ import unicode_literals
import json import json
from datetime import datetime from datetime import datetime
from email.mime.application import MIMEApplication from email.mime.application import MIMEApplication
from unittest import skipIf
import botocore.config import botocore.config
import botocore.exceptions import botocore.exceptions
@@ -18,9 +17,7 @@ from mock import ANY, patch
from anymail.exceptions import AnymailAPIError, AnymailUnsupportedFeature from anymail.exceptions import AnymailAPIError, AnymailUnsupportedFeature
from anymail.inbound import AnymailInboundMessage from anymail.inbound import AnymailInboundMessage
from anymail.message import attach_inline_image_file, AnymailMessage from anymail.message import attach_inline_image_file, AnymailMessage
from .utils import ( from .utils import AnymailTestMixin, SAMPLE_IMAGE_FILENAME, sample_image_content, sample_image_path
AnymailTestMixin, SAMPLE_IMAGE_FILENAME, python_has_broken_mime_param_handling,
sample_image_content, sample_image_path)
@override_settings(EMAIL_BACKEND='anymail.backends.amazon_ses.EmailBackend') @override_settings(EMAIL_BACKEND='anymail.backends.amazon_ses.EmailBackend')
@@ -152,9 +149,6 @@ class AmazonSESBackendStandardEmailTests(AmazonSESBackendMockAPITestCase):
self.assertIn(b"\nCc: cc@xn--th-e0a.example.com\n", raw_mime) self.assertIn(b"\nCc: cc@xn--th-e0a.example.com\n", raw_mime)
# SES doesn't support non-ASCII in the username@ part (RFC 6531 "SMTPUTF8" extension) # SES doesn't support non-ASCII in the username@ part (RFC 6531 "SMTPUTF8" extension)
@skipIf(python_has_broken_mime_param_handling(),
"This Python has a buggy email package that crashes on non-ASCII "
"characters in RFC2231-encoded MIME header parameters")
def test_attachments(self): def test_attachments(self):
text_content = "• Item one\n• Item two\n• Item three" # those are \u2022 bullets ("\N{BULLET}") text_content = "• Item one\n• Item two\n• Item three" # those are \u2022 bullets ("\N{BULLET}")
self.message.attach(filename="Une pièce jointe.txt", # utf-8 chars in filename self.message.attach(filename="Une pièce jointe.txt", # utf-8 chars in filename

View File

@@ -5,14 +5,13 @@ import quopri
from base64 import b64encode from base64 import b64encode
from email.utils import collapse_rfc2231_value from email.utils import collapse_rfc2231_value
from textwrap import dedent from textwrap import dedent
from unittest import skipIf
from django.core.mail import SafeMIMEText from django.core.mail import SafeMIMEText
from django.test import SimpleTestCase from django.test import SimpleTestCase
from anymail.inbound import AnymailInboundMessage from anymail.inbound import AnymailInboundMessage
from .utils import SAMPLE_IMAGE_FILENAME, python_has_broken_mime_param_handling, sample_email_path, sample_image_content from .utils import SAMPLE_IMAGE_FILENAME, sample_email_path, sample_image_content
SAMPLE_IMAGE_CONTENT = sample_image_content() SAMPLE_IMAGE_CONTENT = sample_image_content()
@@ -566,9 +565,6 @@ class EmailParserWorkaroundTests(SimpleTestCase):
# Replace illegal encodings (rather than causing error): # Replace illegal encodings (rather than causing error):
self.assertEqual(msg["X-Broken"], "Not a char: \N{REPLACEMENT CHARACTER}.") self.assertEqual(msg["X-Broken"], "Not a char: \N{REPLACEMENT CHARACTER}.")
@skipIf(python_has_broken_mime_param_handling(),
"This Python has a buggy email package that crashes on non-ASCII "
"characters in RFC2231-encoded MIME header parameters")
def test_parse_encoded_params(self): def test_parse_encoded_params(self):
raw = dedent("""\ raw = dedent("""\
MIME-Version: 1.0 MIME-Version: 1.0

View File

@@ -300,20 +300,3 @@ class ClientWithCsrfChecks(Client):
def __init__(self, **defaults): def __init__(self, **defaults):
super(ClientWithCsrfChecks, self).__init__( super(ClientWithCsrfChecks, self).__init__(
enforce_csrf_checks=True, **defaults) enforce_csrf_checks=True, **defaults)
def python_has_broken_mime_param_handling():
# In Python 3.3 (only), trying to access any parsed MIME header will crash if the header
# has parameters with non-ASCII characters. (Common in, e.g., attachment filenames.)
# The bug is somewhere within email._header_value_parser.parse_mime_parameters, and is too
# complicated to work around for an uncommon version combination (Django 1.8 on Python 3.3).
# If you run into it, please upgrade to (at least) Python 3.4.
try:
from email.policy import default
default.header_fetch_parse("Content-Type", "plain; name*=iso-8859-1''Une%20pi%E8ce")
except ImportError:
return False # Python 2 (or pre Python 3.3) -- bug doesn't apply
except UnicodeEncodeError:
return True # this is the bug
else:
return False # worked fine