async def test_form_invalid_auth(opp): """Test we handle invalid auth.""" result = await opp.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}) with patch( "openpeerpower.components.control4.config_flow.C4Account", side_effect=Unauthorized("message"), ): result2 = await opp.config_entries.flow.async_configure( result["flow_id"], { CONF_HOST: "1.1.1.1", CONF_USERNAME: "******", CONF_PASSWORD: "******", }, ) assert result2["type"] == "form" assert result2["errors"] == {"base": "invalid_auth"}
async def test_form_cannot_connect(opp): """Test we handle cannot connect error.""" result = await opp.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}) with patch( "openpeerpower.components.control4.config_flow.Control4Validator.authenticate", return_value=True, ), patch( "openpeerpower.components.control4.config_flow.C4Director", side_effect=Unauthorized("message"), ): result2 = await opp.config_entries.flow.async_configure( result["flow_id"], { CONF_HOST: "1.1.1.1", CONF_USERNAME: "******", CONF_PASSWORD: "******", }, ) assert result2["type"] == "form" assert result2["errors"] == {"base": "cannot_connect"}