mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add full test coverage for Fritz config_flow (#142418)
This commit is contained in:
parent
82c688e3be
commit
816edb66c7
@ -4,9 +4,7 @@ rules:
|
||||
appropriate-polling: done
|
||||
brands: done
|
||||
common-modules: done
|
||||
config-flow-test-coverage:
|
||||
status: todo
|
||||
comment: one coverage miss in line 110
|
||||
config-flow-test-coverage: done
|
||||
config-flow: done
|
||||
dependency-transparency: done
|
||||
docs-actions: done
|
||||
|
@ -200,6 +200,7 @@ MOCK_FB_SERVICES: dict[str, dict] = {
|
||||
MOCK_IPS["printer"]: {"NewDisallow": False, "NewWANAccess": "granted"}
|
||||
}
|
||||
},
|
||||
"X_AVM-DE_UPnP1": {"GetInfo": {"NewEnable": True}},
|
||||
}
|
||||
|
||||
MOCK_MESH_DATA = {
|
||||
|
@ -27,6 +27,7 @@
|
||||
'WLANConfiguration1',
|
||||
'X_AVM-DE_Homeauto1',
|
||||
'X_AVM-DE_HostFilter1',
|
||||
'X_AVM-DE_UPnP1',
|
||||
]),
|
||||
'is_router': True,
|
||||
'last_exception': None,
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Tests for Fritz!Tools config flow."""
|
||||
|
||||
from copy import deepcopy
|
||||
import dataclasses
|
||||
from unittest.mock import patch
|
||||
|
||||
@ -20,6 +21,7 @@ from homeassistant.components.fritz.const import (
|
||||
ERROR_AUTH_INVALID,
|
||||
ERROR_CANNOT_CONNECT,
|
||||
ERROR_UNKNOWN,
|
||||
ERROR_UPNP_NOT_CONFIGURED,
|
||||
FRITZ_AUTH_EXCEPTIONS,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER
|
||||
@ -38,7 +40,9 @@ from homeassistant.helpers.service_info.ssdp import (
|
||||
SsdpServiceInfo,
|
||||
)
|
||||
|
||||
from .conftest import FritzConnectionMock
|
||||
from .const import (
|
||||
MOCK_FB_SERVICES,
|
||||
MOCK_FIRMWARE_INFO,
|
||||
MOCK_IPS,
|
||||
MOCK_REQUEST,
|
||||
@ -761,3 +765,54 @@ async def test_ssdp_ipv6_link_local(hass: HomeAssistant) -> None:
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "ignore_ip6_link_local"
|
||||
|
||||
|
||||
async def test_upnp_not_enabled(hass: HomeAssistant) -> None:
|
||||
"""Test if UPNP service is enabled on the router."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
# Disable UPnP
|
||||
services = deepcopy(MOCK_FB_SERVICES)
|
||||
services["X_AVM-DE_UPnP1"]["GetInfo"]["NewEnable"] = False
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.fritz.config_flow.FritzConnection",
|
||||
return_value=FritzConnectionMock(services),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=MOCK_USER_INPUT_SIMPLE
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"]["base"] == ERROR_UPNP_NOT_CONFIGURED
|
||||
|
||||
# Enable UPnP
|
||||
services["X_AVM-DE_UPnP1"]["GetInfo"]["NewEnable"] = True
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.fritz.config_flow.FritzConnection",
|
||||
return_value=FritzConnectionMock(services),
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.fritz.config_flow.socket.gethostbyname",
|
||||
return_value=MOCK_IPS["fritz.box"],
|
||||
),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=MOCK_USER_INPUT_SIMPLE
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"][CONF_HOST] == "fake_host"
|
||||
assert result["data"][CONF_PASSWORD] == "fake_pass"
|
||||
assert result["data"][CONF_USERNAME] == "fake_user"
|
||||
assert result["data"][CONF_PORT] == 49000
|
||||
assert result["data"][CONF_SSL] is False
|
||||
|
Loading…
x
Reference in New Issue
Block a user