mirror of
https://github.com/elisspace/core.git
synced 2026-10-05 16:56:19 +00:00
Add config flow tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Tests for the Huawei LTE config flow."""
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
from huawei_lte_api.enums.client import ResponseCodeEnum
|
||||
@@ -18,6 +19,7 @@ from homeassistant.const import (
|
||||
CONF_RECIPIENT,
|
||||
CONF_URL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@@ -25,8 +27,9 @@ from tests.common import MockConfigEntry
|
||||
|
||||
FIXTURE_UNIQUE_ID = "SERIALNUMBER"
|
||||
|
||||
FIXTURE_USER_INPUT = {
|
||||
FIXTURE_USER_INPUT: dict[str, Any] = {
|
||||
CONF_URL: "http://192.168.1.1/",
|
||||
CONF_VERIFY_SSL: False,
|
||||
CONF_USERNAME: "admin",
|
||||
CONF_PASSWORD: "secret",
|
||||
}
|
||||
@@ -95,18 +98,36 @@ async def test_already_configured(
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_connection_error(
|
||||
hass: HomeAssistant, requests_mock: requests_mock.Mocker
|
||||
) -> None:
|
||||
"""Test we show user form on connection error."""
|
||||
requests_mock.request(ANY, ANY, exc=ConnectionError())
|
||||
@pytest.mark.parametrize(
|
||||
("exception", "errors", "data_patch"),
|
||||
(
|
||||
(ConnectionError(), {CONF_URL: "unknown"}, {}),
|
||||
(requests.exceptions.SSLError(), {CONF_URL: "ssl_error_try_plain"}, {}),
|
||||
(
|
||||
requests.exceptions.SSLError(),
|
||||
{CONF_URL: "ssl_error_try_unverified"},
|
||||
{CONF_VERIFY_SSL: True},
|
||||
),
|
||||
),
|
||||
)
|
||||
async def test_connection_errors(
|
||||
hass: HomeAssistant,
|
||||
requests_mock: requests_mock.Mocker,
|
||||
exception: Exception,
|
||||
errors: dict[str, str],
|
||||
data_patch: dict[str, Any],
|
||||
):
|
||||
"""Test we show user form on various errors."""
|
||||
requests_mock.request(ANY, ANY, exc=exception)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=FIXTURE_USER_INPUT
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data=FIXTURE_USER_INPUT | data_patch,
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {CONF_URL: "unknown"}
|
||||
assert result["errors"] == errors
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -300,8 +321,9 @@ async def test_ssdp(
|
||||
)
|
||||
|
||||
for k, v in expected_result.items():
|
||||
assert result[k] == v
|
||||
assert result[k] == v # type: ignore[literal-required] # expected is a subset
|
||||
if result.get("data_schema"):
|
||||
assert result["data_schema"] is not None
|
||||
assert result["data_schema"]({})[CONF_URL] == url + "/"
|
||||
|
||||
|
||||
@@ -355,6 +377,7 @@ async def test_reauth(
|
||||
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
assert result["data_schema"] is not None
|
||||
assert result["data_schema"]({}) == {
|
||||
CONF_USERNAME: mock_entry_data[CONF_USERNAME],
|
||||
CONF_PASSWORD: mock_entry_data[CONF_PASSWORD],
|
||||
@@ -376,7 +399,7 @@ async def test_reauth(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
for k, v in expected_result.items():
|
||||
assert result[k] == v
|
||||
assert result[k] == v # type: ignore[literal-required] # expected is a subset
|
||||
for k, v in expected_entry_data.items():
|
||||
assert entry.data[k] == v
|
||||
|
||||
|
||||
Reference in New Issue
Block a user