From b97189752bbc9cc3e92164c9758b67cd88f62038 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2026 08:41:47 +0000 Subject: [PATCH] test: add OSError test for post_webhook Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- tests/test_alerting.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_alerting.py b/tests/test_alerting.py index d689d7c..287ffea 100644 --- a/tests/test_alerting.py +++ b/tests/test_alerting.py @@ -1,6 +1,7 @@ from __future__ import annotations import httpx +from unittest.mock import AsyncMock, patch from netsleuth.alerting import build_payload, post_webhook, should_fire from netsleuth.exporter import dump_json @@ -67,3 +68,11 @@ async def test_post_webhook_returns_false_and_never_raises_on_failure(httpx_mock async with httpx.AsyncClient() as client: ok = await post_webhook(client, "https://example.com/hook", {"a": 1}, timeout=5.0) assert ok is False + + +async def test_post_webhook_returns_false_on_oserror(): + with patch("httpx.AsyncClient.post", new_callable=AsyncMock) as mock_post: + mock_post.side_effect = OSError("Network unreachable") + async with httpx.AsyncClient() as client: + ok = await post_webhook(client, "https://example.com/hook", {"a": 1}, timeout=5.0) + assert ok is False