mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
add basic tests and fix error
This commit is contained in:
parent
195f3a5dbf
commit
6024a862d6
@ -101,13 +101,15 @@ class TagMailAction(BaseMailAction):
|
|||||||
raise MailError("Not a valid AppleMail tag color.")
|
raise MailError("Not a valid AppleMail tag color.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MailError(
|
raise MailError(
|
||||||
"""Could not parse the parameters.
|
"""Could not parse parameters.
|
||||||
Make sure they look like this: apple:<color>""",
|
Make sure they look like this: apple:<color> and
|
||||||
|
only use allowed colors.""",
|
||||||
) from e
|
) from e
|
||||||
self.keyword = None
|
self.keyword = None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.keyword = parameter
|
self.keyword = parameter
|
||||||
|
self.color = None
|
||||||
|
|
||||||
def get_criteria(self):
|
def get_criteria(self):
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ from imap_tools import NOT
|
|||||||
from paperless_mail import tasks
|
from paperless_mail import tasks
|
||||||
from paperless_mail.mail import MailAccountHandler
|
from paperless_mail.mail import MailAccountHandler
|
||||||
from paperless_mail.mail import MailError
|
from paperless_mail.mail import MailError
|
||||||
|
from paperless_mail.mail import TagMailAction
|
||||||
from paperless_mail.models import MailAccount
|
from paperless_mail.models import MailAccount
|
||||||
from paperless_mail.models import MailRule
|
from paperless_mail.models import MailRule
|
||||||
|
|
||||||
@ -674,6 +675,44 @@ class TestMail(DirectoriesMixin, TestCase):
|
|||||||
self.assertEqual(len(self.bogus_mailbox.fetch(criteria, False)), 0)
|
self.assertEqual(len(self.bogus_mailbox.fetch(criteria, False)), 0)
|
||||||
self.assertEqual(len(self.bogus_mailbox.messages), 3)
|
self.assertEqual(len(self.bogus_mailbox.messages), 3)
|
||||||
|
|
||||||
|
def test_tag_mail_action_applemail_wrong_input(self):
|
||||||
|
|
||||||
|
self.assertRaises(
|
||||||
|
MailError,
|
||||||
|
TagMailAction,
|
||||||
|
"apple:black",
|
||||||
|
)
|
||||||
|
self.assertRaises(
|
||||||
|
MailError,
|
||||||
|
TagMailAction,
|
||||||
|
"applegreen",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_handle_mail_account_tag_applemail(self):
|
||||||
|
# all mails will be FLAGGED afterwards
|
||||||
|
|
||||||
|
account = MailAccount.objects.create(
|
||||||
|
name="test",
|
||||||
|
imap_server="",
|
||||||
|
username="admin",
|
||||||
|
password="secret",
|
||||||
|
)
|
||||||
|
|
||||||
|
_ = MailRule.objects.create(
|
||||||
|
name="testrule",
|
||||||
|
account=account,
|
||||||
|
action=MailRule.MailAction.TAG,
|
||||||
|
action_parameter="apple:green",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(len(self.bogus_mailbox.messages), 3)
|
||||||
|
self.assertEqual(self.async_task.call_count, 0)
|
||||||
|
self.assertEqual(len(self.bogus_mailbox.fetch("UNFLAGGED", False)), 2)
|
||||||
|
self.mail_account_handler.handle_mail_account(account)
|
||||||
|
self.assertEqual(self.async_task.call_count, 2)
|
||||||
|
self.assertEqual(len(self.bogus_mailbox.fetch("UNFLAGGED", False)), 0)
|
||||||
|
self.assertEqual(len(self.bogus_mailbox.messages), 3)
|
||||||
|
|
||||||
def test_error_login(self):
|
def test_error_login(self):
|
||||||
account = MailAccount.objects.create(
|
account = MailAccount.objects.create(
|
||||||
name="test",
|
name="test",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user