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:
parent
13d2e4adeb
commit
3abc7b18c6
1 changed files with 16 additions and 0 deletions
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue