Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Jan 25, 2025
1 parent 9fdb1d6 commit 3f935bb
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/components/reolink/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ApiError,
CredentialsInvalidError,
LoginFirmwareError,
LoginPrivacyModeError,
ReolinkError,
)

Expand Down Expand Up @@ -88,6 +89,58 @@ async def test_config_flow_manual_success(
assert result["result"].unique_id == TEST_MAC


async def test_config_flow_privacy_success(
hass: HomeAssistant, reolink_connect: MagicMock, mock_setup_entry: MagicMock
) -> None:
"""Successful flow when privacy mode is turned on."""
reolink_connect.baichuan.privacy_mode.return_value = True
reolink_connect.get_host_data.side_effect = LoginPrivacyModeError("Test error")

result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_USERNAME: TEST_USERNAME,
CONF_PASSWORD: TEST_PASSWORD,
CONF_HOST: TEST_HOST,
},
)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "privacy"
assert result["errors"] is None

assert reolink_connect.baichuan.set_privacy_mode.call_count == 0
reolink_connect.get_host_data.reset_mock(side_effect=True)

result = await hass.config_entries.flow.async_configure(result["flow_id"], {})

assert reolink_connect.baichuan.set_privacy_mode.call_count == 1

assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == TEST_NVR_NAME
assert result["data"] == {
CONF_HOST: TEST_HOST,
CONF_USERNAME: TEST_USERNAME,
CONF_PASSWORD: TEST_PASSWORD,
CONF_PORT: TEST_PORT,
CONF_USE_HTTPS: TEST_USE_HTTPS,
}
assert result["options"] == {
CONF_PROTOCOL: DEFAULT_PROTOCOL,
}
assert result["result"].unique_id == TEST_MAC

reolink_connect.baichuan.privacy_mode.return_value = False


async def test_config_flow_errors(
hass: HomeAssistant, reolink_connect: MagicMock, mock_setup_entry: MagicMock
) -> None:
Expand Down

0 comments on commit 3f935bb

Please sign in to comment.