<commit_before>"""Test the SRP Energy config flow."""
from unittest.mock import patch

from homeassistant import config_entries, data_entry_flow
from homeassistant.components.srp_energy.const import CONF_IS_TOU, SRP_ENERGY_DOMAIN

from . import ENTRY_CONFIG, init_integration


async def test_form(hass):
    """Test user config."""
    # First get the form
    result = await hass.config_entries.flow.async_init(
        SRP_ENERGY_DOMAIN, context={"source": "user"}
    )
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"
    assert result["errors"] == {}

    # Fill submit form data for config entry
    with patch("homeassistant.components.srp_energy.config_flow.SrpEnergyClient"):

        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            user_input=ENTRY_CONFIG,
        )

        assert result["type"] == "create_entry"
        assert result["title"] == "Test"
        assert result["data"][CONF_IS_TOU] is False


async def test_form_invalid_auth(hass):
    """Test user config with invalid auth."""
    result = await hass.config_entries.flow.async_init(
        SRP_ENERGY_DOMAIN, context={"source": "user"}
    )<commit_msg>Fix flaky SRP_Energy test (#45471)<commit_after>"""Test the SRP Energy config flow."""
from unittest.mock import patch

from homeassistant import config_entries, data_entry_flow
from homeassistant.components.srp_energy.const import CONF_IS_TOU, SRP_ENERGY_DOMAIN

from . import ENTRY_CONFIG, init_integration


async def test_form(hass):
    """Test user config."""
    # First get the form
    result = await hass.config_entries.flow.async_init(
        SRP_ENERGY_DOMAIN, context={"source": "user"}
    )
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"
    assert result["errors"] == {}

    # Fill submit form data for config entry
    with patch(
        "homeassistant.components.srp_energy.config_flow.SrpEnergyClient"
    ), patch(
        "homeassistant.components.srp_energy.async_setup", return_value=True
    ) as mock_setup, patch(
        "homeassistant.components.srp_energy.async_setup_entry",
        return_value=True,
    ) as mock_setup_entry:

        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            user_input=ENTRY_CONFIG,
        )

        assert result["type"] == "create_entry"
        assert result["title"] == "Test"
        assert result["data"][CONF_IS_TOU] is False

    assert len(mock_setup.mock_calls) == 1
    assert len(mock_setup_entry.mock_calls) == 1


async def test_form_invalid_auth(hass):
    """Test user config with invalid auth."""
    result = await hass.config_entries.flow.async_init(
        SRP_ENERGY_DOMAIN, context={"source": "user"}
    )
{'fraction_non_alphanumeric': 0.10856538597109623, 'fraction_numerical': 0.0024673951357067326, 'mean_word_length': 3.6677631578947367, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '818133', 'n_tokens_mistral': 893, 'n_tokens_neox': 859, 'n_words': 195}