"""Tests für die Webhook-Benachrichtigungen (Typ-Erkennung + Payload-Bau).""" from notify import baue_payload, erkenne_webhook_typ def test_discord_wird_an_url_erkannt(): assert erkenne_webhook_typ("https://discord.com/api/webhooks/1/abc") == "discord" assert erkenne_webhook_typ("https://discordapp.com/api/webhooks/1/abc") == "discord" def test_slack_und_ntfy_und_generisch(): assert erkenne_webhook_typ("https://hooks.slack.com/services/T/B/x") == "slack" assert erkenne_webhook_typ("https://ntfy.sh/mein-thema") == "ntfy" assert erkenne_webhook_typ("https://ha.local/api/webhook/rippy") == "generisch" def test_discord_payload_nutzt_content(): typ, payload = baue_payload("https://discord.com/api/webhooks/1/a", "Titel", "Text") assert typ == "discord" assert payload == {"content": "**Titel**\nText"} def test_slack_payload_nutzt_text(): typ, payload = baue_payload("https://hooks.slack.com/services/x", "Titel", "Text") assert typ == "slack" assert payload == {"text": "*Titel*\nText"} def test_ntfy_sendet_rohtext(): typ, payload = baue_payload("https://ntfy.sh/thema", "Titel", "Text") assert typ == "ntfy" assert payload is None # Roh-Text-Body, kein JSON def test_generischer_payload_traegt_level(): typ, payload = baue_payload("https://example.org/hook", "Titel", "Text", "error") assert typ == "generisch" assert payload == {"title": "Titel", "message": "Text", "level": "error"}