mail tests

This commit is contained in:
jonaswinkler 2021-01-18 22:23:53 +01:00
parent 4fda8f3348
commit e1e11de2b5

View File

@ -1,3 +1,4 @@
import os
import uuid
from collections import namedtuple
from typing import ContextManager
@ -9,6 +10,7 @@ from django.test import TestCase
from imap_tools import MailMessageFlags, MailboxFolderSelectError
from documents.models import Correspondent
from documents.tests.utils import DirectoriesMixin
from paperless_mail import tasks
from paperless_mail.mail import MailError, MailAccountHandler
from paperless_mail.models import MailRule, MailAccount
@ -130,7 +132,7 @@ def fake_magic_from_buffer(buffer, mime=False):
@mock.patch('paperless_mail.mail.magic.from_buffer', fake_magic_from_buffer)
class TestMail(TestCase):
class TestMail(DirectoriesMixin, TestCase):
def setUp(self):
patcher = mock.patch('paperless_mail.mail.MailBox')
@ -146,6 +148,7 @@ class TestMail(TestCase):
self.reset_bogus_mailbox()
self.mail_account_handler = MailAccountHandler()
super(TestMail, self).setUp()
def reset_bogus_mailbox(self):
self.bogus_mailbox.messages = []
@ -220,9 +223,13 @@ class TestMail(TestCase):
args1, kwargs1 = self.async_task.call_args_list[0]
args2, kwargs2 = self.async_task.call_args_list[1]
self.assertTrue(os.path.isfile(kwargs1['path']), kwargs1['path'])
self.assertEqual(kwargs1['override_title'], "file_0")
self.assertEqual(kwargs1['override_filename'], "file_0.pdf")
self.assertTrue(os.path.isfile(kwargs2['path']), kwargs1['path'])
self.assertEqual(kwargs2['override_title'], "file_1")
self.assertEqual(kwargs2['override_filename'], "file_1.pdf")
@ -253,6 +260,7 @@ class TestMail(TestCase):
self.assertEqual(self.async_task.call_count, 1)
args, kwargs = self.async_task.call_args
self.assertTrue(os.path.isfile(kwargs['path']), kwargs['path'])
self.assertEqual(kwargs['override_filename'], "f1.pdf")
def test_handle_disposition(self):