Fix tolo test warning (#99555)

This commit is contained in:
Marc Mueller 2023-09-04 02:58:01 +02:00 committed by GitHub
parent 377d9f6687
commit 115518cab9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,6 +23,18 @@ def toloclient_fixture() -> Mock:
yield toloclient
@pytest.fixture
def coordinator_toloclient() -> Mock:
"""Patch ToloClient in async_setup_entry.
Throw exception to abort entry setup and prevent socket IO. Only testing config flow.
"""
with patch(
"homeassistant.components.tolo.ToloClient", side_effect=Exception
) as toloclient:
yield toloclient
async def test_user_with_timed_out_host(hass: HomeAssistant, toloclient: Mock) -> None:
"""Test a user initiated config flow with provided host which times out."""
toloclient().get_status_info.side_effect = ResponseTimedOutError()
@ -38,7 +50,9 @@ async def test_user_with_timed_out_host(hass: HomeAssistant, toloclient: Mock) -
assert result["errors"] == {"base": "cannot_connect"}
async def test_user_walkthrough(hass: HomeAssistant, toloclient: Mock) -> None:
async def test_user_walkthrough(
hass: HomeAssistant, toloclient: Mock, coordinator_toloclient: Mock
) -> None:
"""Test complete user flow with first wrong and then correct host."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
@ -70,7 +84,9 @@ async def test_user_walkthrough(hass: HomeAssistant, toloclient: Mock) -> None:
assert result3["data"][CONF_HOST] == "127.0.0.1"
async def test_dhcp(hass: HomeAssistant, toloclient: Mock) -> None:
async def test_dhcp(
hass: HomeAssistant, toloclient: Mock, coordinator_toloclient: Mock
) -> None:
"""Test starting a flow from discovery."""
toloclient().get_status_info.side_effect = lambda *args, **kwargs: object()