Beispiel #1
0
async def test_abort_if_no_app_configured(hass):
    """Test abort if no app is configured."""
    flow = config_flow.ToonFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user()

    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == "no_app"
Beispiel #2
0
async def test_show_authenticate_form(hass):
    """Test that the authentication form is served."""
    await setup_component(hass)

    flow = config_flow.ToonFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=None)

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "authenticate"
Beispiel #3
0
async def test_toon_abort(hass, mock_toonapilib, side_effect, reason):
    """Test we abort on Toon error."""
    await setup_component(hass)

    flow = config_flow.ToonFlowHandler()
    flow.hass = hass

    mock_toonapilib.side_effect = side_effect

    result = await flow.async_step_authenticate(user_input=FIXTURE_CREDENTIALS)

    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == reason
Beispiel #4
0
async def test_abort_last_minute_fail(hass, mock_toonapilib):
    """Test we abort when API communication fails in the last step."""
    await setup_component(hass)

    flow = config_flow.ToonFlowHandler()
    flow.hass = hass
    await flow.async_step_user(user_input=FIXTURE_CREDENTIALS)

    mock_toonapilib.side_effect = Exception

    result = await flow.async_step_display(user_input=FIXTURE_DISPLAY)
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == "unknown_auth_fail"
Beispiel #5
0
async def test_invalid_credentials(hass, mock_toonapilib):
    """Test we show authentication form on Toon auth error."""
    mock_toonapilib.side_effect = InvalidCredentials

    await setup_component(hass)

    flow = config_flow.ToonFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=FIXTURE_CREDENTIALS)

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "authenticate"
    assert result["errors"] == {"base": "credentials"}
Beispiel #6
0
async def test_no_displays(hass, mock_toonapilib):
    """Test abort when there are no displays."""
    await setup_component(hass)

    mock_toonapilib().display_names = []

    flow = config_flow.ToonFlowHandler()
    flow.hass = hass
    await flow.async_step_user(user_input=FIXTURE_CREDENTIALS)

    result = await flow.async_step_display(user_input=None)

    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == "no_displays"
Beispiel #7
0
async def test_display_already_exists(hass, mock_toonapilib):
    """Test showing display form again if display already exists."""
    await setup_component(hass)

    flow = config_flow.ToonFlowHandler()
    flow.hass = hass
    await flow.async_step_user(user_input=FIXTURE_CREDENTIALS)

    MockConfigEntry(domain=DOMAIN, data=FIXTURE_DISPLAY).add_to_hass(hass)

    result = await flow.async_step_display(user_input=FIXTURE_DISPLAY)

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "display"
    assert result["errors"] == {"base": "display_exists"}
Beispiel #8
0
async def test_full_flow_implementation(hass, mock_toonapilib):
    """Test registering an integration and finishing flow works."""
    await setup_component(hass)

    flow = config_flow.ToonFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=None)
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "authenticate"

    result = await flow.async_step_user(user_input=FIXTURE_CREDENTIALS)
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "display"

    result = await flow.async_step_display(user_input=FIXTURE_DISPLAY)
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == FIXTURE_DISPLAY[CONF_DISPLAY]
    assert result["data"][CONF_USERNAME] == FIXTURE_CREDENTIALS[CONF_USERNAME]
    assert result["data"][CONF_PASSWORD] == FIXTURE_CREDENTIALS[CONF_PASSWORD]
    assert result["data"][CONF_TENANT] == FIXTURE_CREDENTIALS[CONF_TENANT]
    assert result["data"][CONF_DISPLAY] == FIXTURE_DISPLAY[CONF_DISPLAY]