mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Use freezegun in here_travel_time tests (#99032)
This commit is contained in:
parent
676f59fded
commit
75743ed947
@ -2,6 +2,7 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
from here_routing import (
|
from here_routing import (
|
||||||
HERERoutingError,
|
HERERoutingError,
|
||||||
HERERoutingTooManyRequestsError,
|
HERERoutingTooManyRequestsError,
|
||||||
@ -64,7 +65,6 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import CoreState, HomeAssistant, State
|
from homeassistant.core import CoreState, HomeAssistant, State
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util.dt import utcnow
|
|
||||||
|
|
||||||
from .conftest import RESPONSE, TRANSIT_RESPONSE
|
from .conftest import RESPONSE, TRANSIT_RESPONSE
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -662,7 +662,9 @@ async def test_transit_errors(
|
|||||||
|
|
||||||
|
|
||||||
async def test_routing_rate_limit(
|
async def test_routing_rate_limit(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that rate limiting is applied when encountering HTTP 429."""
|
"""Test that rate limiting is applied when encountering HTTP 429."""
|
||||||
with patch(
|
with patch(
|
||||||
@ -689,9 +691,8 @@ async def test_routing_rate_limit(
|
|||||||
"Rate limit for this service has been reached"
|
"Rate limit for this service has been reached"
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
async_fire_time_changed(
|
freezer.tick(timedelta(seconds=DEFAULT_SCAN_INTERVAL + 1))
|
||||||
hass, utcnow() + timedelta(seconds=DEFAULT_SCAN_INTERVAL + 1)
|
async_fire_time_changed(hass)
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("sensor.test_distance").state == "unavailable"
|
assert hass.states.get("sensor.test_distance").state == "unavailable"
|
||||||
@ -701,18 +702,17 @@ async def test_routing_rate_limit(
|
|||||||
"here_routing.HERERoutingApi.route",
|
"here_routing.HERERoutingApi.route",
|
||||||
return_value=RESPONSE,
|
return_value=RESPONSE,
|
||||||
):
|
):
|
||||||
async_fire_time_changed(
|
freezer.tick(timedelta(seconds=DEFAULT_SCAN_INTERVAL * BACKOFF_MULTIPLIER + 1))
|
||||||
hass,
|
async_fire_time_changed(hass)
|
||||||
utcnow()
|
|
||||||
+ timedelta(seconds=DEFAULT_SCAN_INTERVAL * BACKOFF_MULTIPLIER + 1),
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get("sensor.test_distance").state == "13.682"
|
assert hass.states.get("sensor.test_distance").state == "13.682"
|
||||||
assert "Resetting update interval to" in caplog.text
|
assert "Resetting update interval to" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_transit_rate_limit(
|
async def test_transit_rate_limit(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that rate limiting is applied when encountering HTTP 429."""
|
"""Test that rate limiting is applied when encountering HTTP 429."""
|
||||||
with patch(
|
with patch(
|
||||||
@ -747,9 +747,8 @@ async def test_transit_rate_limit(
|
|||||||
"Rate limit for this service has been reached"
|
"Rate limit for this service has been reached"
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
async_fire_time_changed(
|
freezer.tick(timedelta(seconds=DEFAULT_SCAN_INTERVAL + 1))
|
||||||
hass, utcnow() + timedelta(seconds=DEFAULT_SCAN_INTERVAL + 1)
|
async_fire_time_changed(hass)
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("sensor.test_distance").state == "unavailable"
|
assert hass.states.get("sensor.test_distance").state == "unavailable"
|
||||||
@ -759,11 +758,8 @@ async def test_transit_rate_limit(
|
|||||||
"here_transit.HERETransitApi.route",
|
"here_transit.HERETransitApi.route",
|
||||||
return_value=TRANSIT_RESPONSE,
|
return_value=TRANSIT_RESPONSE,
|
||||||
):
|
):
|
||||||
async_fire_time_changed(
|
freezer.tick(timedelta(seconds=DEFAULT_SCAN_INTERVAL * BACKOFF_MULTIPLIER + 1))
|
||||||
hass,
|
async_fire_time_changed(hass)
|
||||||
utcnow()
|
|
||||||
+ timedelta(seconds=DEFAULT_SCAN_INTERVAL * BACKOFF_MULTIPLIER + 1),
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get("sensor.test_distance").state == "1.883"
|
assert hass.states.get("sensor.test_distance").state == "1.883"
|
||||||
assert "Resetting update interval to" in caplog.text
|
assert "Resetting update interval to" in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user