mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-11 10:00:48 -05:00
UnitTests for inline attachment email
This commit is contained in:
parent
93d75fc6a2
commit
9ff4b6c6bc
8044
src/documents/tests/samples/inline_mail.txt
Normal file
8044
src/documents/tests/samples/inline_mail.txt
Normal file
File diff suppressed because it is too large
Load Diff
57
src/documents/tests/test_mail_inline.py
Normal file
57
src/documents/tests/test_mail_inline.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user