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.
This commit is contained in:
counterweight 2025-12-22 16:11:00 +01:00
parent 13d2e4adeb
commit 3abc7b18c6
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -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."""