Files
checkbot/tests/test_cli_messages.py
T
patrickandClaude Sonnet 5.5 f34fc6d686 feat: Ausgangslog für Messenger-Nachrichten
- LoggingAdapter protokolliert send/edit (Matrix zusätzlich reply) inkl. Fehlversuche
- Tabelle outbound_log (Migration 10), Aufbewahrung retention.outbound_days (30 Tage)
- Seite /messages und CLI checkbot messages mit Filtern
- Text gekappt (4000) und Secrets maskiert

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 23:38:07 +01:00

43 lines
1.7 KiB
Python

from app.cli import main
from app.db import Database
def seed(db_path):
db = Database(db_path)
db.insert("INSERT INTO outbound_log(ts, backend, target, action, message_id, silent, ok, error, text) "
"VALUES (?,?,?,?,?,?,?,?,?)", (100, "telegram", "1", "send", "a", 0, 1, None, "erste\nzeile"))
db.insert("INSERT INTO outbound_log(ts, backend, target, action, message_id, silent, ok, error, text) "
"VALUES (?,?,?,?,?,?,?,?,?)", (200, "matrix", "!room", "send", "", 0, 0, "boom", "zweite"))
db.close()
def test_messages_prints_newest_first(tmp_path, monkeypatch, capsys):
db_path = tmp_path / "checkbot.db"
monkeypatch.setenv("CHECKBOT_CONFIG_DIR", str(tmp_path))
monkeypatch.setenv("CHECKBOT_DB", str(db_path))
seed(db_path)
assert main(["messages"]) == 0
out = capsys.readouterr().out.splitlines()
assert len(out) == 2
assert "matrix" in out[0] and "ERR:boom" in out[0]
assert "telegram" in out[1] and " ok " in out[1] and "erste\\nzeile" in out[1]
def test_messages_filters_errors_only(tmp_path, monkeypatch, capsys):
db_path = tmp_path / "checkbot.db"
monkeypatch.setenv("CHECKBOT_CONFIG_DIR", str(tmp_path))
monkeypatch.setenv("CHECKBOT_DB", str(db_path))
seed(db_path)
assert main(["messages", "--errors"]) == 0
out = capsys.readouterr().out.splitlines()
assert len(out) == 1 and "matrix" in out[0]
def test_messages_rejects_invalid_since(tmp_path, monkeypatch, capsys):
db_path = tmp_path / "checkbot.db"
monkeypatch.setenv("CHECKBOT_CONFIG_DIR", str(tmp_path))
monkeypatch.setenv("CHECKBOT_DB", str(db_path))
seed(db_path)
assert main(["messages", "--since", "xyz"]) == 1
assert "Ungültiges" in capsys.readouterr().err