async def test_webhook_error(hass, smartthings_mock): """Test an error is when there's an error with the webhook endpoint.""" flow = SmartThingsFlowHandler() flow.hass = hass data = {'error': {}} error = APIResponseError(None, None, data=data, status=422) error.is_target_error = Mock(return_value=True) smartthings_mock.apps.side_effect = error result = await flow.async_step_user({'access_token': str(uuid4())}) assert result['type'] == data_entry_flow.RESULT_TYPE_FORM assert result['step_id'] == 'user' assert result['errors'] == {'base': 'webhook_error'}
async def test_webhook_error(hass, smartthings_mock): """Test an error is when there's an error with the webhook endpoint.""" flow = SmartThingsFlowHandler() flow.hass = hass data = {'error': {}} error = APIResponseError(None, None, data=data, status=422) error.is_target_error = Mock(return_value=True) smartthings_mock.return_value.apps.return_value = mock_coro( exception=error) result = await flow.async_step_user({'access_token': str(uuid4())}) assert result['type'] == data_entry_flow.RESULT_TYPE_FORM assert result['step_id'] == 'user' assert result['errors'] == {'base': 'webhook_error'}
async def test_webhook_error(hass, smartthings_mock): """Test an error is when there's an error with the webhook endpoint.""" flow = SmartThingsFlowHandler() flow.hass = hass data = {"error": {}} request_info = Mock(real_url="http://example.com") error = APIResponseError(request_info=request_info, history=None, data=data, status=422) error.is_target_error = Mock(return_value=True) smartthings_mock.apps.side_effect = error result = await flow.async_step_user({"access_token": str(uuid4())}) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" assert result["errors"] == {"base": "webhook_error"}
async def test_step_pat_webhook_error(hass, smartthings_mock): """Test an error is shown when there's an problem with the webhook endpoint.""" flow = SmartThingsFlowHandler() flow.hass = hass data = {"error": {}} request_info = Mock(real_url="http://example.com") error = APIResponseError(request_info=request_info, history=None, data=data, status=422) error.is_target_error = Mock(return_value=True) smartthings_mock.apps.side_effect = error token = str(uuid4()) result = await flow.async_step_pat({CONF_ACCESS_TOKEN: token}) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "pat" assert result["errors"] == {"base": "webhook_error"} assert result["data_schema"]({}) == {CONF_ACCESS_TOKEN: token}
async def test_webhook_problem_shows_error(hass, smartthings_mock): """Test an error is shown when there's an problem with the webhook endpoint.""" token = str(uuid4()) data = {"error": {}} request_info = Mock(real_url="http://example.com") error = APIResponseError( request_info=request_info, history=None, data=data, status=HTTPStatus.UNPROCESSABLE_ENTITY, ) error.is_target_error = Mock(return_value=True) smartthings_mock.apps.side_effect = error # Webhook confirmation shown result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" assert result["description_placeholders"][ "webhook_url"] == smartapp.get_webhook_url(hass) # Advance to PAT screen result = await hass.config_entries.flow.async_configure( result["flow_id"], {}) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "pat" assert "token_url" in result["description_placeholders"] assert "component_url" in result["description_placeholders"] # Enter token result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_ACCESS_TOKEN: token}) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "pat" assert result["data_schema"]({}) == {CONF_ACCESS_TOKEN: token} assert result["errors"] == {"base": "webhook_error"} assert "token_url" in result["description_placeholders"] assert "component_url" in result["description_placeholders"]