Repository: home-assistant/core
File: tests/components/nina/test_config_flow.py (Python)

Code before:
    CONF_MESSAGE_SLOTS,
    CONF_REGIONS,
    CONST_REGION_A_TO_D,
    CONST_REGION_E_TO_H,
    CONST_REGION_I_TO_L,
    CONST_REGION_M_TO_Q,
    CONST_REGION_R_TO_U,
    CONST_REGION_V_TO_Z,
    DOMAIN,
)
from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import entity_registry as er

from . import mocked_request_function
from .const import DUMMY_CONFIG_ENTRY, DUMMY_USER_INPUT

from tests.common import MockConfigEntry, load_fixture

DUMMY_RESPONSE_REGIONS: dict[str, Any] = json.loads(
    load_fixture("sample_regions.json", "nina")
)


def assert_dummy_entry_created(result: dict[str, Any]):
    """Asserts that an entry from DUMMY_USER_INPUT is created."""
    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert result["title"] == "NINA"
    assert result["data"] == DUMMY_USER_INPUT | {
        CONF_REGIONS: {
            "095760000000": "Allersberg, M (Roth - Bayern) + Büchenbach (Roth - Bayern)"
        }
    }
    assert result["version"] == 1
    assert result["minor_version"] == 3


async def test_step_user_connection_error(hass: HomeAssistant) -> None:
    """Test starting a flow by user but no connection."""
    with patch(
        "pynina.baseApi.BaseAPI._makeRequest",
        side_effect=ApiError("Could not connect to Api"),
    ):
        result: dict[str, Any] = await hass.config_entries.flow.async_init(
            DOMAIN, context={"source": SOURCE_USER}
        )

        assert result["type"] is FlowResultType.ABORT
        assert result["reason"] == "no_fetch"


Review comment (suggestion):
```suggestion
def assert_dummy_entry_created(result: dict[str, Any]) -> None:
```

Code after:
    CONF_MESSAGE_SLOTS,
    CONF_REGIONS,
    CONST_REGION_A_TO_D,
    CONST_REGION_E_TO_H,
    CONST_REGION_I_TO_L,
    CONST_REGION_M_TO_Q,
    CONST_REGION_R_TO_U,
    CONST_REGION_V_TO_Z,
    DOMAIN,
)
from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import entity_registry as er

from . import mocked_request_function
from .const import DUMMY_CONFIG_ENTRY, DUMMY_USER_INPUT

from tests.common import MockConfigEntry, load_fixture

DUMMY_RESPONSE_REGIONS: dict[str, Any] = json.loads(
    load_fixture("sample_regions.json", "nina")
)


def assert_dummy_entry_created(result: dict[str, Any]) -> None:
    """Asserts that an entry from DUMMY_USER_INPUT is created."""
    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert result["title"] == "NINA"
    assert result["data"] == DUMMY_USER_INPUT | {
        CONF_REGIONS: {
            "095760000000": "Allersberg, M (Roth - Bayern) + Büchenbach (Roth - Bayern)"
        }
    }
    assert result["version"] == 1
    assert result["minor_version"] == 3


async def test_step_user_connection_error(hass: HomeAssistant) -> None:
    """Test starting a flow by user but no connection."""
    with patch(
        "pynina.baseApi.BaseAPI._makeRequest",
        side_effect=ApiError("Could not connect to Api"),
    ):
        result: dict[str, Any] = await hass.config_entries.flow.async_init(
            DOMAIN, context={"source": SOURCE_USER}
        )

        assert result["type"] is FlowResultType.ABORT
        assert result["reason"] == "no_fetch"