Minor improvement in tests of hardware integrations (#99361)

pull/99317/head
Erik Montnemery 2023-08-30 21:11:52 +02:00 committed by GitHub
parent cdd22bf0fa
commit 03b1c7ad1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 18 deletions

View File

@ -26,7 +26,8 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
) as mock_get_os_info:
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert len(mock_get_os_info.mock_calls) == 1
async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
@ -41,13 +42,17 @@ async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
title="Hardkernel",
)
config_entry.add_to_hass(hass)
assert len(hass.config_entries.async_entries()) == 1
with patch(
"homeassistant.components.hardkernel.get_os_info",
return_value={"board": "generic-x86-64"},
) as mock_get_os_info:
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert len(mock_get_os_info.mock_calls) == 1
assert len(hass.config_entries.async_entries()) == 0
async def test_setup_entry_wait_hassio(hass: HomeAssistant) -> None:
@ -68,5 +73,6 @@ async def test_setup_entry_wait_hassio(hass: HomeAssistant) -> None:
) as mock_get_os_info:
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert config_entry.state == ConfigEntryState.SETUP_RETRY
assert len(mock_get_os_info.mock_calls) == 1
assert config_entry.state == ConfigEntryState.SETUP_RETRY

View File

@ -44,13 +44,17 @@ async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
title="Home Assistant Green",
)
config_entry.add_to_hass(hass)
assert len(hass.config_entries.async_entries()) == 1
with patch(
"homeassistant.components.homeassistant_green.get_os_info",
return_value={"board": "generic-x86-64"},
) as mock_get_os_info:
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert len(mock_get_os_info.mock_calls) == 1
assert len(hass.config_entries.async_entries()) == 0
async def test_setup_entry_wait_hassio(hass: HomeAssistant) -> None:
@ -71,5 +75,6 @@ async def test_setup_entry_wait_hassio(hass: HomeAssistant) -> None:
) as mock_get_os_info:
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert config_entry.state == ConfigEntryState.SETUP_RETRY
assert len(mock_get_os_info.mock_calls) == 1
assert config_entry.state == ConfigEntryState.SETUP_RETRY

View File

@ -37,7 +37,8 @@ async def test_setup_entry(
):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert len(mock_get_os_info.mock_calls) == 1
# Finish setting up ZHA
if num_entries > 0:
@ -216,13 +217,17 @@ async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
title="Home Assistant Yellow",
)
config_entry.add_to_hass(hass)
assert len(hass.config_entries.async_entries()) == 1
with patch(
"homeassistant.components.homeassistant_yellow.get_os_info",
return_value={"board": "generic-x86-64"},
) as mock_get_os_info:
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert len(mock_get_os_info.mock_calls) == 1
assert len(hass.config_entries.async_entries()) == 0
async def test_setup_entry_wait_hassio(hass: HomeAssistant) -> None:
@ -243,8 +248,9 @@ async def test_setup_entry_wait_hassio(hass: HomeAssistant) -> None:
) as mock_get_os_info:
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert config_entry.state == ConfigEntryState.SETUP_RETRY
assert len(mock_get_os_info.mock_calls) == 1
assert config_entry.state == ConfigEntryState.SETUP_RETRY
async def test_setup_entry_addon_info_fails(
@ -269,8 +275,9 @@ async def test_setup_entry_addon_info_fails(
"homeassistant.components.onboarding.async_is_onboarded", return_value=False
):
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state == ConfigEntryState.SETUP_RETRY
await hass.async_block_till_done()
assert config_entry.state == ConfigEntryState.SETUP_RETRY
async def test_setup_entry_addon_not_running(
@ -295,5 +302,6 @@ async def test_setup_entry_addon_not_running(
):
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state == ConfigEntryState.SETUP_RETRY
start_addon.assert_called_once()
assert config_entry.state == ConfigEntryState.SETUP_RETRY
start_addon.assert_called_once()

View File

@ -58,13 +58,17 @@ async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
title="Raspberry Pi",
)
config_entry.add_to_hass(hass)
assert len(hass.config_entries.async_entries()) == 1
with patch(
"homeassistant.components.raspberry_pi.get_os_info",
return_value={"board": "generic-x86-64"},
) as mock_get_os_info:
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert len(mock_get_os_info.mock_calls) == 1
assert len(hass.config_entries.async_entries()) == 0
async def test_setup_entry_wait_hassio(hass: HomeAssistant) -> None:
@ -85,5 +89,6 @@ async def test_setup_entry_wait_hassio(hass: HomeAssistant) -> None:
) as mock_get_os_info:
assert not await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
assert config_entry.state == ConfigEntryState.SETUP_RETRY
assert len(mock_get_os_info.mock_calls) == 1
assert config_entry.state == ConfigEntryState.SETUP_RETRY