Files
forwarder/tests/test_smtp_forward.py
T
1sonhador 0f4bb5f522 feat: BizDocs API delivery, WebDAV source, and invoice validation
Add optional API upload alongside SMTP, Nextcloud/WebDAV as a document source with the same dedup/retry flow as IMAP, stricter invoice file checks for images, and admin UI for source and delivery modes.
2026-07-02 19:21:01 +01:00

78 lines
2.4 KiB
Python

"""Outbound forward sends a clean message with invoice attachments only."""
from __future__ import annotations
from email.message import EmailMessage
from forwarder.email.smtp_client import build_forward_message
def test_forward_sends_clean_message_with_pdf_only():
original = EmailMessage()
original["From"] = "[email protected]"
original["To"] = "[email protected]"
original["Subject"] = "Invoice & Ticket Delivery"
original["X-SG-EID"] = "spam-marker"
original.set_content("marketing body")
original.add_attachment(
b"%PDF-1.4\n" + (b"x" * 1200),
maintype="application",
subtype="pdf",
filename="fatura.pdf",
)
outbound = build_forward_message(
original,
from_addr="[email protected]",
destination_email="[email protected]",
)
assert outbound["From"] == "[email protected]"
assert outbound["To"] == "[email protected]"
assert outbound["Subject"] == "Invoice & Ticket Delivery"
assert not outbound["Subject"].lower().startswith("fwd:")
assert outbound.get("Cc") is None
assert outbound.get("X-SG-EID") is None
attachments = list(outbound.iter_attachments())
assert len(attachments) == 1
assert attachments[0].get_filename() == "fatura.pdf"
assert attachments[0].get_content_type() == "application/pdf"
text_parts = [
p.get_content()
for p in outbound.walk()
if not p.is_multipart() and p.get_content_type() == "text/plain"
]
assert text_parts
assert "Remetente original" in text_parts[0]
assert "marketing body" not in text_parts[0]
def test_forward_includes_multiple_invoice_types():
original = EmailMessage()
original["Subject"] = "Docs"
original.set_content("x")
original.add_attachment(
b"%PDF-1.4\n" + (b"x" * 1200),
maintype="application",
subtype="pdf",
filename="a.pdf",
)
original.add_attachment(
b'<?xml version="1.0" encoding="UTF-8"?>'
b"<Invoice><Id>1</Id><Line>item description</Line><Total>10.00</Total></Invoice>",
maintype="text",
subtype="xml",
filename="b.xml",
)
outbound = build_forward_message(
original,
from_addr="[email protected]",
destination_email="[email protected]",
)
names = {p.get_filename() for p in outbound.iter_attachments()}
assert names == {"a.pdf", "b.xml"}