mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
add unittest for get_thumbnail
This commit is contained in:
parent
cdd2b99b6b
commit
261c6fb990
src/paperless_mail/tests
23
src/paperless_mail/tests/samples/simple_text.eml
Normal file
23
src/paperless_mail/tests/samples/simple_text.eml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
Return-Path: <mail@someserver.de>
|
||||||
|
Delivered-To: mail@someserver.de
|
||||||
|
Received: from mail.someserver.org ([::1])
|
||||||
|
by e1acdba3bd07 with LMTP
|
||||||
|
id KBKZGD2YR2NTCgQAjubtDA
|
||||||
|
(envelope-from <mail@someserver.de>)
|
||||||
|
for <mail@someserver.de>; Wed, 10 Oct 2022 11:40:46 +0200
|
||||||
|
Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2BC9064C1616
|
||||||
|
for <some@one.de>; Wed, 12 Oct 2022 21:40:46 +0200 (CEST)
|
||||||
|
Message-ID: <6e99e34d-e20a-80c4-ea61-d8234b612be9@someserver.de>
|
||||||
|
Date: Wed, 12 Oct 2022 21:40:43 +0200
|
||||||
|
MIME-Version: 1.0
|
||||||
|
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
|
||||||
|
Thunderbird/102.3.1
|
||||||
|
Content-Language: en-US
|
||||||
|
To: some@one.de
|
||||||
|
From: Some One <mail@someserver.de>
|
||||||
|
Content-Type: text/plain; charset=UTF-8; format=flowed
|
||||||
|
Content-Transfer-Encoding: 7bit
|
||||||
|
X-Last-TLS-Session-Version: TLSv1.3
|
||||||
|
Subject: Simple Text Mail
|
||||||
|
|
||||||
|
This is just a simple Text Mail.
|
39
src/paperless_mail/tests/test_eml.py
Normal file
39
src/paperless_mail/tests/test_eml.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import hashlib
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
from paperless_mail.parsers import MailDocumentParser
|
||||||
|
|
||||||
|
|
||||||
|
class TestParser(TestCase):
|
||||||
|
SAMPLE_FILES = os.path.join(os.path.dirname(__file__), "samples")
|
||||||
|
|
||||||
|
def test_thumbnail(self):
|
||||||
|
def hashfile(file):
|
||||||
|
buf_size = 65536 # An arbitrary (but fixed) buffer
|
||||||
|
sha256 = hashlib.sha256()
|
||||||
|
with open(file, "rb") as f:
|
||||||
|
while True:
|
||||||
|
data = f.read(buf_size)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
sha256.update(data)
|
||||||
|
return sha256.hexdigest()
|
||||||
|
|
||||||
|
parser = MailDocumentParser(None)
|
||||||
|
thumb = parser.get_thumbnail(
|
||||||
|
os.path.join(self.SAMPLE_FILES, "simple_text.eml"),
|
||||||
|
"message/rfc822",
|
||||||
|
)
|
||||||
|
self.assertTrue(os.path.isfile(thumb))
|
||||||
|
thumb_hash = hashfile(thumb)
|
||||||
|
|
||||||
|
# The created intermediary pdf is not reproducible. But the thumbnail image should always look the same.
|
||||||
|
expected_hash = (
|
||||||
|
"18a2513c80584e538c4a129e8a2b0ce19bf0276eab9c95b72fa93e941db38d12"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
thumb_hash,
|
||||||
|
expected_hash,
|
||||||
|
"Thumbnail file hash not as expected.",
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user