From 121239bcf7a48460a0ea8b5d45a664fadd53ccd2 Mon Sep 17 00:00:00 2001 From: Manu <4445816+tr4nt0r@users.noreply.github.com> Date: Tue, 24 Jun 2025 08:53:45 +0200 Subject: [PATCH] Fix unbound var and tests in PlayStation Network integration (#147398) fix unbound var and test mocks --- .../components/playstation_network/config_flow.py | 3 +-- .../components/playstation_network/strings.json | 2 +- tests/components/playstation_network/conftest.py | 9 +++------ tests/components/playstation_network/test_config_flow.py | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/playstation_network/config_flow.py b/homeassistant/components/playstation_network/config_flow.py index c177aa6e219..e2b402a212e 100644 --- a/homeassistant/components/playstation_network/config_flow.py +++ b/homeassistant/components/playstation_network/config_flow.py @@ -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() diff --git a/homeassistant/components/playstation_network/strings.json b/homeassistant/components/playstation_network/strings.json index 01fc551d929..e4581322edb 100644 --- a/homeassistant/components/playstation_network/strings.json +++ b/homeassistant/components/playstation_network/strings.json @@ -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." } diff --git a/tests/components/playstation_network/conftest.py b/tests/components/playstation_network/conftest.py index 69e84fbaa6b..f03b3e6f1cf 100644 --- a/tests/components/playstation_network/conftest.py +++ b/tests/components/playstation_network/conftest.py @@ -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 diff --git a/tests/components/playstation_network/test_config_flow.py b/tests/components/playstation_network/test_config_flow.py index 107c92d8bff..031872a7a0b 100644 --- a/tests/components/playstation_network/test_config_flow.py +++ b/tests/components/playstation_network/test_config_flow.py @@ -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},