mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Migrate geo_rss_events test to use freezegun (#105895)
This commit is contained in:
parent
e3b09a5470
commit
bdaf269ba3
@ -1,6 +1,7 @@
|
|||||||
"""The test for the geo rss events sensor platform."""
|
"""The test for the geo rss events sensor platform."""
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import sensor
|
from homeassistant.components import sensor
|
||||||
@ -56,7 +57,9 @@ def _generate_mock_feed_entry(
|
|||||||
return feed_entry
|
return feed_entry
|
||||||
|
|
||||||
|
|
||||||
async def test_setup(hass: HomeAssistant, mock_feed) -> None:
|
async def test_setup(
|
||||||
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_feed
|
||||||
|
) -> None:
|
||||||
"""Test the general setup of the platform."""
|
"""Test the general setup of the platform."""
|
||||||
# Set up some mock feed entries for this test.
|
# Set up some mock feed entries for this test.
|
||||||
mock_entry_1 = _generate_mock_feed_entry(
|
mock_entry_1 = _generate_mock_feed_entry(
|
||||||
@ -68,10 +71,8 @@ async def test_setup(hass: HomeAssistant, mock_feed) -> None:
|
|||||||
mock_feed.return_value.update.return_value = "OK", [mock_entry_1, mock_entry_2]
|
mock_feed.return_value.update.return_value = "OK", [mock_entry_1, mock_entry_2]
|
||||||
|
|
||||||
utcnow = dt_util.utcnow()
|
utcnow = dt_util.utcnow()
|
||||||
# Patching 'utcnow' to gain more control over the timed update.
|
freezer.move_to(utcnow)
|
||||||
with patch(
|
with assert_setup_component(1, sensor.DOMAIN):
|
||||||
"homeassistant.util.dt.utcnow", return_value=utcnow
|
|
||||||
), assert_setup_component(1, sensor.DOMAIN):
|
|
||||||
assert await async_setup_component(hass, sensor.DOMAIN, VALID_CONFIG)
|
assert await async_setup_component(hass, sensor.DOMAIN, VALID_CONFIG)
|
||||||
# Artificially trigger update.
|
# Artificially trigger update.
|
||||||
hass.bus.fire(EVENT_HOMEASSISTANT_START)
|
hass.bus.fire(EVENT_HOMEASSISTANT_START)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user