1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-26 03:39:31 +01:00

Update config flow test scaffolding (#30694)

* Update config flow test scaffolding

* asyncpatch -> patch

* Update classname
This commit is contained in:
Paulus Schoutsen
2020-01-13 06:20:25 -08:00
committed by Pascal Vizeli
parent 040b283a14
commit f50714d7e9
2 changed files with 37 additions and 13 deletions

View File

@@ -1,12 +1,10 @@
"""Test the NEW_NAME config flow."""
from unittest.mock import patch
from asynctest import patch
from homeassistant import config_entries, setup
from homeassistant.components.NEW_DOMAIN.config_flow import CannotConnect, InvalidAuth
from homeassistant.components.NEW_DOMAIN.const import DOMAIN
from tests.common import mock_coro
async def test_form(hass):
"""Test we get the form."""
@@ -18,13 +16,12 @@ async def test_form(hass):
assert result["errors"] == {}
with patch(
"homeassistant.components.NEW_DOMAIN.config_flow.validate_input",
return_value=mock_coro({"title": "Test Title"}),
"homeassistant.components.NEW_DOMAIN.config_flow.PlaceholderHub.authenticate",
return_value=True,
), patch(
"homeassistant.components.NEW_DOMAIN.async_setup", return_value=mock_coro(True)
"homeassistant.components.NEW_DOMAIN.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.NEW_DOMAIN.async_setup_entry",
return_value=mock_coro(True),
"homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True,
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
@@ -36,7 +33,7 @@ async def test_form(hass):
)
assert result2["type"] == "create_entry"
assert result2["title"] == "Test Title"
assert result2["title"] == "Name of the device"
assert result2["data"] == {
"host": "1.1.1.1",
"username": "test-username",
@@ -54,7 +51,7 @@ async def test_form_invalid_auth(hass):
)
with patch(
"homeassistant.components.NEW_DOMAIN.config_flow.validate_input",
"homeassistant.components.NEW_DOMAIN.config_flow.PlaceholderHub.authenticate",
side_effect=InvalidAuth,
):
result2 = await hass.config_entries.flow.async_configure(
@@ -77,7 +74,7 @@ async def test_form_cannot_connect(hass):
)
with patch(
"homeassistant.components.NEW_DOMAIN.config_flow.validate_input",
"homeassistant.components.NEW_DOMAIN.config_flow.PlaceholderHub.authenticate",
side_effect=CannotConnect,
):
result2 = await hass.config_entries.flow.async_configure(