Add reauth flow to webOS TV integration (#86168)
* Add reauth flow to webOS TV integration * Remove unnecessary else
This commit is contained in:
parent
f2b348dbdf
commit
c40c37e9ee
8 changed files with 217 additions and 37 deletions
|
@ -9,11 +9,11 @@ from homeassistant import config_entries
|
|||
from homeassistant.components import ssdp
|
||||
from homeassistant.components.webostv.const import CONF_SOURCES, DOMAIN, LIVE_TV_APP_ID
|
||||
from homeassistant.config_entries import SOURCE_SSDP
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_SOURCE
|
||||
from homeassistant.const import CONF_CLIENT_SECRET, CONF_HOST, CONF_NAME, CONF_SOURCE
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from . import setup_webostv
|
||||
from .const import FAKE_UUID, HOST, MOCK_APPS, MOCK_INPUTS, TV_NAME
|
||||
from .const import CLIENT_KEY, FAKE_UUID, HOST, MOCK_APPS, MOCK_INPUTS, TV_NAME
|
||||
|
||||
MOCK_USER_CONFIG = {
|
||||
CONF_HOST: HOST,
|
||||
|
@ -289,3 +289,64 @@ async def test_form_abort_uuid_configured(hass, client):
|
|||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert entry.data[CONF_HOST] == "new_host"
|
||||
|
||||
|
||||
async def test_reauth_successful(hass, client, monkeypatch):
|
||||
"""Test that the reauthorization is successful."""
|
||||
entry = await setup_webostv(hass)
|
||||
assert client
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_REAUTH, "entry_id": entry.entry_id},
|
||||
data=entry.data,
|
||||
)
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
assert entry.data[CONF_CLIENT_SECRET] == CLIENT_KEY
|
||||
|
||||
monkeypatch.setattr(client, "client_key", "new_key")
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={}
|
||||
)
|
||||
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
assert entry.data[CONF_CLIENT_SECRET] == "new_key"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"side_effect,reason",
|
||||
[
|
||||
(WebOsTvPairError, "error_pairing"),
|
||||
(ConnectionRefusedError, "reauth_unsuccessful"),
|
||||
],
|
||||
)
|
||||
async def test_reauth_errors(hass, client, monkeypatch, side_effect, reason):
|
||||
"""Test reauthorization errors."""
|
||||
entry = await setup_webostv(hass)
|
||||
assert client
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_REAUTH, "entry_id": entry.entry_id},
|
||||
data=entry.data,
|
||||
)
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
monkeypatch.setattr(client, "connect", Mock(side_effect=side_effect))
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={}
|
||||
)
|
||||
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == reason
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue