mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Strip the NYT Games token (#127548)
This commit is contained in:
parent
ae8219dc97
commit
ebfa2fb1d0
@ -22,7 +22,8 @@ class NYTGamesConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
if user_input:
|
if user_input:
|
||||||
session = async_create_clientsession(self.hass)
|
session = async_create_clientsession(self.hass)
|
||||||
client = NYTGamesClient(user_input[CONF_TOKEN], session=session)
|
token = user_input[CONF_TOKEN].strip()
|
||||||
|
client = NYTGamesClient(token, session=session)
|
||||||
try:
|
try:
|
||||||
user_id = await client.get_user_id()
|
user_id = await client.get_user_id()
|
||||||
except NYTGamesAuthenticationError:
|
except NYTGamesAuthenticationError:
|
||||||
@ -35,7 +36,9 @@ class NYTGamesConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
else:
|
else:
|
||||||
await self.async_set_unique_id(str(user_id))
|
await self.async_set_unique_id(str(user_id))
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(title="NYT Games", data=user_input)
|
return self.async_create_entry(
|
||||||
|
title="NYT Games", data={CONF_TOKEN: token}
|
||||||
|
)
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=vol.Schema({vol.Required(CONF_TOKEN): str}),
|
data_schema=vol.Schema({vol.Required(CONF_TOKEN): str}),
|
||||||
|
@ -37,6 +37,27 @@ async def test_full_flow(
|
|||||||
assert result["result"].unique_id == "218886794"
|
assert result["result"].unique_id == "218886794"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_stripping_token(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_nyt_games_client: AsyncMock,
|
||||||
|
mock_setup_entry: AsyncMock,
|
||||||
|
) -> None:
|
||||||
|
"""Test stripping token."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": SOURCE_USER},
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{CONF_TOKEN: " token "},
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
assert result["data"] == {CONF_TOKEN: "token"}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("exception", "error"),
|
("exception", "error"),
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user