Exemple #1
0
async def test_user_connection_bad_key(hass, mock_auth, mock_entry_setup):
    """Test a connection with bad key."""
    mock_auth.side_effect = config_flow.AuthError("invalid_security_code")

    flow = await hass.config_entries.flow.async_init(
        "tradfri", context={"source": "user"}
    )

    result = await hass.config_entries.flow.async_configure(
        flow["flow_id"], {"host": "127.0.0.1", "security_code": "abcd"}
    )

    assert len(mock_entry_setup.mock_calls) == 0

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["errors"] == {"security_code": "invalid_security_code"}
async def test_user_connection_bad_key(hass, mock_auth, mock_entry_setup):
    """Test a connection with bad key."""
    mock_auth.side_effect = config_flow.AuthError('invalid_security_code')

    flow = await hass.config_entries.flow.async_init(
        'tradfri', context={'source': 'user'})

    result = await hass.config_entries.flow.async_configure(
        flow['flow_id'], {
            'host': '127.0.0.1',
            'security_code': 'abcd',
        })

    assert len(mock_entry_setup.mock_calls) == 0

    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['errors'] == {'security_code': 'invalid_security_code'}
Exemple #3
0
async def test_user_connection_timeout(hass, mock_auth, mock_entry_setup):
    """Test a connection timeout."""
    mock_auth.side_effect = config_flow.AuthError("timeout")

    flow = await hass.config_entries.flow.async_init(
        "tradfri", context={"source": config_entries.SOURCE_USER})

    result = await hass.config_entries.flow.async_configure(
        flow["flow_id"], {
            "host": "127.0.0.1",
            "security_code": "abcd"
        })

    assert len(mock_entry_setup.mock_calls) == 0

    assert result["type"] == data_entry_flow.FlowResultType.FORM
    assert result["errors"] == {"base": "timeout"}