mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 23:41:48 -05:00
Allow empty motionEye usernames (#181270)
This commit is contained in:
@@ -71,7 +71,7 @@ class MotionEyeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
**url_schema,
|
||||
vol.Optional(
|
||||
CONF_ADMIN_USERNAME,
|
||||
default=user_input.get(CONF_ADMIN_USERNAME),
|
||||
default=user_input.get(CONF_ADMIN_USERNAME, ""),
|
||||
): str,
|
||||
vol.Optional(
|
||||
CONF_ADMIN_PASSWORD,
|
||||
@@ -79,7 +79,7 @@ class MotionEyeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
): str,
|
||||
vol.Optional(
|
||||
CONF_SURVEILLANCE_USERNAME,
|
||||
default=user_input.get(CONF_SURVEILLANCE_USERNAME),
|
||||
default=user_input.get(CONF_SURVEILLANCE_USERNAME, ""),
|
||||
): str,
|
||||
vol.Optional(
|
||||
CONF_SURVEILLANCE_PASSWORD,
|
||||
|
||||
@@ -7,6 +7,7 @@ from motioneye_client.client import (
|
||||
MotionEyeClientInvalidAuthError,
|
||||
MotionEyeClientRequestError,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.motioneye.const import (
|
||||
@@ -30,7 +31,44 @@ from . import TEST_URL, create_mock_motioneye_client, create_mock_motioneye_conf
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_user_success(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("user_input", "expected_data"),
|
||||
[
|
||||
pytest.param(
|
||||
{
|
||||
CONF_URL: TEST_URL,
|
||||
CONF_ADMIN_USERNAME: "admin-username",
|
||||
CONF_ADMIN_PASSWORD: "admin-password",
|
||||
CONF_SURVEILLANCE_USERNAME: "surveillance-username",
|
||||
CONF_SURVEILLANCE_PASSWORD: "surveillance-password",
|
||||
},
|
||||
{
|
||||
CONF_URL: TEST_URL,
|
||||
CONF_ADMIN_USERNAME: "admin-username",
|
||||
CONF_ADMIN_PASSWORD: "admin-password",
|
||||
CONF_SURVEILLANCE_USERNAME: "surveillance-username",
|
||||
CONF_SURVEILLANCE_PASSWORD: "surveillance-password",
|
||||
},
|
||||
id="credentials",
|
||||
),
|
||||
pytest.param(
|
||||
{CONF_URL: TEST_URL},
|
||||
{
|
||||
CONF_URL: TEST_URL,
|
||||
CONF_ADMIN_USERNAME: "",
|
||||
CONF_ADMIN_PASSWORD: "",
|
||||
CONF_SURVEILLANCE_USERNAME: "",
|
||||
CONF_SURVEILLANCE_PASSWORD: "",
|
||||
},
|
||||
id="no_credentials",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_user_success(
|
||||
hass: HomeAssistant,
|
||||
user_input: dict[str, str],
|
||||
expected_data: dict[str, str],
|
||||
) -> None:
|
||||
"""Test successful user flow."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@@ -52,26 +90,13 @@ async def test_user_success(hass: HomeAssistant) -> None:
|
||||
) as mock_setup_entry,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_URL: TEST_URL,
|
||||
CONF_ADMIN_USERNAME: "admin-username",
|
||||
CONF_ADMIN_PASSWORD: "admin-password",
|
||||
CONF_SURVEILLANCE_USERNAME: "surveillance-username",
|
||||
CONF_SURVEILLANCE_PASSWORD: "surveillance-password",
|
||||
},
|
||||
result["flow_id"], user_input
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == f"{TEST_URL}"
|
||||
assert result["data"] == {
|
||||
CONF_URL: TEST_URL,
|
||||
CONF_ADMIN_USERNAME: "admin-username",
|
||||
CONF_ADMIN_PASSWORD: "admin-password",
|
||||
CONF_SURVEILLANCE_USERNAME: "surveillance-username",
|
||||
CONF_SURVEILLANCE_PASSWORD: "surveillance-password",
|
||||
}
|
||||
assert result["data"] == expected_data
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
assert mock_client.async_client_close.called
|
||||
|
||||
|
||||
Reference in New Issue
Block a user