mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Attempt to fix flaky tomorrowio test (#72890)
* Fix flaky tomorrowio test * reset mock outside context manager * add to hass outside of context manager
This commit is contained in:
parent
c2fdac2014
commit
6ccaf33bdf
@ -66,26 +66,31 @@ async def test_update_intervals(
|
|||||||
version=1,
|
version=1,
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=now):
|
||||||
await hass.async_block_till_done()
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
assert len(tomorrowio_config_entry_update.call_args_list) == 1
|
await hass.async_block_till_done()
|
||||||
|
assert len(tomorrowio_config_entry_update.call_args_list) == 1
|
||||||
|
|
||||||
tomorrowio_config_entry_update.reset_mock()
|
tomorrowio_config_entry_update.reset_mock()
|
||||||
|
|
||||||
# Before the update interval, no updates yet
|
# Before the update interval, no updates yet
|
||||||
async_fire_time_changed(hass, now + timedelta(minutes=30))
|
future = now + timedelta(minutes=30)
|
||||||
await hass.async_block_till_done()
|
with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=future):
|
||||||
assert len(tomorrowio_config_entry_update.call_args_list) == 0
|
async_fire_time_changed(hass, future)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(tomorrowio_config_entry_update.call_args_list) == 0
|
||||||
|
|
||||||
# On the update interval, we get a new update
|
|
||||||
async_fire_time_changed(hass, now + timedelta(minutes=32))
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert len(tomorrowio_config_entry_update.call_args_list) == 1
|
|
||||||
tomorrowio_config_entry_update.reset_mock()
|
tomorrowio_config_entry_update.reset_mock()
|
||||||
|
|
||||||
with patch(
|
# On the update interval, we get a new update
|
||||||
"homeassistant.helpers.update_coordinator.utcnow",
|
future = now + timedelta(minutes=32)
|
||||||
return_value=now + timedelta(minutes=32),
|
with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=future):
|
||||||
):
|
async_fire_time_changed(hass, now + timedelta(minutes=32))
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(tomorrowio_config_entry_update.call_args_list) == 1
|
||||||
|
|
||||||
|
tomorrowio_config_entry_update.reset_mock()
|
||||||
|
|
||||||
# Adding a second config entry should cause the update interval to double
|
# Adding a second config entry should cause the update interval to double
|
||||||
config_entry_2 = MockConfigEntry(
|
config_entry_2 = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
@ -101,17 +106,26 @@ async def test_update_intervals(
|
|||||||
# We should get an immediate call once the new config entry is setup for a
|
# We should get an immediate call once the new config entry is setup for a
|
||||||
# partial update
|
# partial update
|
||||||
assert len(tomorrowio_config_entry_update.call_args_list) == 1
|
assert len(tomorrowio_config_entry_update.call_args_list) == 1
|
||||||
tomorrowio_config_entry_update.reset_mock()
|
|
||||||
|
tomorrowio_config_entry_update.reset_mock()
|
||||||
|
|
||||||
# We should get no new calls on our old interval
|
# We should get no new calls on our old interval
|
||||||
async_fire_time_changed(hass, now + timedelta(minutes=64))
|
future = now + timedelta(minutes=64)
|
||||||
await hass.async_block_till_done()
|
with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=future):
|
||||||
assert len(tomorrowio_config_entry_update.call_args_list) == 0
|
async_fire_time_changed(hass, future)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(tomorrowio_config_entry_update.call_args_list) == 0
|
||||||
|
|
||||||
|
tomorrowio_config_entry_update.reset_mock()
|
||||||
|
|
||||||
# We should get two calls on our new interval, one for each entry
|
# We should get two calls on our new interval, one for each entry
|
||||||
async_fire_time_changed(hass, now + timedelta(minutes=96))
|
future = now + timedelta(minutes=96)
|
||||||
await hass.async_block_till_done()
|
with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=future):
|
||||||
assert len(tomorrowio_config_entry_update.call_args_list) == 2
|
async_fire_time_changed(hass, future)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(tomorrowio_config_entry_update.call_args_list) == 2
|
||||||
|
|
||||||
|
tomorrowio_config_entry_update.reset_mock()
|
||||||
|
|
||||||
|
|
||||||
async def test_climacell_migration_logic(
|
async def test_climacell_migration_logic(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user