Пример #1
0
async def test_show_form(hass):
    """Test that the form is served with no input."""
    flow = config_flow.AmbientStationFlowHandler()
    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"] == "user"
async def test_no_devices(hass, mock_aioambient):
    """Test that an account with no associated devices throws an error."""
    conf = {CONF_API_KEY: "12345abcde12345abcde", CONF_APP_KEY: "67890fghij67890fghij"}

    flow = config_flow.AmbientStationFlowHandler()
    flow.hass = hass
    flow.context = {"source": SOURCE_USER}

    result = await flow.async_step_user(user_input=conf)
    assert result["errors"] == {"base": "no_devices"}
async def test_invalid_api_key(hass, mock_aioambient):
    """Test that an invalid API/App Key throws an error."""
    conf = {CONF_API_KEY: "12345abcde12345abcde", CONF_APP_KEY: "67890fghij67890fghij"}

    flow = config_flow.AmbientStationFlowHandler()
    flow.hass = hass
    flow.context = {"source": SOURCE_USER}

    result = await flow.async_step_user(user_input=conf)
    assert result["errors"] == {"base": "invalid_key"}
Пример #4
0
async def test_no_devices(hass, mock_aioambient):
    """Test that an account with no associated devices throws an error."""
    conf = {
        CONF_API_KEY: '12345abcde12345abcde',
        CONF_APP_KEY: '67890fghij67890fghij',
    }

    flow = config_flow.AmbientStationFlowHandler()
    flow.hass = hass

    result = await flow.async_step_user(user_input=conf)
    assert result['errors'] == {'base': 'no_devices'}
Пример #5
0
async def test_invalid_api_key(hass, mock_aioambient):
    """Test that an invalid API/App Key throws an error."""
    conf = {
        CONF_API_KEY: '12345abcde12345abcde',
        CONF_APP_KEY: '67890fghij67890fghij',
    }

    flow = config_flow.AmbientStationFlowHandler()
    flow.hass = hass

    result = await flow.async_step_user(user_input=conf)
    assert result['errors'] == {'base': 'invalid_key'}
Пример #6
0
async def test_duplicate_error(hass):
    """Test that errors are shown when duplicates are added."""
    conf = {
        CONF_API_KEY: "12345abcde12345abcde",
        CONF_APP_KEY: "67890fghij67890fghij"
    }

    MockConfigEntry(domain=DOMAIN, data=conf).add_to_hass(hass)
    flow = config_flow.AmbientStationFlowHandler()
    flow.hass = hass

    result = await flow.async_step_user(user_input=conf)
    assert result["errors"] == {CONF_APP_KEY: "identifier_exists"}
async def test_step_import(hass, mock_aioambient):
    """Test that the import step works."""
    conf = {CONF_API_KEY: "12345abcde12345abcde", CONF_APP_KEY: "67890fghij67890fghij"}

    flow = config_flow.AmbientStationFlowHandler()
    flow.hass = hass
    flow.context = {"source": SOURCE_USER}

    result = await flow.async_step_import(import_config=conf)
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == "67890fghij67"
    assert result["data"] == {
        CONF_API_KEY: "12345abcde12345abcde",
        CONF_APP_KEY: "67890fghij67890fghij",
    }
Пример #8
0
async def test_step_user(hass, mock_aioambient):
    """Test that the user step works."""
    conf = {
        CONF_API_KEY: "12345abcde12345abcde",
        CONF_APP_KEY: "67890fghij67890fghij"
    }

    flow = config_flow.AmbientStationFlowHandler()
    flow.hass = hass

    result = await flow.async_step_user(user_input=conf)
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == "67890fghij67"
    assert result["data"] == {
        CONF_API_KEY: "12345abcde12345abcde",
        CONF_APP_KEY: "67890fghij67890fghij",
    }
Пример #9
0
async def test_step_import(hass, mock_aioambient):
    """Test that the import step works."""
    conf = {
        CONF_API_KEY: '12345abcde12345abcde',
        CONF_APP_KEY: '67890fghij67890fghij',
    }

    flow = config_flow.AmbientStationFlowHandler()
    flow.hass = hass

    result = await flow.async_step_import(import_config=conf)
    assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result['title'] == '67890fghij67'
    assert result['data'] == {
        CONF_API_KEY: '12345abcde12345abcde',
        CONF_APP_KEY: '67890fghij67890fghij',
    }