@@ -185,6 +185,53 @@ async def test_flow_fails_site_already_configured(hass, aioclient_mock):
185185 )
186186
187187 assert result ["type" ] == data_entry_flow .RESULT_TYPE_ABORT
188+ assert result ["reason" ] == "already_configured"
189+
190+
191+ async def test_flow_fails_site_has_no_local_user (hass , aioclient_mock ):
192+ """Test config flow."""
193+ entry = MockConfigEntry (
194+ domain = UNIFI_DOMAIN , data = {"controller" : {"host" : "1.2.3.4" , "site" : "site_id" }}
195+ )
196+ entry .add_to_hass (hass )
197+
198+ result = await hass .config_entries .flow .async_init (
199+ UNIFI_DOMAIN , context = {"source" : "user" }
200+ )
201+
202+ assert result ["type" ] == data_entry_flow .RESULT_TYPE_FORM
203+ assert result ["step_id" ] == "user"
204+
205+ aioclient_mock .get ("https://1.2.3.4:1234" , status = 302 )
206+
207+ aioclient_mock .post (
208+ "https://1.2.3.4:1234/api/login" ,
209+ json = {"data" : "login successful" , "meta" : {"rc" : "ok" }},
210+ headers = {"content-type" : "application/json" },
211+ )
212+
213+ aioclient_mock .get (
214+ "https://1.2.3.4:1234/api/self/sites" ,
215+ json = {
216+ "data" : [{"desc" : "Site name" , "name" : "site_id" }],
217+ "meta" : {"rc" : "ok" },
218+ },
219+ headers = {"content-type" : "application/json" },
220+ )
221+
222+ result = await hass .config_entries .flow .async_configure (
223+ result ["flow_id" ],
224+ user_input = {
225+ CONF_HOST : "1.2.3.4" ,
226+ CONF_USERNAME : "username" ,
227+ CONF_PASSWORD : "password" ,
228+ CONF_PORT : 1234 ,
229+ CONF_VERIFY_SSL : True ,
230+ },
231+ )
232+
233+ assert result ["type" ] == data_entry_flow .RESULT_TYPE_ABORT
234+ assert result ["reason" ] == "no_local_user"
188235
189236
190237async def test_flow_fails_user_credentials_faulty (hass , aioclient_mock ):
0 commit comments