mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-01-30 23:08:59 -06:00
Chore: Switch to a local IMAP server instead of a real email service (#11913)
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
import os
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
|
||||
from paperless_mail.mail import MailAccountHandler
|
||||
@@ -9,53 +6,51 @@ from paperless_mail.models import MailAccount
|
||||
from paperless_mail.models import MailRule
|
||||
|
||||
|
||||
# Only run if the environment is setup
|
||||
# And the environment is not empty (forks, I think)
|
||||
@pytest.mark.skipif(
|
||||
"PAPERLESS_MAIL_TEST_HOST" not in os.environ
|
||||
or not len(os.environ["PAPERLESS_MAIL_TEST_HOST"]),
|
||||
reason="Live server testing not enabled",
|
||||
)
|
||||
@pytest.mark.django_db()
|
||||
class TestMailLiveServer:
|
||||
def test_process_non_gmail_server_flag(
|
||||
@pytest.mark.django_db
|
||||
class TestMailGreenmail:
|
||||
"""
|
||||
Mail tests using local Greenmail server
|
||||
"""
|
||||
|
||||
def test_process_flag(
|
||||
self,
|
||||
mail_account_handler: MailAccountHandler,
|
||||
live_mail_account: MailAccount,
|
||||
):
|
||||
greenmail_mail_account: MailAccount,
|
||||
) -> None:
|
||||
"""
|
||||
Test processing mail with FLAG action.
|
||||
"""
|
||||
rule = MailRule.objects.create(
|
||||
name="testrule",
|
||||
account=greenmail_mail_account,
|
||||
action=MailRule.MailAction.FLAG,
|
||||
)
|
||||
|
||||
try:
|
||||
rule1 = MailRule.objects.create(
|
||||
name="testrule",
|
||||
account=live_mail_account,
|
||||
action=MailRule.MailAction.FLAG,
|
||||
)
|
||||
|
||||
mail_account_handler.handle_mail_account(live_mail_account)
|
||||
|
||||
rule1.delete()
|
||||
|
||||
mail_account_handler.handle_mail_account(greenmail_mail_account)
|
||||
except MailError as e:
|
||||
pytest.fail(f"Failure: {e}")
|
||||
except Exception as e:
|
||||
warnings.warn(f"Unhandled exception: {e}")
|
||||
finally:
|
||||
rule.delete()
|
||||
|
||||
def test_process_non_gmail_server_tag(
|
||||
def test_process_tag(
|
||||
self,
|
||||
mail_account_handler: MailAccountHandler,
|
||||
live_mail_account: MailAccount,
|
||||
):
|
||||
greenmail_mail_account: MailAccount,
|
||||
) -> None:
|
||||
"""
|
||||
Test processing mail with TAG action.
|
||||
"""
|
||||
rule = MailRule.objects.create(
|
||||
name="testrule",
|
||||
account=greenmail_mail_account,
|
||||
action=MailRule.MailAction.TAG,
|
||||
action_parameter="TestTag",
|
||||
)
|
||||
|
||||
try:
|
||||
rule2 = MailRule.objects.create(
|
||||
name="testrule",
|
||||
account=live_mail_account,
|
||||
action=MailRule.MailAction.TAG,
|
||||
)
|
||||
|
||||
mail_account_handler.handle_mail_account(live_mail_account)
|
||||
|
||||
rule2.delete()
|
||||
|
||||
mail_account_handler.handle_mail_account(greenmail_mail_account)
|
||||
except MailError as e:
|
||||
pytest.fail(f"Failure: {e}")
|
||||
except Exception as e:
|
||||
warnings.warn(f"Unhandled exception: {e}")
|
||||
finally:
|
||||
rule.delete()
|
||||
|
||||
Reference in New Issue
Block a user