Exemple #1
0
async def test_full_user_flow_implementation(
    hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
    """Test the full manual user flow from start to finish."""
    mock_connection(aioclient_mock)

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={CONF_SOURCE: SOURCE_USER},
    )

    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "user"

    user_input = MOCK_USER_INPUT.copy()
    with patch(
        "homeassistant.components.sonarr.async_setup_entry", return_value=True
    ), patch("homeassistant.components.sonarr.async_setup", return_value=True):
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"], user_input=user_input,
        )

    assert result["type"] == RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == HOST

    assert result["data"]
    assert result["data"][CONF_HOST] == HOST
Exemple #2
0
async def test_full_user_flow_advanced_options(
    hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
    """Test the full manual user flow with advanced options."""
    mock_connection(aioclient_mock)

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={CONF_SOURCE: SOURCE_USER, "show_advanced_options": True}
    )

    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "user"

    user_input = {
        **MOCK_USER_INPUT,
        CONF_VERIFY_SSL: True,
    }

    with patch(
        "homeassistant.components.sonarr.async_setup_entry", return_value=True
    ), patch("homeassistant.components.sonarr.async_setup", return_value=True):
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"], user_input=user_input,
        )

    assert result["type"] == RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == HOST

    assert result["data"]
    assert result["data"][CONF_HOST] == HOST
    assert result["data"][CONF_VERIFY_SSL]
Exemple #3
0
async def test_full_user_flow_advanced_options(
        opp: OpenPeerPower, aioclient_mock: AiohttpClientMocker) -> None:
    """Test the full manual user flow with advanced options."""
    mock_connection(aioclient_mock)

    result = await opp.config_entries.flow.async_init(
        DOMAIN,
        context={
            CONF_SOURCE: SOURCE_USER,
            "show_advanced_options": True
        })

    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "user"

    user_input = {
        **MOCK_USER_INPUT,
        CONF_VERIFY_SSL: True,
    }

    with _patch_async_setup_entry():
        result = await opp.config_entries.flow.async_configure(
            result["flow_id"],
            user_input=user_input,
        )

    assert result["type"] == RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == HOST

    assert result["data"]
    assert result["data"][CONF_HOST] == HOST
    assert result["data"][CONF_VERIFY_SSL]
Exemple #4
0
async def test_full_user_flow_implementation(
        opp: OpenPeerPower, aioclient_mock: AiohttpClientMocker) -> None:
    """Test the full manual user flow from start to finish."""
    mock_connection(aioclient_mock)

    result = await opp.config_entries.flow.async_init(
        DOMAIN,
        context={CONF_SOURCE: SOURCE_USER},
    )

    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "user"

    user_input = MOCK_USER_INPUT.copy()

    with _patch_async_setup_entry():
        result = await opp.config_entries.flow.async_configure(
            result["flow_id"],
            user_input=user_input,
        )

    assert result["type"] == RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == HOST

    assert result["data"]
    assert result["data"][CONF_HOST] == HOST
Exemple #5
0
async def test_import_from_sensor_component(
        hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker) -> None:
    """Test import from sensor platform."""
    mock_connection(aioclient_mock)
    assert await async_setup_component(hass, SENSOR_DOMAIN,
                                       {SENSOR_DOMAIN: MOCK_SENSOR_CONFIG})
    await hass.async_block_till_done()

    entries = hass.config_entries.async_entries(DOMAIN)
    assert len(entries) == 1

    assert entries[0].data[CONF_BASE_PATH] == "/api"
    assert entries[0].options[CONF_UPCOMING_DAYS] == 3

    assert hass.states.get(UPCOMING_ENTITY_ID)
async def test_import_from_sensor_component(
        hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker) -> None:
    """Test import from sensor platform."""
    mock_connection(aioclient_mock)

    with _patch_async_setup(), _patch_async_setup_entry():
        assert await async_setup_component(hass, SENSOR_DOMAIN,
                                           {SENSOR_DOMAIN: MOCK_SENSOR_CONFIG})
        await hass.async_block_till_done()

    entries = hass.config_entries.async_entries(DOMAIN)
    assert len(entries) == 1

    assert entries[0].state == ENTRY_STATE_LOADED
    assert entries[0].data[CONF_BASE_PATH] == "/api"
Exemple #7
0
async def test_availability(
    opp: OpenPeerPower, aioclient_mock: AiohttpClientMocker
) -> None:
    """Test entity availability."""
    now = dt_util.utcnow()

    with patch("openpeerpower.util.dt.utcnow", return_value=now):
        await setup_integration(opp, aioclient_mock)

    assert opp.states.get(UPCOMING_ENTITY_ID).state == "1"

    # state to unavailable
    aioclient_mock.clear_requests()
    mock_connection(aioclient_mock, error=True)

    future = now + timedelta(minutes=1)
    with patch("openpeerpower.util.dt.utcnow", return_value=future):
        async_fire_time_changed(opp, future)
        await opp.async_block_till_done()

    assert opp.states.get(UPCOMING_ENTITY_ID).state == STATE_UNAVAILABLE

    # state to available
    aioclient_mock.clear_requests()
    mock_connection(aioclient_mock)

    future += timedelta(minutes=1)
    with patch("openpeerpower.util.dt.utcnow", return_value=future):
        async_fire_time_changed(opp, future)
        await opp.async_block_till_done()

    assert opp.states.get(UPCOMING_ENTITY_ID).state == "1"

    # state to unavailable
    aioclient_mock.clear_requests()
    mock_connection(aioclient_mock, invalid_auth=True)

    future += timedelta(minutes=1)
    with patch("openpeerpower.util.dt.utcnow", return_value=future):
        async_fire_time_changed(opp, future)
        await opp.async_block_till_done()

    assert opp.states.get(UPCOMING_ENTITY_ID).state == STATE_UNAVAILABLE

    # state to available
    aioclient_mock.clear_requests()
    mock_connection(aioclient_mock)

    future += timedelta(minutes=1)
    with patch("openpeerpower.util.dt.utcnow", return_value=future):
        async_fire_time_changed(opp, future)
        await opp.async_block_till_done()

    assert opp.states.get(UPCOMING_ENTITY_ID).state == "1"
async def test_full_import_flow_implementation(
        hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker) -> None:
    """Test the full manual user flow from start to finish."""
    mock_connection(aioclient_mock)

    user_input = MOCK_USER_INPUT.copy()

    with _patch_async_setup(), _patch_async_setup_entry():
        result = await hass.config_entries.flow.async_init(
            DOMAIN,
            context={CONF_SOURCE: SOURCE_IMPORT},
            data=user_input,
        )

    assert result["type"] == RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == HOST

    assert result["data"]
    assert result["data"][CONF_HOST] == HOST
Exemple #9
0
async def test_full_import_flow_implementation(
    hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
    """Test the full manual user flow from start to finish."""
    mock_connection(aioclient_mock)

    user_input = MOCK_USER_INPUT.copy()

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=user_input,
    )

    assert result["type"] == RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == HOST

    assert result["data"]
    assert result["data"][CONF_HOST] == HOST

    assert result["result"]
    assert result["result"].options[CONF_UPCOMING_DAYS] == DEFAULT_UPCOMING_DAYS
    assert result["result"].options[CONF_WANTED_MAX_ITEMS] == DEFAULT_WANTED_MAX_ITEMS