mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Migrate demo test to use freezegun (#105644)
This commit is contained in:
parent
ac53b78a0c
commit
61a99c911c
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.button import DOMAIN, SERVICE_PRESS
|
from homeassistant.components.button import DOMAIN, SERVICE_PRESS
|
||||||
@ -37,20 +38,20 @@ def test_setup_params(hass: HomeAssistant) -> None:
|
|||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
async def test_press(hass: HomeAssistant) -> None:
|
async def test_press(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None:
|
||||||
"""Test pressing the button."""
|
"""Test pressing the button."""
|
||||||
state = hass.states.get(ENTITY_PUSH)
|
state = hass.states.get(ENTITY_PUSH)
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
now = dt_util.parse_datetime("2021-01-09 12:00:00+00:00")
|
now = dt_util.parse_datetime("2021-01-09 12:00:00+00:00")
|
||||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
freezer.move_to(now)
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_PRESS,
|
SERVICE_PRESS,
|
||||||
{ATTR_ENTITY_ID: ENTITY_PUSH},
|
{ATTR_ENTITY_ID: ENTITY_PUSH},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get(ENTITY_PUSH)
|
state = hass.states.get(ENTITY_PUSH)
|
||||||
assert state
|
assert state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user