Exemple #1
0
async def test_user_flow_minimum_fields(hass: HomeAssistantType,
                                        aioclient_mock):
    """ Test user config flow with minimum fields. """

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_USER})
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"

    es_url = "http://minimum-fields:9200"

    mock_es_initialization(
        aioclient_mock,
        url=es_url,
        mock_health_check=True,
        mock_index_creation=True,
        mock_template_setup=True,
    )

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"], user_input={"url": es_url})

    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == es_url
    assert result["data"]["url"] == es_url
    assert result["data"]["username"] is None
    assert result["data"]["password"] is None
    assert result["data"]["ssl_ca_path"] is None
    assert result["data"]["verify_ssl"] is True
    assert result["data"]["publish_enabled"] is True
    assert result["data"]["health_sensor_enabled"] is True
Exemple #2
0
async def test_complex_setup_component(hass: HomeAssistantType,
                                       aioclient_mock) -> None:
    """Test component setup via legacy yml-based configuration."""
    mock_es_initialization(aioclient_mock,
                           url=MOCK_COMPLEX_LEGACY_CONFIG.get(CONF_URL))

    assert await async_setup_component(
        hass, ELASTIC_DOMAIN, {ELASTIC_DOMAIN: MOCK_COMPLEX_LEGACY_CONFIG})
    await hass.async_block_till_done()
    assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 0

    config_entries = hass.config_entries.async_entries(ELASTIC_DOMAIN)
    assert len(config_entries) == 1

    merged_config = get_merged_config(config_entries[0])

    expected_config = {
        "excluded_domains": ["sensor", "weather"],
        "excluded_entities": ["switch.my_switch"],
        "included_domains": [],
        "included_entities": [],
        "ssl_ca_path": None,
        "publish_mode": "All",
        **MOCK_COMPLEX_LEGACY_CONFIG,
    }

    del expected_config["exclude"]
    del expected_config["only_publish_changed"]

    assert merged_config == expected_config
Exemple #3
0
async def test_options_flow(hass: HomeAssistantType, aioclient_mock,
                            event_loop) -> None:
    """Test options config flow."""

    es_url = "http://localhost:9200"

    mock_es_initialization(
        aioclient_mock,
        url=es_url,
        mock_health_check=True,
        mock_index_creation=True,
        mock_template_setup=True,
        mock_ilm_setup=True,
    )

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_USER}, data={"url": es_url})
    await hass.async_block_till_done()
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    entry = result["result"]

    result = await hass.config_entries.options.async_init(entry.entry_id,
                                                          data=None)

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "publish_options"

    result = await hass.config_entries.options.async_configure(
        result["flow_id"], user_input={})

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "ilm_options"

    result = await hass.config_entries.options.async_configure(
        result["flow_id"], user_input={})

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "health_options"

    result = await hass.config_entries.options.async_configure(
        result["flow_id"], user_input={})

    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
Exemple #4
0
async def test_user_flow_unsupported_version(hass: HomeAssistantType,
                                             aioclient_mock):
    """ Test user config flow with minimum fields. """

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_USER})
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"

    es_url = "http://minimum-fields:9200"

    mock_es_initialization(aioclient_mock,
                           url=es_url,
                           mock_unsupported_version=True)

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"], user_input={"url": es_url})

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"
    assert result["errors"]["base"] == "unsupported_version"
Exemple #5
0
async def test_minimal_setup_component(hass: HomeAssistantType,
                                       aioclient_mock) -> None:
    """Test component setup via legacy yml-based configuration."""
    mock_es_initialization(aioclient_mock,
                           url=MOCK_MINIMAL_LEGACY_CONFIG.get(CONF_URL))

    assert await async_setup_component(
        hass, ELASTIC_DOMAIN, {ELASTIC_DOMAIN: MOCK_MINIMAL_LEGACY_CONFIG})
    await hass.async_block_till_done()
    assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 0

    config_entries = hass.config_entries.async_entries(ELASTIC_DOMAIN)
    assert len(config_entries) == 1

    merged_config = get_merged_config(config_entries[0])

    expected_config = {
        "alias": "active-hass-index",
        "health_sensor_enabled": True,
        "ilm_enabled": True,
        "publish_enabled": True,
        "excluded_domains": [],
        "excluded_entities": [],
        "included_domains": [],
        "included_entities": [],
        "index_format": "hass-events",
        "publish_mode": "All",
        "publish_frequency": 60,
        "timeout": 30,
        "username": None,
        "password": None,
        "verify_ssl": True,
        "ssl_ca_path": None,
        "ilm_delete_after": "365d",
        "ilm_max_size": "30gb",
        "ilm_policy_name": "home-assistant",
        **MOCK_MINIMAL_LEGACY_CONFIG,
    }

    assert merged_config == expected_config