35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
"""Spec §7.10 : le seul envoi vers …/messages est la note privée, private en dur, sans destinataires."""
|
|
import ast
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
PAQUET = Path(__file__).resolve().parents[1] / "support_diagnostic"
|
|
|
|
|
|
class TestGardeFou(unittest.TestCase):
|
|
def sources(self):
|
|
return {f.name: f.read_text() for f in PAQUET.glob("*.py")}
|
|
|
|
def test_un_seul_post_de_messages(self):
|
|
sources = self.sources()
|
|
for nom, texte in sources.items():
|
|
if nom != "libredesk.py":
|
|
self.assertNotIn("/messages", texte, nom)
|
|
arbre = ast.parse(sources["libredesk.py"])
|
|
fonctions = {f.name for f in ast.walk(arbre) if isinstance(f, ast.FunctionDef)
|
|
and "/messages" in ast.get_source_segment(sources["libredesk.py"], f)}
|
|
self.assertEqual(fonctions, {"note_privee", "messages"})
|
|
messages = next(f for f in ast.walk(arbre) if isinstance(f, ast.FunctionDef) and f.name == "messages")
|
|
self.assertNotIn("POST", ast.get_source_segment(sources["libredesk.py"], messages))
|
|
|
|
def test_private_en_dur(self):
|
|
sources = self.sources()
|
|
self.assertIn('"private": True', sources["libredesk.py"])
|
|
for nom, texte in sources.items():
|
|
for interdit in ('"to"', '"cc"', '"bcc"', "set_tags"):
|
|
self.assertNotIn(interdit, texte, f"{interdit} dans {nom}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|