diff --git a/homeassistant/components/motioneye/config_flow.py b/homeassistant/components/motioneye/config_flow.py index 557025a58994..b80df4b75365 100644 --- a/homeassistant/components/motioneye/config_flow.py +++ b/homeassistant/components/motioneye/config_flow.py @@ -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, diff --git a/tests/components/motioneye/test_config_flow.py b/tests/components/motioneye/test_config_flow.py index 7dbc851394a3..fbd8a0915681 100644 --- a/tests/components/motioneye/test_config_flow.py +++ b/tests/components/motioneye/test_config_flow.py @@ -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