Extend update_entry_and_reload tests (#127776)

This commit is contained in:
epenet 2024-10-07 11:23:48 +02:00 committed by GitHub
parent 550858092c
commit 8c0e96e6e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5116,52 +5116,92 @@ def test_raise_trying_to_add_same_config_entry_twice(
@pytest.mark.parametrize( @pytest.mark.parametrize(
( (
"title",
"unique_id",
"data_vendor",
"options_vendor",
"kwargs", "kwargs",
"expected_title",
"expected_unique_id",
"expected_data",
"expected_options",
"calls_entry_load_unload", "calls_entry_load_unload",
), ),
[ [
( (
("Test", "Updated title"), {
("1234", "5678"), "unique_id": "5678",
("data", "data2"), "title": "Updated title",
("options", "options2"), "data": {"vendor": "data2"},
{}, "options": {"vendor": "options2"},
},
"Updated title",
"5678",
{"vendor": "data2"},
{"vendor": "options2"},
(2, 1), (2, 1),
), ),
( (
("Test", "Test"), {
("1234", "1234"), "unique_id": "1234",
("data", "data"), "title": "Test",
("options", "options"), "data": {"vendor": "data"},
{}, "options": {"vendor": "options"},
},
"Test",
"1234",
{"vendor": "data"},
{"vendor": "options"},
(2, 1), (2, 1),
), ),
( (
("Test", "Updated title"), {
("1234", "5678"), "unique_id": "5678",
("data", "data2"), "title": "Updated title",
("options", "options2"), "data": {"vendor": "data2"},
{"reload_even_if_entry_is_unchanged": True}, "options": {"vendor": "options2"},
"reload_even_if_entry_is_unchanged": True,
},
"Updated title",
"5678",
{"vendor": "data2"},
{"vendor": "options2"},
(2, 1), (2, 1),
), ),
( (
("Test", "Test"), {
("1234", "1234"), "unique_id": "1234",
("data", "data"), "title": "Test",
("options", "options"), "data": {"vendor": "data"},
{"reload_even_if_entry_is_unchanged": False}, "options": {"vendor": "options"},
"reload_even_if_entry_is_unchanged": False,
},
"Test",
"1234",
{"vendor": "data"},
{"vendor": "options"},
(1, 0), (1, 0),
), ),
(
{},
"Test",
"1234",
{"vendor": "data"},
{"vendor": "options"},
(2, 1),
),
(
{"data": {"buyer": "me"}, "options": {}},
"Test",
"1234",
{"buyer": "me"},
{},
(2, 1),
),
], ],
ids=[ ids=[
"changed_entry_default", "changed_entry_default",
"unchanged_entry_default", "unchanged_entry_default",
"changed_entry_explicit_reload", "changed_entry_explicit_reload",
"changed_entry_no_reload", "unchanged_entry_no_reload",
"no_kwargs",
"replace_data",
], ],
) )
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -5175,20 +5215,20 @@ async def test_update_entry_and_reload(
hass: HomeAssistant, hass: HomeAssistant,
source: str, source: str,
reason: str, reason: str,
title: tuple[str, str], expected_title: str,
unique_id: tuple[str, str], expected_unique_id: str,
data_vendor: tuple[str, str], expected_data: dict[str, Any],
options_vendor: tuple[str, str], expected_options: dict[str, Any],
kwargs: dict[str, Any], kwargs: dict[str, Any],
calls_entry_load_unload: tuple[int, int], calls_entry_load_unload: tuple[int, int],
) -> None: ) -> None:
"""Test updating an entry and reloading.""" """Test updating an entry and reloading."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain="comp", domain="comp",
unique_id=unique_id[0], unique_id="1234",
title=title[0], title="Test",
data={"vendor": data_vendor[0]}, data={"vendor": "data"},
options={"vendor": options_vendor[0]}, options={"vendor": "options"},
) )
entry.add_to_hass(hass) entry.add_to_hass(hass)
@ -5209,37 +5249,24 @@ async def test_update_entry_and_reload(
async def async_step_reauth(self, data): async def async_step_reauth(self, data):
"""Mock Reauth.""" """Mock Reauth."""
return self.async_update_reload_and_abort( return self.async_update_reload_and_abort(entry, **kwargs)
entry=entry,
unique_id=unique_id[1],
title=title[1],
data={"vendor": data_vendor[1]},
options={"vendor": options_vendor[1]},
**kwargs,
)
async def async_step_reconfigure(self, data): async def async_step_reconfigure(self, data):
"""Mock Reauth.""" """Mock Reconfigure."""
return self.async_update_reload_and_abort( return self.async_update_reload_and_abort(entry, **kwargs)
entry=entry,
unique_id=unique_id[1],
title=title[1],
data={"vendor": data_vendor[1]},
options={"vendor": options_vendor[1]},
**kwargs,
)
with mock_config_flow("comp", MockFlowHandler): with mock_config_flow("comp", MockFlowHandler):
if source == config_entries.SOURCE_REAUTH: if source == config_entries.SOURCE_REAUTH:
result = await entry.start_reauth_flow(hass) result = await entry.start_reauth_flow(hass)
elif source == config_entries.SOURCE_RECONFIGURE: elif source == config_entries.SOURCE_RECONFIGURE:
result = await entry.start_reconfigure_flow(hass) result = await entry.start_reconfigure_flow(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
assert entry.title == title[1] assert entry.title == expected_title
assert entry.unique_id == unique_id[1] assert entry.unique_id == expected_unique_id
assert entry.data == {"vendor": data_vendor[1]} assert entry.data == expected_data
assert entry.options == {"vendor": options_vendor[1]} assert entry.options == expected_options
assert entry.state == config_entries.ConfigEntryState.LOADED assert entry.state == config_entries.ConfigEntryState.LOADED
assert result["type"] == FlowResultType.ABORT assert result["type"] == FlowResultType.ABORT
assert result["reason"] == reason assert result["reason"] == reason