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]) npsso = parse_npsso_token(user_input[CONF_NPSSO])
except PSNAWPInvalidTokenError: except PSNAWPInvalidTokenError:
errors["base"] = "invalid_account" errors["base"] = "invalid_account"
else:
if npsso:
psn = PlaystationNetwork(self.hass, npsso) psn = PlaystationNetwork(self.hass, npsso)
try: try:
user: User = await psn.get_user() user: User = await psn.get_user()

View File

@ -6,7 +6,7 @@
"npsso": "NPSSO token" "npsso": "NPSSO token"
}, },
"data_description": { "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." "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.""" """Mock psnawp_api."""
with patch( with patch(
"psnawp_api.utils.misc.parse_npsso_token", "homeassistant.components.playstation_network.config_flow.parse_npsso_token",
autospec=True, side_effect=lambda token: token,
) as mock_parse_npsso_token: ) as npsso:
npsso = mock_parse_npsso_token.return_value
npsso.parse_npsso_token.return_value = NPSSO_TOKEN
yield npsso yield npsso

View File

@ -120,7 +120,7 @@ async def test_parse_npsso_token_failures(
mock_psnawp_npsso: MagicMock, mock_psnawp_npsso: MagicMock,
) -> None: ) -> None:
"""Test parse_npsso_token raises the correct exceptions during config flow.""" """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( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": SOURCE_USER}, context={"source": SOURCE_USER},
@ -128,7 +128,7 @@ async def test_parse_npsso_token_failures(
) )
assert result["errors"] == {"base": "invalid_account"} 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 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{CONF_NPSSO: NPSSO_TOKEN}, {CONF_NPSSO: NPSSO_TOKEN},