Fix flapping trafikverket tests (#116238)

* Fix flapping trafikverket tests

* Fix copy-paste mistake
This commit is contained in:
Erik Montnemery 2024-04-26 13:49:43 +02:00 committed by GitHub
parent 09a18459ff
commit 56f2f10a17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -25,6 +25,25 @@ async def load_integration_from_entry(
get_train_stop: TrainStop, get_train_stop: TrainStop,
) -> MockConfigEntry: ) -> MockConfigEntry:
"""Set up the Trafikverket Train integration in Home Assistant.""" """Set up the Trafikverket Train integration in Home Assistant."""
async def setup_config_entry_with_mocked_data(config_entry_id: str) -> None:
"""Set up a config entry with mocked trafikverket data."""
with (
patch(
"homeassistant.components.trafikverket_train.coordinator.TrafikverketTrain.async_get_next_train_stops",
return_value=get_trains,
),
patch(
"homeassistant.components.trafikverket_train.coordinator.TrafikverketTrain.async_get_train_stop",
return_value=get_train_stop,
),
patch(
"homeassistant.components.trafikverket_train.TrafikverketTrain.async_get_train_station",
),
):
await hass.config_entries.async_setup(config_entry_id)
await hass.async_block_till_done()
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
source=SOURCE_USER, source=SOURCE_USER,
@ -34,6 +53,8 @@ async def load_integration_from_entry(
unique_id="stockholmc-uppsalac--['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']", unique_id="stockholmc-uppsalac--['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']",
) )
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
await setup_config_entry_with_mocked_data(config_entry.entry_id)
config_entry2 = MockConfigEntry( config_entry2 = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
source=SOURCE_USER, source=SOURCE_USER,
@ -42,22 +63,7 @@ async def load_integration_from_entry(
unique_id="stockholmc-uppsalac-1100-['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']", unique_id="stockholmc-uppsalac-1100-['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']",
) )
config_entry2.add_to_hass(hass) config_entry2.add_to_hass(hass)
await setup_config_entry_with_mocked_data(config_entry2.entry_id)
with (
patch(
"homeassistant.components.trafikverket_train.coordinator.TrafikverketTrain.async_get_next_train_stops",
return_value=get_trains,
),
patch(
"homeassistant.components.trafikverket_train.coordinator.TrafikverketTrain.async_get_train_stop",
return_value=get_train_stop,
),
patch(
"homeassistant.components.trafikverket_train.TrafikverketTrain.async_get_train_station",
),
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
return config_entry return config_entry