88 lines
2.6 KiB
Python
88 lines
2.6 KiB
Python
"""Test the Wyoming config flow."""
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.components.wyoming.const import DOMAIN
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.data_entry_flow import FlowResultType
|
|
|
|
from . import EMPTY_INFO, STT_INFO
|
|
|
|
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
|
|
|
|
|
async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
|
"""Test we get the form."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
assert result["type"] == FlowResultType.FORM
|
|
assert result["errors"] is None
|
|
|
|
with patch(
|
|
"homeassistant.components.wyoming.data.load_wyoming_info",
|
|
return_value=STT_INFO,
|
|
):
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{
|
|
"host": "1.1.1.1",
|
|
"port": 1234,
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
|
assert result2["title"] == "Test ASR"
|
|
assert result2["data"] == {
|
|
"host": "1.1.1.1",
|
|
"port": 1234,
|
|
}
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
|
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
|
"""Test we handle cannot connect error."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
|
|
with patch(
|
|
"homeassistant.components.wyoming.data.load_wyoming_info",
|
|
return_value=None,
|
|
):
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{
|
|
"host": "1.1.1.1",
|
|
"port": 1234,
|
|
},
|
|
)
|
|
|
|
assert result2["type"] == FlowResultType.FORM
|
|
assert result2["errors"] == {"base": "cannot_connect"}
|
|
|
|
|
|
async def test_no_supported_services(hass: HomeAssistant) -> None:
|
|
"""Test we handle no supported services error."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
|
|
with patch(
|
|
"homeassistant.components.wyoming.data.load_wyoming_info",
|
|
return_value=EMPTY_INFO,
|
|
):
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{
|
|
"host": "1.1.1.1",
|
|
"port": 1234,
|
|
},
|
|
)
|
|
|
|
assert result2["type"] == FlowResultType.ABORT
|
|
assert result2["reason"] == "no_services"
|