Fichiers
jobrunner-html/beta/tests/test_assainissement.py
T
2026-10-29 10:23:57 +01:00

50 lignes
1.6 KiB
Python

import io, os, sys, tempfile, unittest
from contextlib import redirect_stdout
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
os.environ["BETA_DATA"] = str(Path(tempfile.mkdtemp()) / "data")
import db, codes, server # noqa: E402
ESC = "\x1b[2J\x1b]0;pwn\x07"
def sortie(*args):
b = io.StringIO()
with redirect_stdout(b):
codes.main(list(args))
return b.getvalue()
class T(unittest.TestCase):
def setUp(self):
self.c = db.connect()
def test_propre(self):
self.assertEqual(codes.propre("a\x1bb\nc\x07"), "a b c ")
self.assertEqual(codes.propre(None), "")
def test_retours(self):
self.c.execute("INSERT INTO feedback(ts,text,page,viewport,kind) VALUES(1,?,?,?,?)", (ESC + "x", ESC, ESC, ESC)); self.c.commit()
self.assertNotIn("\x1b", sortie("retours"))
def test_testeurs(self):
self.c.execute("INSERT INTO testers(ts,nom,prenom,email,tel,mineur,parent_nom) VALUES(1,?,?,?,?,1,?)", (ESC,) * 4 + (ESC,)); self.c.commit()
self.assertNotIn("\x1b", sortie("testeurs"))
def test_liste_et_journal(self):
db.creer_code(self.c, ESC + "etiquette", 1)
db.journal(self.c, ESC, None, ESC, ESC)
self.assertNotIn("\x1b", sortie("liste"))
self.assertNotIn("\x1b", sortie("journal"))
def test_generer(self):
self.assertNotIn("\x1b", sortie("generer", "--label", ESC))
def test_serveur_refuse_controle(self):
self.assertTrue(server.a_controle("Jean\x1b[2J"))
self.assertFalse(server.a_controle("Éloïse-Marie"))
if __name__ == "__main__":
unittest.main()