Exemplo n.º 1
0
async def test_api_error(hass):
    """Test API error."""
    with patch(
            "homeassistant.components.accuweather.AccuWeather._async_get_data",
            side_effect=ApiError("Invalid response from AccuWeather API"),
    ):

        result = await hass.config_entries.flow.async_init(
            DOMAIN,
            context={"source": SOURCE_USER},
            data=VALID_CONFIG,
        )

        assert result["errors"] == {"base": "cannot_connect"}
Exemplo n.º 2
0
async def test_config_not_ready(hass):
    """Test for setup failure if connection to AccuWeather is missing."""
    entry = MockConfigEntry(
        domain=DOMAIN,
        title="Home",
        unique_id="0123456",
        data={
            "api_key": "32-character-string-1234567890qw",
            "latitude": 55.55,
            "longitude": 122.12,
            "name": "Home",
        },
    )

    with patch(
            "homeassistant.components.accuweather.AccuWeather._async_get_data",
            side_effect=ApiError("API Error"),
    ):
        entry.add_to_hass(hass)
        await hass.config_entries.async_setup(entry.entry_id)
        assert entry.state is ConfigEntryState.SETUP_RETRY