Пример #1
0
async def test_without_config(hass):
    """Test config flow with no configuration."""
    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass
    flow.context = {}

    result = await flow.async_step_user()

    assert result["type"] == "form"
    assert result["step_id"] == "user"
    assert result["errors"] == {}
Пример #2
0
async def test_already_configured(hass, config_entry, config_data):
    """Test config flow when iaqualink component is already setup."""
    config_entry.add_to_hass(hass)

    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass
    flow.context = {}

    result = await flow.async_step_user(config_data)

    assert result["type"] == "abort"
Пример #3
0
async def test_without_config(hass, step):
    """Test config flow with no configuration."""
    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass
    flow.context = {}

    fname = f"async_step_{step}"
    func = getattr(flow, fname)
    result = await func()

    assert result["type"] == "form"
    assert result["step_id"] == "user"
    assert result["errors"] == {}
Пример #4
0
async def test_already_configured(hass, config_entry, config_data, step):
    """Test config flow when iaqualink component is already setup."""
    config_entry.add_to_hass(hass)

    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass
    flow.context = {}

    fname = f"async_step_{step}"
    func = getattr(flow, fname)
    result = await func(config_data)

    assert result["type"] == "abort"
Пример #5
0
async def test_already_configured(hass, step):
    """Test config flow when iaqualink component is already setup."""
    MockConfigEntry(domain="iaqualink", data=DATA).add_to_hass(hass)

    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass
    flow.context = {}

    fname = f"async_step_{step}"
    func = getattr(flow, fname)
    result = await func(DATA)

    assert result["type"] == "abort"
Пример #6
0
async def test_with_existing_config(hass, step):
    """Test with existing configuration."""
    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass
    flow.context = {}

    fname = f"async_step_{step}"
    func = getattr(flow, fname)
    with patch("iaqualink.AqualinkClient.login", return_value=mock_coro(None)):
        result = await func(DATA)

    assert result["type"] == "create_entry"
    assert result["title"] == DATA["username"]
    assert result["data"] == DATA
Пример #7
0
async def test_service_exception(hass, config_data):
    """Test config flow encountering service exception."""
    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass

    with patch(
            "homeassistant.components.iaqualink.config_flow.AqualinkClient.login",
            side_effect=AqualinkServiceException,
    ):
        result = await flow.async_step_user(config_data)

    assert result["type"] == "form"
    assert result["step_id"] == "user"
    assert result["errors"] == {"base": "cannot_connect"}
Пример #8
0
async def test_with_invalid_credentials(hass, config_data):
    """Test config flow with invalid username and/or password."""
    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass

    with patch(
            "homeassistant.components.iaqualink.config_flow.AqualinkClient.login",
            side_effect=AqualinkServiceUnauthorizedException,
    ):
        result = await flow.async_step_user(config_data)

    assert result["type"] == "form"
    assert result["step_id"] == "user"
    assert result["errors"] == {"base": "invalid_auth"}
Пример #9
0
async def test_with_invalid_credentials(hass, step):
    """Test config flow with invalid username and/or password."""
    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass

    fname = f"async_step_{step}"
    func = getattr(flow, fname)
    with patch(
        "iaqualink.AqualinkClient.login", side_effect=iaqualink.AqualinkLoginException
    ):
        result = await func(DATA)

    assert result["type"] == "form"
    assert result["step_id"] == "user"
    assert result["errors"] == {"base": "connection_failure"}
Пример #10
0
async def test_with_existing_config(hass, config_data):
    """Test config flow with existing configuration."""
    flow = config_flow.AqualinkFlowHandler()
    flow.hass = hass
    flow.context = {}

    with patch(
            "homeassistant.components.iaqualink.config_flow.AqualinkClient.login",
            return_value=None,
    ):
        result = await flow.async_step_user(config_data)

    assert result["type"] == "create_entry"
    assert result["title"] == config_data["username"]
    assert result["data"] == config_data