Add forecast subscription failure test case to nws (#115541)
This commit is contained in:
parent
f1ac33c246
commit
f452c5b84e
2 changed files with 64 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
"""Fixtures for National Weather Service tests."""
|
||||
|
||||
import asyncio
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
@ -24,6 +25,23 @@ def mock_simple_nws():
|
|||
yield mock_nws
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_simple_nws_times_out():
|
||||
"""Mock pynws SimpleNWS that times out."""
|
||||
with patch("homeassistant.components.nws.SimpleNWS") as mock_nws:
|
||||
instance = mock_nws.return_value
|
||||
instance.set_station = AsyncMock(side_effect=asyncio.TimeoutError)
|
||||
instance.update_observation = AsyncMock(side_effect=asyncio.TimeoutError)
|
||||
instance.update_forecast = AsyncMock(side_effect=asyncio.TimeoutError)
|
||||
instance.update_forecast_hourly = AsyncMock(side_effect=asyncio.TimeoutError)
|
||||
instance.station = "ABC"
|
||||
instance.stations = ["ABC"]
|
||||
instance.observation = None
|
||||
instance.forecast = None
|
||||
instance.forecast_hourly = None
|
||||
yield mock_nws
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_simple_nws_config():
|
||||
"""Mock pynws SimpleNWS with default values in config_flow."""
|
||||
|
|
|
@ -476,3 +476,49 @@ async def test_forecast_subscription(
|
|||
|
||||
assert forecast2 != []
|
||||
assert forecast2 == snapshot
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("forecast_type", "entity_id"),
|
||||
[("hourly", "weather.abc")],
|
||||
)
|
||||
async def test_forecast_subscription_with_failing_coordinator(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_simple_nws_times_out,
|
||||
no_sensor,
|
||||
forecast_type: str,
|
||||
entity_id: str,
|
||||
) -> None:
|
||||
"""Test a forecast subscription when the coordinator is failing to update."""
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
registry = er.async_get(hass)
|
||||
# Pre-create the hourly entity
|
||||
registry.async_get_or_create(
|
||||
WEATHER_DOMAIN,
|
||||
nws.DOMAIN,
|
||||
"35_-75_hourly",
|
||||
suggested_object_id="abc_hourly",
|
||||
)
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=nws.DOMAIN,
|
||||
data=NWS_CONFIG,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await client.send_json_auto_id(
|
||||
{
|
||||
"type": "weather/subscribe_forecast",
|
||||
"forecast_type": forecast_type,
|
||||
"entity_id": entity_id,
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
assert not msg["success"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue