"""Prépare une instance de test neuve : la boîte e-mail « Test » (SMTP = Mailpit, rien ne sort) et l'agent « Import base » (rôle Admin) avec sa clé. Écrase instance-de-test/.env (LIBREDESK_URL, LIBREDESK_ADMIN_KEY, LIBREDESK_ADMIN_SECRET). S'arrête si l'instance est déjà préparée. python3 instance-de-test/preparer.py """ import sys from pathlib import Path from session import B, connexion, req SMTP = {"enabled": True, "host": "mailpit", "port": 1025, "username": "", "password": "", "auth_protocol": "none", "tls_type": "none", "max_conns": 1, "max_msg_retries": 0, "idle_timeout": "5s", "pool_wait_timeout": "5s", "hello_hostname": ""} IMAP = {"host": "127.0.0.1", "port": 1, "username": "x", "password": "x", "mailbox": "INBOX", "read_interval": "1h", "scan_inbox_since": "1h", "tls_type": "none"} def main(mot_de_passe: str) -> None: connexion(mot_de_passe) if any(b["name"] == "Test" for b in req("GET", "/api/v1/inboxes") or []): sys.exit("instance déjà préparée : docker compose -p ldtest down -v, puis demarrer.sh") req("POST", "/api/v1/inboxes", {"name": "Test", "channel": "email", "enabled": True, "csat_enabled": False, "from": "Support ", "config": {"auth_type": "password", "from": "Support ", "smtp": [SMTP], "imap": [IMAP]}}) agent = req("POST", "/api/v1/agents", {"first_name": "Import", "last_name": "base", "email": "import@example.com", "roles": ["Admin"], "send_welcome_email": False, "enabled": True}) cle = req("POST", f"/api/v1/agents/{agent['id']}/api-key") env = Path(__file__).with_name(".env") env.write_text(f"LIBREDESK_URL={B}\nLIBREDESK_ADMIN_KEY={cle['api_key']}\n" f"LIBREDESK_ADMIN_SECRET={cle['api_secret']}\n") print(f"prête : boîte « Test » (SMTP = Mailpit), clé d'import dans {env}") if __name__ == "__main__": main(*sys.argv[1:2])