async def test_availability(hass, aioclient_mock):
    """Ensure that we mark the entities unavailable correctly when service causes an error."""
    await init_integration(hass, aioclient_mock)

    state = hass.states.get("air_quality.home")
    assert state
    assert state.state != STATE_UNAVAILABLE
    assert state.state == "14"

    aioclient_mock.clear_requests()
    aioclient_mock.get(API_POINT_URL,
                       exc=AirlyError(HTTP_INTERNAL_SERVER_ERROR,
                                      "Unexpected error"))
    future = utcnow() + timedelta(minutes=60)

    async_fire_time_changed(hass, future)
    await hass.async_block_till_done()

    state = hass.states.get("air_quality.home")
    assert state
    assert state.state == STATE_UNAVAILABLE

    aioclient_mock.clear_requests()
    aioclient_mock.get(API_POINT_URL,
                       text=load_fixture("airly_valid_station.json"))
    future = utcnow() + timedelta(minutes=120)

    async_fire_time_changed(hass, future)
    await hass.async_block_till_done()

    state = hass.states.get("air_quality.home")
    assert state
    assert state.state != STATE_UNAVAILABLE
    assert state.state == "14"
示例#2
0
async def test_availability(hass):
    """Ensure that we mark the entities unavailable correctly when service causes an error."""
    await init_integration(hass)

    state = hass.states.get("air_quality.home")
    assert state
    assert state.state != STATE_UNAVAILABLE
    assert state.state == "14"

    future = utcnow() + timedelta(minutes=60)
    with patch(
            "airly._private._RequestsHandler.get",
            side_effect=AirlyError(500, "Unexpected error"),
    ):
        async_fire_time_changed(hass, future)
        await hass.async_block_till_done()

        state = hass.states.get("air_quality.home")
        assert state
        assert state.state == STATE_UNAVAILABLE

    future = utcnow() + timedelta(minutes=120)
    with patch(
            "airly._private._RequestsHandler.get",
            return_value=json.loads(load_fixture("airly_valid_station.json")),
    ):
        async_fire_time_changed(hass, future)
        await hass.async_block_till_done()

        state = hass.states.get("air_quality.home")
        assert state
        assert state.state != STATE_UNAVAILABLE
        assert state.state == "14"
async def test_invalid_api_key(hass, aioclient_mock):
    """Test that errors are shown when API key is invalid."""
    aioclient_mock.get(
        API_POINT_URL,
        exc=AirlyError(HTTP_UNAUTHORIZED,
                       {"message": "Invalid authentication credentials"}),
    )

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

    assert result["errors"] == {"base": "invalid_api_key"}
示例#4
0
async def test_invalid_api_key(hass):
    """Test that errors are shown when API key is invalid."""
    with patch(
            "airly._private._RequestsHandler.get",
            side_effect=AirlyError(
                403, {"message": "Invalid authentication credentials"}),
    ):
        flow = config_flow.AirlyFlowHandler()
        flow.hass = hass

        result = await flow.async_step_user(user_input=CONFIG)

        assert result["errors"] == {"base": "auth"}
示例#5
0
async def test_invalid_api_key(hass):
    """Test that errors are shown when API key is invalid."""
    with patch(
            "airly._private._RequestsHandler.get",
            side_effect=AirlyError(
                HTTP_FORBIDDEN,
                {"message": "Invalid authentication credentials"}),
    ):

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

        assert result["errors"] == {"base": "auth"}
示例#6
0
async def test_invalid_location(hass, aioclient_mock):
    """Test that errors are shown when location is invalid."""
    aioclient_mock.get(API_POINT_URL, text=load_fixture("no_station.json", "airly"))

    aioclient_mock.get(
        API_NEAREST_URL,
        exc=AirlyError(HTTPStatus.NOT_FOUND, {"message": "Installation was not found"}),
    )

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

    assert result["errors"] == {"base": "wrong_location"}