Use freezegun in fully_kiosk tests (#99031)

This commit is contained in:
Erik Montnemery 2023-08-25 16:03:51 +02:00 committed by GitHub
parent 1f9c180233
commit 3b07181d87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -1,6 +1,7 @@
"""Test the Fully Kiosk Browser binary sensors.""" """Test the Fully Kiosk Browser binary sensors."""
from unittest.mock import MagicMock from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from fullykiosk import FullyKioskError from fullykiosk import FullyKioskError
from homeassistant.components.binary_sensor import BinarySensorDeviceClass from homeassistant.components.binary_sensor import BinarySensorDeviceClass
@ -15,13 +16,13 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.util import dt as dt_util
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry, async_fire_time_changed
async def test_binary_sensors( async def test_binary_sensors(
hass: HomeAssistant, hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
mock_fully_kiosk: MagicMock, mock_fully_kiosk: MagicMock,
init_integration: MockConfigEntry, init_integration: MockConfigEntry,
) -> None: ) -> None:
@ -76,7 +77,8 @@ async def test_binary_sensors(
# Test unknown/missing data # Test unknown/missing data
mock_fully_kiosk.getDeviceInfo.return_value = {} mock_fully_kiosk.getDeviceInfo.return_value = {}
async_fire_time_changed(hass, dt_util.utcnow() + UPDATE_INTERVAL) freezer.tick(UPDATE_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("binary_sensor.amazon_fire_plugged_in") state = hass.states.get("binary_sensor.amazon_fire_plugged_in")
@ -85,7 +87,8 @@ async def test_binary_sensors(
# Test failed update # Test failed update
mock_fully_kiosk.getDeviceInfo.side_effect = FullyKioskError("error", "status") mock_fully_kiosk.getDeviceInfo.side_effect = FullyKioskError("error", "status")
async_fire_time_changed(hass, dt_util.utcnow() + UPDATE_INTERVAL) freezer.tick(UPDATE_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("binary_sensor.amazon_fire_plugged_in") state = hass.states.get("binary_sensor.amazon_fire_plugged_in")

View File

@ -1,6 +1,7 @@
"""Test the Fully Kiosk Browser sensors.""" """Test the Fully Kiosk Browser sensors."""
from unittest.mock import MagicMock from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from fullykiosk import FullyKioskError from fullykiosk import FullyKioskError
from homeassistant.components.fully_kiosk.const import DOMAIN, UPDATE_INTERVAL from homeassistant.components.fully_kiosk.const import DOMAIN, UPDATE_INTERVAL
@ -25,6 +26,7 @@ from tests.common import MockConfigEntry, async_fire_time_changed
async def test_sensors_sensors( async def test_sensors_sensors(
hass: HomeAssistant, hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
mock_fully_kiosk: MagicMock, mock_fully_kiosk: MagicMock,
init_integration: MockConfigEntry, init_integration: MockConfigEntry,
) -> None: ) -> None:
@ -141,7 +143,8 @@ async def test_sensors_sensors(
# Test unknown/missing data # Test unknown/missing data
mock_fully_kiosk.getDeviceInfo.return_value = {} mock_fully_kiosk.getDeviceInfo.return_value = {}
async_fire_time_changed(hass, dt_util.utcnow() + UPDATE_INTERVAL) freezer.tick(UPDATE_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("sensor.amazon_fire_internal_storage_free_space") state = hass.states.get("sensor.amazon_fire_internal_storage_free_space")
@ -150,7 +153,8 @@ async def test_sensors_sensors(
# Test failed update # Test failed update
mock_fully_kiosk.getDeviceInfo.side_effect = FullyKioskError("error", "status") mock_fully_kiosk.getDeviceInfo.side_effect = FullyKioskError("error", "status")
async_fire_time_changed(hass, dt_util.utcnow() + UPDATE_INTERVAL) freezer.tick(UPDATE_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("sensor.amazon_fire_internal_storage_free_space") state = hass.states.get("sensor.amazon_fire_internal_storage_free_space")