UnitTests for inline attachment email

This commit is contained in:
Florian Harr 2016-04-14 13:01:03 -04:00
parent 93d75fc6a2
commit 9ff4b6c6bc
2 changed files with 8101 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
import base64
import os
import magic
from hashlib import md5
from unittest import mock
from django.conf import settings
from django.test import TestCase
from ..mail import Message, Attachment
class TestMessage(TestCase):
def __init__(self, *args, **kwargs):
TestCase.__init__(self, *args, **kwargs)
self.sample = os.path.join(
settings.BASE_DIR,
"documents",
"tests",
"samples",
"inline_mail.txt"
)
def test_init(self):
with open(self.sample, "rb") as f:
with mock.patch("logging.StreamHandler.emit") as __:
message = Message(f.read())
self.assertTrue(message)
self.assertEqual(message.subject, "Paperless Inline Image")
data = message.attachment.read()
self.assertEqual(
md5(data).hexdigest(), "30c00a7b42913e65f7fdb0be40b9eef3")
self.assertEqual(
message.attachment.content_type, "image/png")
with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m:
self.assertEqual(m.id_buffer(data), "image/png")
class TestAttachment(TestCase):
def test_init(self):
data = base64.encodebytes(b"0")
self.assertEqual(Attachment(data, "application/pdf").suffix, "pdf")
self.assertEqual(Attachment(data, "image/png").suffix, "png")
self.assertEqual(Attachment(data, "image/jpeg").suffix, "jpeg")
self.assertEqual(Attachment(data, "image/gif").suffix, "gif")
self.assertEqual(Attachment(data, "image/tiff").suffix, "tiff")
self.assertEqual(Attachment(data, "image/png").read(), data)