mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 03:35:56 +02:00
Add test
This commit is contained in:
parent
68491fc7da
commit
4e8f1faebc
2 changed files with 61 additions and 1 deletions
|
@ -262,3 +262,20 @@ def mock_coordinator(request: pytest.FixtureRequest) -> Generator[None, MagicMoc
|
|||
coord = coordinator_mock.return_value
|
||||
coord._async_animation_data.return_value = {'animation': None}
|
||||
yield coord
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def mock_irm_kmi_api_works_but_pollen_and_radar_fail(request: pytest.FixtureRequest) -> Generator[
|
||||
None, MagicMock, None]:
|
||||
"""Return a mocked IrmKmi api client."""
|
||||
fixture: str = "forecast.json"
|
||||
|
||||
forecast = json.loads(load_fixture(fixture))
|
||||
with patch(
|
||||
"custom_components.irm_kmi.coordinator.IrmKmiApiClient", autospec=True
|
||||
) as irm_kmi_api_mock:
|
||||
irm_kmi = irm_kmi_api_mock.return_value
|
||||
irm_kmi.get_forecasts_coord.return_value = forecast
|
||||
irm_kmi.get_svg.side_effect = IrmKmiApiError
|
||||
irm_kmi.get_image.side_effect = IrmKmiApiError
|
||||
yield irm_kmi
|
||||
|
|
|
@ -8,7 +8,9 @@ from homeassistant.core import HomeAssistant
|
|||
from pytest_homeassistant_custom_component.common import MockConfigEntry
|
||||
|
||||
from custom_components.irm_kmi.coordinator import IrmKmiCoordinator
|
||||
from custom_components.irm_kmi.data import CurrentWeatherData, IrmKmiForecast
|
||||
from custom_components.irm_kmi.data import CurrentWeatherData, IrmKmiForecast, ProcessedCoordinatorData, \
|
||||
RadarAnimationData
|
||||
from custom_components.irm_kmi.pollen import PollenParser
|
||||
from tests.conftest import get_api_data
|
||||
|
||||
|
||||
|
@ -134,3 +136,44 @@ def test_hourly_forecast() -> None:
|
|||
)
|
||||
|
||||
assert result[8] == expected
|
||||
|
||||
|
||||
async def test_refresh_succeed_even_when_pollen_and_radar_fail(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_irm_kmi_api_works_but_pollen_and_radar_fail
|
||||
):
|
||||
hass.states.async_set(
|
||||
"zone.home",
|
||||
0,
|
||||
{"latitude": 50.738681639, "longitude": 4.054077148},
|
||||
)
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
coordinator = IrmKmiCoordinator(hass, mock_config_entry)
|
||||
|
||||
result = await coordinator._async_update_data()
|
||||
|
||||
assert result.get('current_weather').get('condition') == ATTR_CONDITION_CLOUDY
|
||||
|
||||
assert result.get('animation') == dict()
|
||||
|
||||
assert result.get('pollen') == PollenParser.get_unavailable_data()
|
||||
|
||||
existing_data = ProcessedCoordinatorData(
|
||||
current_weather=CurrentWeatherData(),
|
||||
daily_forecast=[],
|
||||
hourly_forecast=[],
|
||||
animation=RadarAnimationData(hint="This will remain unchanged"),
|
||||
warnings=[],
|
||||
pollen={'foo': 'bar'}
|
||||
)
|
||||
coordinator.data = existing_data
|
||||
result = await coordinator._async_update_data()
|
||||
|
||||
assert result.get('current_weather').get('condition') == ATTR_CONDITION_CLOUDY
|
||||
|
||||
assert result.get('animation').get('hint') == "This will remain unchanged"
|
||||
|
||||
assert result.get('pollen') == {'foo': 'bar'}
|
||||
|
|
Loading…
Add table
Reference in a new issue