From 3abc7b18c6f2d95d8d5062b735285f1a7f59867c Mon Sep 17 00:00:00 2001 From: counterweight Date: Mon, 22 Dec 2025 16:11:00 +0100 Subject: [PATCH] test: add test for network errors (httpx.ConnectError) The docstring of fetch_btc_eur_price mentions it raises httpx.RequestError on network errors, but this wasn't tested. Add test for ConnectError. --- backend/tests/test_price_history.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/tests/test_price_history.py b/backend/tests/test_price_history.py index 2dacaee..200e4a0 100644 --- a/backend/tests/test_price_history.py +++ b/backend/tests/test_price_history.py @@ -65,6 +65,22 @@ class TestFetchBtcEurPrice: ): await fetch_btc_eur_price() + @pytest.mark.asyncio + async def test_raises_on_network_error(self): + """Verify network errors (ConnectError, TimeoutException) are propagated.""" + import httpx + + mock_client = AsyncMock() + mock_client.get.side_effect = httpx.ConnectError("Connection refused") + mock_client.__aenter__.return_value = mock_client + mock_client.__aexit__.return_value = None + + with ( + patch("price_fetcher.httpx.AsyncClient", return_value=mock_client), + pytest.raises(httpx.ConnectError), + ): + await fetch_btc_eur_price() + @pytest.mark.asyncio async def test_raises_on_invalid_response_format(self): """Verify ValueError is raised for unexpected response format."""