Migrate roku tests to use freezegun (#105418)

This commit is contained in:
Jan-Philipp Benecke 2023-12-09 23:47:19 +01:00 committed by GitHub
parent 64a5271a51
commit a8148cea65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@
from datetime import timedelta
from unittest.mock import MagicMock, patch
from freezegun.api import FrozenDateTimeFactory
import pytest
from rokuecp import RokuConnectionError, RokuConnectionTimeoutError, RokuError
@ -153,6 +154,7 @@ async def test_availability(
hass: HomeAssistant,
mock_roku: MagicMock,
mock_config_entry: MockConfigEntry,
freezer: FrozenDateTimeFactory,
error: RokuError,
) -> None:
"""Test entity availability."""
@ -160,23 +162,22 @@ async def test_availability(
future = now + timedelta(minutes=1)
mock_config_entry.add_to_hass(hass)
with patch("homeassistant.util.dt.utcnow", return_value=now):
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
freezer.move_to(now)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
with patch("homeassistant.util.dt.utcnow", return_value=future):
mock_roku.update.side_effect = error
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert hass.states.get(MAIN_ENTITY_ID).state == STATE_UNAVAILABLE
freezer.move_to(future)
mock_roku.update.side_effect = error
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert hass.states.get(MAIN_ENTITY_ID).state == STATE_UNAVAILABLE
future += timedelta(minutes=1)
with patch("homeassistant.util.dt.utcnow", return_value=future):
mock_roku.update.side_effect = None
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert hass.states.get(MAIN_ENTITY_ID).state == STATE_IDLE
freezer.move_to(future)
mock_roku.update.side_effect = None
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert hass.states.get(MAIN_ENTITY_ID).state == STATE_IDLE
async def test_supported_features(