예제 #1
0
async def test_import_create(hass):
    """Test configuration from YAML."""
    flow = config_flow.SomaFlowHandler()
    flow.hass = hass
    with patch.object(SomaApi, "list_devices", return_value={"result": "success"}):
        result = await flow.async_step_import({"host": MOCK_HOST, "port": MOCK_PORT})
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
예제 #2
0
async def test_full_flow(hass):
    """Check classic use case."""
    hass.data[DOMAIN] = {}
    flow = config_flow.SomaFlowHandler()
    flow.hass = hass
    with patch.object(SomaApi, "list_devices", return_value={"result": "success"}):
        result = await flow.async_step_user({"host": MOCK_HOST, "port": MOCK_PORT})
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
예제 #3
0
async def test_exception(hass):
    """Test if RequestException fires when no connection can be made."""
    flow = config_flow.SomaFlowHandler()
    flow.hass = hass
    with patch.object(SomaApi, "list_devices", side_effect=RequestException()):
        result = await flow.async_step_import({"host": MOCK_HOST, "port": MOCK_PORT})
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == "connection_error"
예제 #4
0
async def test_key_error(hass):
    """Test Connect returning empty string."""
    flow = config_flow.SomaFlowHandler()
    flow.hass = hass
    with patch.object(SomaApi, "list_devices", return_value={}):
        result = await flow.async_step_import({"host": MOCK_HOST, "port": MOCK_PORT})
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == "connection_error"
예제 #5
0
async def test_error_status(hass):
    """Test Connect successfully returning error status."""
    flow = config_flow.SomaFlowHandler()
    flow.hass = hass
    with patch.object(SomaApi, "list_devices", return_value={"result": "error"}):
        result = await flow.async_step_import({"host": MOCK_HOST, "port": MOCK_PORT})
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == "result_error"
예제 #6
0
async def test_import_abort(hass):
    """Test configuration from YAML aborting with existing entity."""
    flow = config_flow.SomaFlowHandler()
    flow.hass = hass
    MockConfigEntry(domain=DOMAIN).add_to_hass(hass)
    result = await flow.async_step_import()
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == "already_setup"
예제 #7
0
async def test_form(hass):
    """Test user form showing."""
    flow = config_flow.SomaFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user()
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM