test: cover forensic report edge cases

This commit is contained in:
Christian Krakau-Louis
2026-05-23 12:59:47 +02:00
parent 1f954c9e08
commit 908d4cd2cd
4 changed files with 229 additions and 6 deletions
+42
View File
@@ -465,6 +465,48 @@ class TestProcessMessage:
assert db_session.query(DMARCReport).count() == 0
assert db_session.query(ForensicReport).count() == 1
def test_forensic_report_without_database_is_skipped(self):
client = _make_client()
stats = {"forensic_reports_found": 0, "duplicate_forensic_reports": 0, "errors": []}
imported = client._process_forensic_message(
SAMPLE_FORENSIC_EMAIL,
stats,
message_id="msg-forensic",
)
assert imported is False
assert stats["details"][0]["reason"] == "forensic_report_requires_database"
def test_duplicate_forensic_report_is_skipped(self, db_session):
client = _make_client(db=db_session)
stats = {"forensic_reports_found": 0, "duplicate_forensic_reports": 0, "errors": []}
assert client._process_forensic_message(SAMPLE_FORENSIC_EMAIL, stats, message_id="msg-1")
imported = client._process_forensic_message(
SAMPLE_FORENSIC_EMAIL,
stats,
message_id="msg-1",
)
assert imported is False
assert stats["duplicate_forensic_reports"] == 1
assert stats["details"][1]["status"] == "duplicate"
def test_forensic_parse_error_adds_error_detail(self, db_session):
client = _make_client(db=db_session)
stats = {"errors": []}
imported = client._process_forensic_message(
b"Subject: not forensic\r\n\r\nbody",
stats,
message_id="bad",
)
assert imported is False
assert stats["errors"]
assert stats["details"][0]["reason"] == "forensic_parse_failed"
# ===========================================================================
# _process_attachments