Courrier v1.7 (tt-2026-11-070) : suivi des demandes par fil de discussion, clore et rouvrir, avertissement de fraicheur
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XGaEeWkqZYNP6Wn3mGQsrL
This commit is contained in:
1 parent
b712ee10cd
commit
44bfbc3a0c
8 files changed
+336
-10
No files matched your search
@@ -0,0 +1,105 @@
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app, mirror_client
|
||||
from app.suivi import calculer_suivi, sujet_normalise
|
||||
|
||||
STATIC = Path(__file__).resolve().parent.parent / "app" / "static"
|
||||
MOI = "Nabil.Derouiche <Nabil.Derouiche@tunisietelecom.tn>"
|
||||
AUTRE = "Ali Ben Salah <ali@exemple.tn>"
|
||||
NOW = datetime(2026, 11, 18, 10, 0, tzinfo=timezone(timedelta(hours=1)))
|
||||
|
||||
|
||||
def mail(i, jour, objet, exp, dest, hh="09:00:00"):
|
||||
return {"message_id": f"m{i}", "date": f"2026-11-{jour:02d}T{hh}+01:00", "objet": objet, "expediteur": exp, "destinataires": dest, "etiquettes": []}
|
||||
|
||||
|
||||
def etats(mails, clos=None):
|
||||
return {i["cle"]: i for i in calculer_suivi(mails, "nabil.derouiche@", NOW, clos or {})}
|
||||
|
||||
|
||||
def test_sujet_normalise():
|
||||
assert sujet_normalise("RE: TR: Fwd : Demande de prix ") == "demande de prix"
|
||||
assert sujet_normalise("") == ""
|
||||
|
||||
|
||||
def test_en_attente_et_relance():
|
||||
e = etats([mail(1, 12, "Demande de prix", MOI, AUTRE)])
|
||||
i = e["demande de prix"]
|
||||
assert i["etat"] == "attente" and i["jours"] == 6 and i["relancer"] is True and i["avec"] == "Ali Ben Salah"
|
||||
e = etats([mail(1, 17, "Demande de prix", MOI, AUTRE)])
|
||||
assert e["demande de prix"]["relancer"] is False
|
||||
|
||||
|
||||
def test_reponse_recue_et_a_repondre():
|
||||
fil = [mail(1, 12, "Offre", MOI, AUTRE), mail(2, 14, "RE: Offre", AUTRE, MOI)]
|
||||
assert etats(fil)["offre"]["etat"] == "reponse"
|
||||
assert etats([mail(3, 15, "Question", AUTRE, MOI)])["question"]["etat"] == "a_repondre"
|
||||
|
||||
|
||||
def test_copie_seulement_ignore():
|
||||
assert etats([mail(4, 15, "Info", AUTRE, "autre@exemple.tn, copie@exemple.tn")]) == {}
|
||||
|
||||
|
||||
def test_ma_reponse_ferme_la_demande_recue():
|
||||
fil = [mail(5, 15, "Question", AUTRE, MOI), mail(6, 16, "RE: Question", MOI, AUTRE)]
|
||||
assert etats(fil)["question"]["etat"] == "attente"
|
||||
|
||||
|
||||
def test_clos_tient_jusqu_au_nouveau_message():
|
||||
fil = [mail(7, 12, "Sujet", MOI, AUTRE)]
|
||||
assert etats(fil, {"sujet": "m7"})["sujet"]["clos"] is True
|
||||
fil.append(mail(8, 16, "RE: Sujet", AUTRE, MOI))
|
||||
assert etats(fil, {"sujet": "m7"})["sujet"]["clos"] is False
|
||||
|
||||
|
||||
def test_sujet_vide_ignore_et_ordre():
|
||||
fil = [mail(9, 10, "", MOI, AUTRE), mail(10, 16, "B", MOI, AUTRE), mail(11, 11, "A", MOI, AUTRE), mail(12, 15, "C", AUTRE, MOI), mail(13, 16, "D", AUTRE, MOI)]
|
||||
sortie = calculer_suivi(fil, "nabil.derouiche@", NOW, {})
|
||||
assert [i["sujet"] for i in sortie] == ["A", "B", "D", "C"]
|
||||
|
||||
|
||||
def test_suivi_exige_le_jeton():
|
||||
assert TestClient(app).get("/api/v1/suivi").status_code == 401
|
||||
|
||||
|
||||
def test_endpoint_suivi_et_cloture(client, monkeypatch):
|
||||
jour = datetime.now(timezone(timedelta(hours=1))) - timedelta(days=5)
|
||||
iso = jour.strftime("%Y-%m-%dT09:00:00+01:00")
|
||||
envoye = {"message_id": "e1", "date": iso, "objet": "Besoin cables", "expediteur": MOI, "destinataires": AUTRE, "etiquettes": []}
|
||||
monkeypatch.setattr(mirror_client, "get_mails_since", lambda debut, max_items=800: [])
|
||||
monkeypatch.setattr(mirror_client, "get_sent_mails", lambda n=100: [envoye])
|
||||
j = client.get("/api/v1/suivi?jours=14").json()
|
||||
assert j["compte"] == {"attente": 1, "reponse": 0, "a_repondre": 0, "clos": 0}
|
||||
assert j["items"][0]["relancer"] is True
|
||||
assert client.post("/api/v1/suivi/clore", json={"cle": "besoin cables", "dernier_id": "e1"}).status_code == 200
|
||||
j = client.get("/api/v1/suivi?jours=14").json()
|
||||
assert j["compte"]["attente"] == 0 and j["compte"]["clos"] == 1 and j["items"][0]["clos"] is True
|
||||
client.post("/api/v1/suivi/rouvrir", json={"cle": "besoin cables"})
|
||||
assert client.get("/api/v1/suivi?jours=14").json()["compte"]["attente"] == 1
|
||||
|
||||
|
||||
def test_suivi_miroir_indisponible(client, monkeypatch):
|
||||
def casse(*a, **k): raise ConnectionError("x")
|
||||
monkeypatch.setattr(mirror_client, "get_mails_since", casse)
|
||||
assert client.get("/api/v1/suivi").status_code == 502
|
||||
|
||||
|
||||
def test_interface_suivi():
|
||||
js = (STATIC / "app.js").read_text(encoding="utf-8")
|
||||
assert "vueSuivi" in js and "chargerSuivi" in js and "innerHTML" not in js
|
||||
|
||||
|
||||
def test_envois_automatiques_et_a_soi_meme_ignores():
|
||||
fil = [mail(20, 15, "Rappel perso", MOI, MOI), mail(21, 15, "Alerte", "noreply@exemple.tn", MOI), mail(22, 15, "Vrai besoin", MOI, AUTRE)]
|
||||
assert set(etats(fil)) == {"vrai besoin"}
|
||||
|
||||
|
||||
def test_fraicheur_des_messages_envoyes(client, monkeypatch):
|
||||
ancien = {"message_id": "e0", "date": "2026-11-01T09:00:00+01:00", "objet": "Vieux", "expediteur": MOI, "destinataires": AUTRE, "etiquettes": []}
|
||||
monkeypatch.setattr(mirror_client, "get_mails_since", lambda debut, max_items=800: [])
|
||||
monkeypatch.setattr(mirror_client, "get_sent_mails", lambda n=100: [ancien])
|
||||
j = client.get("/api/v1/suivi").json()
|
||||
assert j["envoyes_a_jour"] is False and j["envoyes_jusqu_au"] == "2026-11-01"
|
||||
Reference in new issue
Block a user