@@ -137,17 +137,46 @@ async def test_form_exception_handling(
137137 assert len (mock_setup_entry .mock_calls ) == 1
138138
139139
140+ async def test_reauth_flow_scenario (
141+ hass : HomeAssistant ,
142+ mock_airos_client : AsyncMock ,
143+ mock_config_entry : MockConfigEntry ,
144+ ) -> None :
145+ """Test successful reauthentication."""
146+ mock_config_entry .add_to_hass (hass )
147+
148+ mock_airos_client .login .side_effect = AirOSConnectionAuthenticationError
149+ await hass .config_entries .async_setup (mock_config_entry .entry_id )
150+
151+ flows = hass .config_entries .flow .async_progress ()
152+ assert len (flows ) == 1
153+
154+ flow = flows [0 ]
155+ assert flow ["step_id" ] == REAUTH_STEP
156+
157+ mock_airos_client .login .side_effect = None
158+ result = await hass .config_entries .flow .async_configure (
159+ flow ["flow_id" ],
160+ user_input = {CONF_PASSWORD : NEW_PASSWORD },
161+ )
162+
163+ # Always test resolution
164+ assert result ["type" ] is FlowResultType .ABORT
165+ assert result ["reason" ] == "reauth_successful"
166+
167+ updated_entry = hass .config_entries .async_get_entry (mock_config_entry .entry_id )
168+ assert updated_entry .data [CONF_PASSWORD ] == NEW_PASSWORD
169+
170+
140171@pytest .mark .parametrize (
141172 ("reauth_exception" , "expected_error" ),
142173 [
143- (None , None ),
144174 (AirOSConnectionAuthenticationError , "invalid_auth" ),
145175 (AirOSDeviceConnectionError , "cannot_connect" ),
146176 (AirOSKeyDataMissingError , "key_data_missing" ),
147177 (Exception , "unknown" ),
148178 ],
149179 ids = [
150- "reauth_succes" ,
151180 "invalid_auth" ,
152181 "cannot_connect" ,
153182 "key_data_missing" ,
@@ -180,19 +209,16 @@ async def test_reauth_flow_scenarios(
180209 user_input = {CONF_PASSWORD : NEW_PASSWORD },
181210 )
182211
183- if expected_error :
184- assert result ["type" ] is FlowResultType .FORM
185- assert result ["step_id" ] == REAUTH_STEP
186- assert result ["errors" ] == {"base" : expected_error }
212+ assert result ["type" ] is FlowResultType .FORM
213+ assert result ["step_id" ] == REAUTH_STEP
214+ assert result ["errors" ] == {"base" : expected_error }
187215
188- # Retry
189- mock_airos_client .login .side_effect = None
190- result = await hass .config_entries .flow .async_configure (
191- flow ["flow_id" ],
192- user_input = {CONF_PASSWORD : NEW_PASSWORD },
193- )
216+ mock_airos_client .login .side_effect = None
217+ result = await hass .config_entries .flow .async_configure (
218+ flow ["flow_id" ],
219+ user_input = {CONF_PASSWORD : NEW_PASSWORD },
220+ )
194221
195- # Always test resolution
196222 assert result ["type" ] is FlowResultType .ABORT
197223 assert result ["reason" ] == "reauth_successful"
198224
0 commit comments