Migrate sonarr tests to use freezegun (#105410)
This commit is contained in:
parent
b4731674f8
commit
47819bde4f
1 changed files with 18 additions and 16 deletions
|
@ -1,8 +1,9 @@
|
||||||
"""Tests for the Sonarr sensor platform."""
|
"""Tests for the Sonarr sensor platform."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from aiopyarr import ArrException
|
from aiopyarr import ArrException
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||||
|
@ -122,6 +123,7 @@ async def test_disabled_by_default_sensors(
|
||||||
|
|
||||||
async def test_availability(
|
async def test_availability(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
mock_sonarr: MagicMock,
|
mock_sonarr: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -129,7 +131,7 @@ async def test_availability(
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
|
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
freezer.move_to(now)
|
||||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -140,7 +142,7 @@ async def test_availability(
|
||||||
mock_sonarr.async_get_calendar.side_effect = ArrException
|
mock_sonarr.async_get_calendar.side_effect = ArrException
|
||||||
|
|
||||||
future = now + timedelta(minutes=1)
|
future = now + timedelta(minutes=1)
|
||||||
with patch("homeassistant.util.dt.utcnow", return_value=future):
|
freezer.move_to(future)
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -151,7 +153,7 @@ async def test_availability(
|
||||||
mock_sonarr.async_get_calendar.side_effect = None
|
mock_sonarr.async_get_calendar.side_effect = None
|
||||||
|
|
||||||
future += timedelta(minutes=1)
|
future += timedelta(minutes=1)
|
||||||
with patch("homeassistant.util.dt.utcnow", return_value=future):
|
freezer.move_to(future)
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -162,7 +164,7 @@ async def test_availability(
|
||||||
mock_sonarr.async_get_calendar.side_effect = ArrException
|
mock_sonarr.async_get_calendar.side_effect = ArrException
|
||||||
|
|
||||||
future += timedelta(minutes=1)
|
future += timedelta(minutes=1)
|
||||||
with patch("homeassistant.util.dt.utcnow", return_value=future):
|
freezer.move_to(future)
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -173,7 +175,7 @@ async def test_availability(
|
||||||
mock_sonarr.async_get_calendar.side_effect = None
|
mock_sonarr.async_get_calendar.side_effect = None
|
||||||
|
|
||||||
future += timedelta(minutes=1)
|
future += timedelta(minutes=1)
|
||||||
with patch("homeassistant.util.dt.utcnow", return_value=future):
|
freezer.move_to(future)
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue