Apply code review on progettihwsw (#39520)

This commit is contained in:
Arda ŞEREMET authored and GitHub committed 2020-09-01 19:42:17 +02:00
1 parent 064d115ccb
commit 1eda3d31f9
6 files changed
+80 -115

No files matched your search

@@ -2,9 +2,14 @@
from homeassistant import config_entries, setup
from homeassistant.components.progettihwsw.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
from homeassistant.data_entry_flow import (
RESULT_TYPE_ABORT,
RESULT_TYPE_CREATE_ENTRY,
RESULT_TYPE_FORM,
)
from tests.async_mock import patch
from tests.common import MockConfigEntry
mock_value_step_user = {
"title": "1R & 1IN Board",
@@ -60,35 +65,6 @@ async def test_form(hass):
assert result3["data"]["relay_count"] == result3["data"]["input_count"] == 1
async def test_form_wrong_info(hass):
"""Test we handle wrong info exception."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["step_id"] == "user"
with patch(
"homeassistant.components.progettihwsw.config_flow.ProgettiHWSWAPI.check_board",
return_value=mock_value_step_user,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_HOST: "", CONF_PORT: 80}
)
assert result2["type"] == RESULT_TYPE_FORM
assert result2["step_id"] == "relay_modes"
assert result2["errors"] == {}
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"], {"relay_1": ""}
)
assert result3["type"] == RESULT_TYPE_FORM
assert result3["step_id"] == "relay_modes"
assert result3["errors"] == {"base": "wrong_info_relay_modes"}
async def test_form_cannot_connect(hass):
"""Test we handle unexisting board."""
result = await hass.config_entries.flow.async_init(
@@ -111,6 +87,32 @@ async def test_form_cannot_connect(hass):
assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_existing_entry_exception(hass):
"""Test we handle existing board."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["step_id"] == "user"
entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_HOST: "",
CONF_PORT: 80,
},
)
entry.add_to_hass(hass)
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: "", CONF_PORT: 80},
)
assert result2["type"] == RESULT_TYPE_ABORT
assert result2["reason"] == "already_configured"
async def test_form_user_exception(hass):
"""Test we handle unknown exception."""
result = await hass.config_entries.flow.async_init(
@@ -131,38 +133,3 @@ async def test_form_user_exception(hass):
assert result2["type"] == RESULT_TYPE_FORM
assert result2["step_id"] == "user"
assert result2["errors"] == {"base": "unknown"}
async def test_form_rm_exception(hass):
"""Test we handle unknown exception on seconds step."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["step_id"] == "user"
with patch(
"homeassistant.components.progettihwsw.config_flow.ProgettiHWSWAPI.check_board",
return_value=mock_value_step_user,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: "", CONF_PORT: 80},
)
assert result2["type"] == RESULT_TYPE_FORM
assert result2["step_id"] == "relay_modes"
assert result2["errors"] == {}
with patch(
"homeassistant.components.progettihwsw.config_flow.validate_input_relay_modes",
side_effect=Exception,
):
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{"relay_1": "bistable"},
)
assert result3["type"] == RESULT_TYPE_FORM
assert result3["step_id"] == "relay_modes"
assert result3["errors"] == {"base": "unknown"}