Conversations : le transcript lisible d'une conversation (texte seul, pièces jointes en lien)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
369f2e0a44
commit
116488ddd4
3 files changed
+139
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import unittest
|
||||
|
||||
from conversations.transcript import texte, transcript
|
||||
|
||||
CONV = {"subject": "Saut", "reference_number": "42", "inbox_name": "Support", "status": "Open",
|
||||
"created_at": "2026-11-18T08:00:00Z", "contact": {"first_name": "Jean", "last_name": "Dupont", "email": "j@x.ch"}}
|
||||
|
||||
|
||||
def piece(nom, type_):
|
||||
return {"name": nom, "content_type": type_, "size": 3, "url": f"attachments/{nom}", "uuid": "u-" + nom}
|
||||
|
||||
|
||||
def msg(heure, type_="incoming", expediteur="contact", prive=False, contenu="<p>Bonjour</p>", pieces=(), auteur=None):
|
||||
return {"created_at": f"2026-11-18T{heure}:00Z", "type": type_, "sender_type": expediteur, "private": prive,
|
||||
"content": contenu, "text_content": "", "attachments": list(pieces), "author": auteur}
|
||||
|
||||
|
||||
MESSAGES = [
|
||||
msg("08:00", pieces=[piece("photo 1.jpg", "image/jpeg"), piece("r.pdf", "application/pdf")],
|
||||
auteur={"first_name": "Jean", "last_name": "Dupont"}),
|
||||
msg("08:05", type_="activity", expediteur="agent", contenu="Assigned to Max"),
|
||||
msg("08:10", type_="outgoing", expediteur="agent", prive=True, contenu="<p>À vérifier</p>",
|
||||
auteur={"first_name": "Max", "last_name": ""}),
|
||||
]
|
||||
|
||||
|
||||
class TestTexte(unittest.TestCase):
|
||||
def test_paragraphes_et_entites(self):
|
||||
self.assertEqual(texte("<p>Bonjour & merci</p><p>L1<br>L2</p>"), "Bonjour\xa0& merci\n\nL1\nL2")
|
||||
|
||||
def test_script_et_style_retires(self):
|
||||
self.assertEqual(texte("<style>p{}</style><script>x()</script><div>ok</div>"), "ok")
|
||||
|
||||
def test_balise_echappee_reste_du_texte(self): # l'app échappe à l'affichage, pas ici
|
||||
self.assertEqual(texte("<script>"), "<script>")
|
||||
|
||||
|
||||
class TestTranscript(unittest.TestCase):
|
||||
def test_entete(self):
|
||||
self.assertTrue(transcript(CONV, MESSAGES).startswith(
|
||||
"# Saut (#42)\n\nContact : Jean Dupont j@x.ch · Boîte : Support · Statut : Open · Créée : 2026-11-18 08:00 UTC\n"))
|
||||
|
||||
def test_messages(self):
|
||||
t = transcript(CONV, MESSAGES)
|
||||
self.assertIn("## 2026-11-18 08:00 UTC — Jean Dupont (client)\n\nBonjour", t)
|
||||
self.assertIn("", t)
|
||||
self.assertIn("[r.pdf](attachments/r.pdf)", t)
|
||||
self.assertIn("*2026-11-18 08:05 UTC — Assigned to Max*", t)
|
||||
self.assertIn("## 2026-11-18 08:10 UTC — Max (note privée)\n\nÀ vérifier", t)
|
||||
|
||||
def test_auteur_absent(self):
|
||||
self.assertIn("— Client (client)", transcript(CONV, [msg("09:00")]))
|
||||
|
||||
def test_svg_en_lien(self): # un svg est un lien, jamais une image en ligne
|
||||
self.assertNotIn("![", transcript(CONV, [msg("09:00", pieces=[piece("a.svg", "image/svg+xml")])]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user