Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XGaEeTZLvHXfYPUNWkgYoi
36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
import pytest
|
|
from app import brouillon as b, ia
|
|
|
|
|
|
def test_assainir_garde_la_mise_en_page_et_retire_le_dangereux():
|
|
h = b.assainir('<p onclick="x()">Bonjour <strong>Samia</strong></p><script>alert(1)</script><a href="http://x">lien</a><ul><li>un</li></ul>')
|
|
assert h == "<p>Bonjour <strong>Samia</strong></p>lien<ul><li>un</li></ul>"
|
|
assert "onclick" not in h and "script" not in h and "href" not in h
|
|
|
|
|
|
def test_assainir_ferme_les_balises_et_echappe():
|
|
assert b.assainir("<p>a < b <strong>gras") == "<p>a < b <strong>gras</strong></p>"
|
|
|
|
|
|
def test_texte_brut():
|
|
assert b.en_texte("<p>Bonjour,</p><p>Merci.<br>A bientot</p><ul><li>un</li></ul>") == "Bonjour,\nMerci.\nA bientot\n- un"
|
|
|
|
|
|
def test_rediger_via_privaite_seulement(monkeypatch):
|
|
vus = {}
|
|
def faux(messages, max_tokens=30):
|
|
vus["m"] = messages
|
|
return "```html\n<p>Bonjour,</p><p>C'est note.</p><p>Cordialement,<br>Nabil Derouiche</p>\n```"
|
|
monkeypatch.setattr(ia, "appeler_privaite", faux)
|
|
r = b.rediger("PO 123", "x@tt.tn", "Merci de confirmer", "- ctx", "dire oui")
|
|
assert r["objet"] == "RE: PO 123" and "<p>Bonjour,</p>" in r["html"] and "```" not in r["html"]
|
|
assert "Contexte du fil" in vus["m"][1]["content"] and "dire oui" in vus["m"][1]["content"]
|
|
|
|
|
|
def test_refus_net_si_privaite_injoignable(monkeypatch):
|
|
def casse(messages, max_tokens=30):
|
|
raise ia.IAIndisponible("PrivAiTe injoignable")
|
|
monkeypatch.setattr(ia, "appeler_privaite", casse)
|
|
with pytest.raises(ia.IAIndisponible):
|
|
b.rediger("o", "e", "c")
|