Migrate octoprint tests to use freezegun (#105408)
parent
3e3f9cf092
commit
b4731674f8
|
@ -1,6 +1,7 @@
|
|||
"""The tests for Octoptint binary sensor module."""
|
||||
from datetime import UTC, datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
@ -8,7 +9,7 @@ from homeassistant.helpers import entity_registry as er
|
|||
from . import init_integration
|
||||
|
||||
|
||||
async def test_sensors(hass: HomeAssistant) -> None:
|
||||
async def test_sensors(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None:
|
||||
"""Test the underlying sensors."""
|
||||
printer = {
|
||||
"state": {
|
||||
|
@ -22,11 +23,8 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||
"progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000},
|
||||
"state": "Printing",
|
||||
}
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow",
|
||||
return_value=datetime(2020, 2, 20, 9, 10, 13, 543, tzinfo=UTC),
|
||||
):
|
||||
await init_integration(hass, "sensor", printer=printer, job=job)
|
||||
freezer.move_to(datetime(2020, 2, 20, 9, 10, 13, 543, tzinfo=UTC))
|
||||
await init_integration(hass, "sensor", printer=printer, job=job)
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
|
@ -80,7 +78,9 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||
assert entry.unique_id == "Estimated Finish Time-uuid"
|
||||
|
||||
|
||||
async def test_sensors_no_target_temp(hass: HomeAssistant) -> None:
|
||||
async def test_sensors_no_target_temp(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||
) -> None:
|
||||
"""Test the underlying sensors."""
|
||||
printer = {
|
||||
"state": {
|
||||
|
@ -89,10 +89,8 @@ async def test_sensors_no_target_temp(hass: HomeAssistant) -> None:
|
|||
},
|
||||
"temperature": {"tool1": {"actual": 18.83136, "target": None}},
|
||||
}
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow", return_value=datetime(2020, 2, 20, 9, 10, 0)
|
||||
):
|
||||
await init_integration(hass, "sensor", printer=printer)
|
||||
freezer.move_to(datetime(2020, 2, 20, 9, 10, 0))
|
||||
await init_integration(hass, "sensor", printer=printer)
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
|
@ -111,7 +109,9 @@ async def test_sensors_no_target_temp(hass: HomeAssistant) -> None:
|
|||
assert entry.unique_id == "target tool1 temp-uuid"
|
||||
|
||||
|
||||
async def test_sensors_paused(hass: HomeAssistant) -> None:
|
||||
async def test_sensors_paused(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||
) -> None:
|
||||
"""Test the underlying sensors."""
|
||||
printer = {
|
||||
"state": {
|
||||
|
@ -125,10 +125,8 @@ async def test_sensors_paused(hass: HomeAssistant) -> None:
|
|||
"progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000},
|
||||
"state": "Paused",
|
||||
}
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow", return_value=datetime(2020, 2, 20, 9, 10, 0)
|
||||
):
|
||||
await init_integration(hass, "sensor", printer=printer, job=job)
|
||||
freezer.move_to(datetime(2020, 2, 20, 9, 10, 0))
|
||||
await init_integration(hass, "sensor", printer=printer, job=job)
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
|
@ -147,17 +145,17 @@ async def test_sensors_paused(hass: HomeAssistant) -> None:
|
|||
assert entry.unique_id == "Estimated Finish Time-uuid"
|
||||
|
||||
|
||||
async def test_sensors_printer_disconnected(hass: HomeAssistant) -> None:
|
||||
async def test_sensors_printer_disconnected(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||
) -> None:
|
||||
"""Test the underlying sensors."""
|
||||
job = {
|
||||
"job": {},
|
||||
"progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000},
|
||||
"state": "Paused",
|
||||
}
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow", return_value=datetime(2020, 2, 20, 9, 10, 0)
|
||||
):
|
||||
await init_integration(hass, "sensor", printer=None, job=job)
|
||||
freezer.move_to(datetime(2020, 2, 20, 9, 10, 0))
|
||||
await init_integration(hass, "sensor", printer=None, job=job)
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
|
|
Loading…
Reference in New Issue