1
0
Fork 0

Switch from nose to py.test.

This commit is contained in:
Adam Coddington 2016-05-14 22:06:32 -07:00
parent 7bb816b9ce
commit b4a3cdc843
11 changed files with 140 additions and 156 deletions

View file

@ -1,5 +1,6 @@
import email.header
import logging
import os
import six
@ -9,19 +10,65 @@ from django.conf import settings
logger = logging.getLogger(__name__)
DEFAULT_CHARSET = getattr(
settings,
'DJANGO_MAILBOX_DEFAULT_CHARSET',
'iso8859-1',
)
def get_settings():
return {
'strip_unallowed_mimetypes': getattr(
settings,
'DJANGO_MAILBOX_STRIP_UNALLOWED_MIMETYPES',
False
),
'allowed_mimetypes': getattr(
settings,
'DJANGO_MAILBOX_ALLOWED_MIMETYPES',
[
'text/plain',
'text/html'
]
),
'text_stored_mimetypes': getattr(
settings,
'DJANGO_MAILBOX_TEXT_STORED_MIMETYPES',
[
'text/plain',
'text/html'
]
),
'altered_message_header': getattr(
settings,
'DJANGO_MAILBOX_ALTERED_MESSAGE_HEADER',
'X-Django-Mailbox-Altered-Message'
),
'attachment_interpolation_header': getattr(
settings,
'DJANGO_MAILBOX_ATTACHMENT_INTERPOLATION_HEADER',
'X-Django-Mailbox-Interpolate-Attachment'
),
'attachment_upload_to': getattr(
settings,
'DJANGO_MAILBOX_ATTACHMENT_UPLOAD_TO',
'mailbox_attachments/%Y/%m/%d/'
),
'store_original_message': getattr(
settings,
'DJANGO_MAILBOX_STORE_ORIGINAL_MESSAGE',
False
),
'default_charset': getattr(
settings,
'DJANGO_MAILBOX_default_charset',
'iso8859-1',
)
}
def convert_header_to_unicode(header):
default_charset = get_settings()['default_charset']
def _decode(value, encoding):
if isinstance(value, six.text_type):
return value
if not encoding or encoding == 'unknown-8bit':
encoding = DEFAULT_CHARSET
encoding = default_charset
return value.decode(encoding, 'replace')
try:
@ -36,9 +83,9 @@ def convert_header_to_unicode(header):
logger.exception(
'Errors encountered decoding header %s into encoding %s.',
header,
DEFAULT_CHARSET,
default_charset,
)
return unicode(header, DEFAULT_CHARSET, 'replace')
return unicode(header, default_charset, 'replace')
def get_body_from_message(message, maintype, subtype):
@ -78,3 +125,12 @@ def get_body_from_message(message, maintype, subtype):
body += this_part
return body
def get_attachment_save_path(instance, filename):
settings = get_settings()
return os.path.join(
settings['attachment_upload_to'],
filename,
)