Fix unbound var and tests in PlayStation Network integration (#147398)

fix unbound var and test mocks
This commit is contained in:
Manu
2025-06-24 08:53:45 +02:00
committed by GitHub
parent eff35e93bd
commit 121239bcf7
4 changed files with 7 additions and 11 deletions

View File

@ -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()

View File

@ -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."
}

View File

@ -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

View File

@ -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},