mirror of
https://github.com/home-assistant/core.git
synced 2025-06-24 17:11:53 +02:00
Fix unbound var and tests in PlayStation Network integration (#147398)
fix unbound var and test mocks
This commit is contained in:
@ -37,8 +37,7 @@ class PlaystationNetworkConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
npsso = parse_npsso_token(user_input[CONF_NPSSO])
|
||||
except PSNAWPInvalidTokenError:
|
||||
errors["base"] = "invalid_account"
|
||||
|
||||
if npsso:
|
||||
else:
|
||||
psn = PlaystationNetwork(self.hass, npsso)
|
||||
try:
|
||||
user: User = await psn.get_user()
|
||||
|
@ -6,7 +6,7 @@
|
||||
"npsso": "NPSSO token"
|
||||
},
|
||||
"data_description": {
|
||||
"npsso": "The NPSSO token is generated during successful login of your PlayStation Network account and is used to authenticate your requests from with Home Assistant."
|
||||
"npsso": "The NPSSO token is generated upon successful login of your PlayStation Network account and is used to authenticate your requests within Home Assistant."
|
||||
},
|
||||
"description": "To obtain your NPSSO token, log in to your [PlayStation account]({psn_link}) first. Then [click here]({npsso_link}) to retrieve the token."
|
||||
}
|
||||
|
@ -97,12 +97,9 @@ def mock_psnawp_npsso(mock_user: MagicMock) -> Generator[MagicMock]:
|
||||
"""Mock psnawp_api."""
|
||||
|
||||
with patch(
|
||||
"psnawp_api.utils.misc.parse_npsso_token",
|
||||
autospec=True,
|
||||
) as mock_parse_npsso_token:
|
||||
npsso = mock_parse_npsso_token.return_value
|
||||
npsso.parse_npsso_token.return_value = NPSSO_TOKEN
|
||||
|
||||
"homeassistant.components.playstation_network.config_flow.parse_npsso_token",
|
||||
side_effect=lambda token: token,
|
||||
) as npsso:
|
||||
yield npsso
|
||||
|
||||
|
||||
|
@ -120,7 +120,7 @@ async def test_parse_npsso_token_failures(
|
||||
mock_psnawp_npsso: MagicMock,
|
||||
) -> None:
|
||||
"""Test parse_npsso_token raises the correct exceptions during config flow."""
|
||||
mock_psnawp_npsso.parse_npsso_token.side_effect = PSNAWPInvalidTokenError
|
||||
mock_psnawp_npsso.side_effect = PSNAWPInvalidTokenError
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
@ -128,7 +128,7 @@ async def test_parse_npsso_token_failures(
|
||||
)
|
||||
assert result["errors"] == {"base": "invalid_account"}
|
||||
|
||||
mock_psnawp_npsso.parse_npsso_token.side_effect = None
|
||||
mock_psnawp_npsso.side_effect = lambda token: token
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_NPSSO: NPSSO_TOKEN},
|
||||
|
Reference in New Issue
Block a user