Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Enable some testing against a real email server to hopefully catch things earlier

Trenton H97ceb1a8a68d
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6b97837c8..b516bbce7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -92,7 +92,12 @@ jobs:
ports:
- "3000:3000/tcp"
env:
+ # Enable Tika end to end testing
TIKA_LIVE: 1
+ # Enable paperless_mail testing against real server
+ PAPERLESS_MAIL_TEST_HOST: ${{ secrets.TEST_MAIL_HOST }}
+ PAPERLESS_MAIL_TEST_USER: ${{ secrets.TEST_MAIL_USER }}
+ PAPERLESS_MAIL_TEST_PASSWD: ${{ secrets.TEST_MAIL_PASSWD }}
steps:
-
name: Checkout
diff --git a/src/paperless_mail/tests/test_live_mail.py b/src/paperless_mail/tests/test_live_mail.py
new file mode 100644
index 000000000..1af870156
--- /dev/null
+++ b/src/paperless_mail/tests/test_live_mail.py
@@ -0,0 +1,70 @@
+import os
+
+import pytest
+from django.test import TestCase
+from paperless_mail.mail import MailAccountHandler
+from paperless_mail.mail import MailError
+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)
+ "PAPERLESS_MAIL_TEST_HOST" not in os.environ
+ or not len(os.environ["PAPERLESS_MAIL_TEST_HOST"]),
+ reason="Live server testing not enabled",
+)
+class TestMailLiveServer(TestCase):
+ def setUp(self) -> None:
+
+ self.mail_account_handler = MailAccountHandler()
+ self.account = MailAccount.objects.create(
+ name="test",
+ imap_server=os.environ["PAPERLESS_MAIL_TEST_HOST"],
+ username=os.environ["PAPERLESS_MAIL_TEST_USER"],
+ password=os.environ["PAPERLESS_MAIL_TEST_PASSWD"],
+ imap_port=993,
+ )
+
+ return super().setUp()
+
+ def tearDown(self) -> None:
+ self.account.delete()
+ return super().tearDown()
+
+ def test_process_non_gmail_server_flag(self):
+
+ try:
+ rule1 = MailRule.objects.create(
+ name="testrule",
+ account=self.account,
+ action=MailRule.MailAction.FLAG,
+ )
+
+ self.mail_account_handler.handle_mail_account(self.account)
+
+ rule1.delete()
+
+ except MailError as e:
+ self.fail(f"Failure: {e}")
+ except Exception as e:
+ pass
+
+ def test_process_non_gmail_server_tag(self):
+
+ try:
+
+ rule2 = MailRule.objects.create(
+ name="testrule",
+ account=self.account,
+ action=MailRule.MailAction.TAG,
+ )
+
+ self.mail_account_handler.handle_mail_account(self.account)
+
+ rule2.delete()
+
+ except MailError as e:
+ self.fail(f"Failure: {e}")
+ except Exception as e:
+ pass