Files
checkbot/tests/test_adapter_silent.py
patrickandClaude Sonnet 5.5 5278530467
test / pytest (3.11) (push) Canceled after 0s
test / pytest (3.13) (push) Canceled after 0s
feat: Phase 6b rules with delay, delta format, reminders, zpool default rule
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 02:38:10 +01:00

59 lines
1.7 KiB
Python

import json
import httpx
from app.chat import MatrixAdapter, MessageRef, TelegramAdapter
ROOM = "!abc:example.de"
def telegram(seen):
def handler(request):
seen.append(json.loads(request.content))
return httpx.Response(200, json={"ok": True, "result": {"message_id": 7}})
return TelegramAdapter("123456:token", "42", transport=httpx.MockTransport(handler))
def matrix(seen):
def handler(request):
seen.append(json.loads(request.content))
return httpx.Response(200, json={"event_id": "$ev1"})
return MatrixAdapter("https://matrix.example.de", "@bot:example.de", "tok", ROOM,
transport=httpx.MockTransport(handler))
async def test_telegram_silent_sets_disable_notification():
seen = []
await telegram(seen).send("42", "x", silent=True)
assert seen[0]["disable_notification"] is True
async def test_telegram_loud_send_has_no_flag():
seen = []
await telegram(seen).send("42", "x")
assert "disable_notification" not in seen[0]
async def test_telegram_edit_accepts_silent():
seen = []
await telegram(seen).edit(MessageRef("telegram", "42", "7"), "neu", silent=True)
assert seen[0]["message_id"] == 7
async def test_matrix_silent_uses_notice():
seen = []
await matrix(seen).send(ROOM, "<b>x</b>", silent=True)
assert seen[0]["msgtype"] == "m.notice"
async def test_matrix_loud_uses_text():
seen = []
await matrix(seen).send(ROOM, "<b>x</b>")
assert seen[0]["msgtype"] == "m.text"
async def test_matrix_silent_edit_keeps_notice_type():
seen = []
await matrix(seen).edit(MessageRef("matrix", ROOM, "$ev0"), "neu", silent=True)
assert seen[0]["msgtype"] == "m.notice" and seen[0]["m.new_content"]["msgtype"] == "m.notice"