fix(projekt-matching): final-review fixes — safe redeploy, poison-mail hardening, plan deviations note
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from unittest import mock
|
||||
|
||||
from projektmatch import ingest
|
||||
@@ -118,6 +120,42 @@ def test_alert_send_failure_still_trashes(tmp_path):
|
||||
box.move_to_trash.assert_called_once_with("1")
|
||||
|
||||
|
||||
def test_unreadable_mail_flagged_pipeline_continues(tmp_path):
|
||||
good = mail("Example 2 for Langflow process", PROJECT_HTML)
|
||||
box = mock.Mock()
|
||||
box.unchecked_uids.return_value = ["1", "2"]
|
||||
|
||||
def fetch_side_effect(uid):
|
||||
if uid == "1":
|
||||
raise RuntimeError("FETCH 1 fehlgeschlagen: NO")
|
||||
return good
|
||||
box.fetch.side_effect = fetch_side_effect
|
||||
espo = mock.Mock()
|
||||
espo.find_opportunity_by_link.return_value = None
|
||||
with mock.patch("projektmatch.ingest.mailparse.bodies",
|
||||
side_effect=lambda m: (m["html"], "")), \
|
||||
mock.patch("projektmatch.ingest.mailer.send_mail",
|
||||
lambda *a: None):
|
||||
summary = ingest.run_ingest(
|
||||
cfg(tmp_path), mailbox=box, espo=espo,
|
||||
resolve=lambda url: "https://www.freelancermap.de/projekt/eins",
|
||||
dispatch=lambda item: {"status": "created"})
|
||||
assert summary["unreadable"] == 1
|
||||
assert summary["created"] == 1
|
||||
box.flag_checked.assert_called_once_with("1")
|
||||
box.move_to_trash.assert_called_once_with("2")
|
||||
box.close.assert_called_once()
|
||||
|
||||
|
||||
def test_close_called_even_if_unchecked_uids_raises(tmp_path):
|
||||
box = mock.Mock()
|
||||
box.unchecked_uids.side_effect = RuntimeError("boom")
|
||||
espo = mock.Mock()
|
||||
with pytest.raises(RuntimeError):
|
||||
ingest.run_ingest(cfg(tmp_path), mailbox=box, espo=espo)
|
||||
box.close.assert_called_once()
|
||||
|
||||
|
||||
def test_parse_run_result_finds_status_json():
|
||||
inner = json.dumps({"status": "created", "mustMatch": 90})
|
||||
payload = {"outputs": [{"outputs": [{"results": {"text": {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import email
|
||||
|
||||
import pytest
|
||||
from unittest import mock
|
||||
|
||||
from projektmatch import mailer
|
||||
@@ -43,6 +45,22 @@ def test_move_uses_move_then_fallback():
|
||||
assert conn.expunge.called
|
||||
|
||||
|
||||
def test_fetch_raises_on_no_response():
|
||||
conn = fake_conn()
|
||||
conn.uid.return_value = ("NO", [None])
|
||||
box = mailer.MailBox("u", "p", conn=conn)
|
||||
with pytest.raises(RuntimeError):
|
||||
box.fetch("3")
|
||||
|
||||
|
||||
def test_fetch_raises_on_malformed_ok_response():
|
||||
conn = fake_conn()
|
||||
conn.uid.return_value = ("OK", [None])
|
||||
box = mailer.MailBox("u", "p", conn=conn)
|
||||
with pytest.raises(RuntimeError):
|
||||
box.fetch("3")
|
||||
|
||||
|
||||
def test_send_mail_starttls():
|
||||
with mock.patch("projektmatch.mailer.smtplib.SMTP") as smtp:
|
||||
server = smtp.return_value.__enter__.return_value
|
||||
|
||||
Reference in New Issue
Block a user