Initial status for developed files on dagda
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,41 @@
|
||||
import unittest
|
||||
|
||||
from dagelijks_overzicht import apple_mail_url, bouw_html
|
||||
|
||||
|
||||
class DagelijksOverzichtTests(unittest.TestCase):
|
||||
def test_apple_mail_url_encodes_message_id(self):
|
||||
self.assertEqual(
|
||||
apple_mail_url("<abc.123@example.com>"),
|
||||
"message://%3Cabc.123%40example.com%3E",
|
||||
)
|
||||
|
||||
def test_apple_mail_url_wraps_bare_message_id(self):
|
||||
self.assertEqual(
|
||||
apple_mail_url("abc.123@example.com"),
|
||||
"message://%3Cabc.123%40example.com%3E",
|
||||
)
|
||||
|
||||
def test_bouw_html_links_subject_and_escapes_headers(self):
|
||||
html = bouw_html(
|
||||
{
|
||||
"INBOX.Test & Folder": [
|
||||
{
|
||||
"time": "08:15",
|
||||
"from": "Alice <admin>",
|
||||
"subject": "Factuur <juli>",
|
||||
"message_id": "<msg@example.com>",
|
||||
}
|
||||
]
|
||||
},
|
||||
__import__("datetime").date(2026, 7, 5),
|
||||
)
|
||||
|
||||
self.assertIn("message://%3Cmsg%40example.com%3E", html)
|
||||
self.assertIn("Alice <admin>", html)
|
||||
self.assertIn("Factuur <juli>", html)
|
||||
self.assertIn("Test & Folder", html)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,51 @@
|
||||
import base64
|
||||
import json
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from manage_routes_web import basic_auth_ok, load_routes, save_routes, validate_routes
|
||||
|
||||
|
||||
class ManageRoutesWebTests(unittest.TestCase):
|
||||
def test_validate_routes_normalizes_domains_and_mailbox(self):
|
||||
routes = validate_routes([
|
||||
{"domains": [" Example.COM ", "example.com"], "mailbox": " Diensten.Test "}
|
||||
])
|
||||
self.assertEqual(routes, [{"domains": ["example.com"], "mailbox": "Diensten.Test"}])
|
||||
|
||||
def test_validate_routes_rejects_duplicate_domain_across_routes(self):
|
||||
with self.assertRaisesRegex(ValueError, "already used"):
|
||||
validate_routes([
|
||||
{"domains": ["example.com"], "mailbox": "Diensten.Een"},
|
||||
{"domains": ["EXAMPLE.com"], "mailbox": "Diensten.Twee"},
|
||||
])
|
||||
|
||||
def test_save_routes_writes_backup_and_normalized_json(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / "domain_routes.json"
|
||||
path.write_text(
|
||||
json.dumps([{"domains": ["old.example"], "mailbox": "Diensten.Oud"}]) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
saved = save_routes(
|
||||
[{"domains": [" New.EXAMPLE "], "mailbox": " Diensten.Nieuw "}],
|
||||
path,
|
||||
)
|
||||
|
||||
self.assertEqual(saved, [{"domains": ["new.example"], "mailbox": "Diensten.Nieuw"}])
|
||||
self.assertEqual(load_routes(path), saved)
|
||||
backup = path.with_suffix(".json.bak")
|
||||
self.assertTrue(backup.exists())
|
||||
self.assertIn("old.example", backup.read_text(encoding="utf-8"))
|
||||
|
||||
def test_basic_auth_ok_accepts_exact_credentials(self):
|
||||
token = base64.b64encode(b"mailcat:secret").decode("ascii")
|
||||
self.assertTrue(basic_auth_ok(f"Basic {token}", "mailcat", "secret"))
|
||||
self.assertFalse(basic_auth_ok(f"Basic {token}", "mailcat", "wrong"))
|
||||
self.assertFalse(basic_auth_ok(None, "mailcat", "secret"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,50 @@
|
||||
import unittest
|
||||
|
||||
from mail_imap_ops import destination_from_header
|
||||
from sort_mail_daemon import mark_processed, processed_set, reset_on_uidvalidity_change
|
||||
|
||||
|
||||
class SortMailDaemonTests(unittest.TestCase):
|
||||
def test_destination_from_header_routes_ai_provider(self):
|
||||
header = (
|
||||
b"From: Claude Team <hello@claude.com>\r\n"
|
||||
b"Subject: Product update\r\n"
|
||||
b"Date: Tue, 01 Jul 2025 10:00:00 +0000\r\n"
|
||||
b"\r\n"
|
||||
)
|
||||
self.assertEqual(destination_from_header(header), "INBOX.Diensten.AI.Claude")
|
||||
|
||||
def test_destination_from_header_routes_invoice_by_quarter(self):
|
||||
header = (
|
||||
b"From: Billing <billing@example.com>\r\n"
|
||||
b"Subject: Your invoice\r\n"
|
||||
b"Date: Tue, 15 Apr 2025 10:00:00 +0000\r\n"
|
||||
b"\r\n"
|
||||
)
|
||||
self.assertEqual(destination_from_header(header), "INBOX.Financieel.Facturen.2025.Q2")
|
||||
|
||||
def test_destination_from_header_returns_none_for_unmatched(self):
|
||||
header = (
|
||||
b"From: Person <person@example.invalid>\r\n"
|
||||
b"Subject: Hello\r\n"
|
||||
b"Date: Tue, 01 Jul 2025 10:00:00 +0000\r\n"
|
||||
b"\r\n"
|
||||
)
|
||||
self.assertIsNone(destination_from_header(header))
|
||||
|
||||
def test_uidvalidity_change_resets_processed_uids(self):
|
||||
state = {"folder_state": {"INBOX": {"uidvalidity": "1", "processed_uids": ["10"]}}}
|
||||
reset_on_uidvalidity_change(state, "INBOX", "2")
|
||||
self.assertEqual(processed_set(state, "INBOX"), set())
|
||||
self.assertEqual(state["folder_state"]["INBOX"]["uidvalidity"], "2")
|
||||
|
||||
def test_mark_processed_is_idempotent(self):
|
||||
state = {"folder_state": {}}
|
||||
mark_processed(state, "INBOX", "2")
|
||||
mark_processed(state, "INBOX", "2")
|
||||
mark_processed(state, "INBOX", "1")
|
||||
self.assertEqual(state["folder_state"]["INBOX"]["processed_uids"], ["1", "2"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user