コード例 #1
0
async def test_import_with_existing_config(hass):
    """Test importing a host with an existing config file."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    bridge = Mock()
    bridge.username = '******'
    bridge.config.bridgeid = 'bridge-id-1234'
    bridge.config.name = 'Mock Bridge'
    bridge.host = '0.0.0.0'

    with patch.object(config_flow, '_find_username_from_config',
                      return_value='mock-user'), \
            patch.object(config_flow, 'get_bridge',
                         return_value=mock_coro(bridge)):
        result = await flow.async_step_import({
            'host': '0.0.0.0',
            'path': 'bla.conf'
        })

    assert result['type'] == 'create_entry'
    assert result['title'] == 'Mock Bridge'
    assert result['data'] == {
        'host': '0.0.0.0',
        'bridge_id': 'bridge-id-1234',
        'username': '******'
    }
コード例 #2
0
async def test_flow_two_bridges_discovered(hass, aioclient_mock):
    """Test config flow discovers two bridges."""
    # Add ignored config entry. Should still show up as option.
    MockConfigEntry(domain="hue",
                    source=config_entries.SOURCE_IGNORE,
                    unique_id="bla").add_to_hass(hass)

    aioclient_mock.get(
        const.API_NUPNP,
        json=[
            {
                "internalipaddress": "1.2.3.4",
                "id": "bla"
            },
            {
                "internalipaddress": "5.6.7.8",
                "id": "beer"
            },
        ],
    )
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_init()
    assert result["type"] == "form"
    assert result["step_id"] == "init"

    with pytest.raises(vol.Invalid):
        assert result["data_schema"]({"id": "not-discovered"})

    result["data_schema"]({"id": "bla"})
    result["data_schema"]({"id": "beer"})
コード例 #3
0
async def test_flow_two_bridges_discovered_one_new(hass, aioclient_mock):
    """Test config flow discovers two bridges."""
    aioclient_mock.get(
        const.API_NUPNP,
        json=[
            {
                "internalipaddress": "1.2.3.4",
                "id": "bla"
            },
            {
                "internalipaddress": "5.6.7.8",
                "id": "beer"
            },
        ],
    )
    MockConfigEntry(domain="hue", unique_id="bla", data={
        "host": "1.2.3.4"
    }).add_to_hass(hass)
    flow = config_flow.HueFlowHandler()
    flow.hass = hass
    flow.context = {}

    result = await flow.async_step_init()
    assert result["type"] == "form"
    assert result["step_id"] == "link"
    assert flow.bridge.host == "5.6.7.8"
コード例 #4
0
async def test_flow_no_discovered_bridges(hass, aioclient_mock):
    """Test config flow discovers no bridges."""
    aioclient_mock.get(const.API_NUPNP, json=[])
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_init()
    assert result['type'] == 'abort'
コード例 #5
0
async def test_bridge_ssdp_discover_other_bridge(hass):
    """Test that discovery ignores other bridges."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_ssdp(
        {'manufacturerURL': 'http://www.notphilips.com'})

    assert result['type'] == 'abort'
コード例 #6
0
async def test_bridge_ssdp_discover_other_bridge(hass):
    """Test that discovery ignores other bridges."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_ssdp(
        {ssdp.ATTR_UPNP_MANUFACTURER_URL: "http://www.notphilips.com"})

    assert result["type"] == "abort"
コード例 #7
0
async def test_import_with_no_config(hass):
    """Test importing a host without an existing config file."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass
    flow.context = {}

    result = await flow.async_step_import({"host": "0.0.0.0"})

    assert result["type"] == "form"
    assert result["step_id"] == "link"
コード例 #8
0
async def test_flow_timeout_discovery(hass):
    """Test config flow ."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    with patch('aiohue.discovery.discover_nupnp',
               side_effect=asyncio.TimeoutError):
        result = await flow.async_step_init()

    assert result['type'] == 'abort'
コード例 #9
0
async def test_flow_link_unknown_host(hass):
    """Test config flow ."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    with patch('aiohue.Bridge.create_user', side_effect=aiohue.RequestError):
        result = await flow.async_step_link({})

    assert result['type'] == 'form'
    assert result['step_id'] == 'link'
    assert result['errors'] == {'base': 'linking'}
コード例 #10
0
async def test_flow_one_bridge_discovered(hass, aioclient_mock):
    """Test config flow discovers one bridge."""
    aioclient_mock.get(
        const.API_NUPNP, json=[{"internalipaddress": "1.2.3.4", "id": "bla"}]
    )
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_init()
    assert result["type"] == "form"
    assert result["step_id"] == "link"
コード例 #11
0
async def test_flow_all_discovered_bridges_exist(hass, aioclient_mock):
    """Test config flow discovers only already configured bridges."""
    aioclient_mock.get(
        const.API_NUPNP, json=[{"internalipaddress": "1.2.3.4", "id": "bla"}]
    )
    MockConfigEntry(domain="hue", data={"host": "1.2.3.4"}).add_to_hass(hass)
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_init()
    assert result["type"] == "abort"
コード例 #12
0
async def test_bridge_homekit_already_configured(hass):
    """Test if a HomeKit discovered bridge has already been configured."""
    MockConfigEntry(domain="hue", data={"host": "0.0.0.0"}).add_to_hass(hass)

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

    result = await flow.async_step_homekit({"host": "0.0.0.0"})

    assert result["type"] == "abort"
コード例 #13
0
async def test_import_cannot_connect(hass):
    """Test importing a host that we cannot conncet to."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass
    flow.context = {}

    with patch.object(config_flow, "get_bridge", side_effect=errors.CannotConnect):
        result = await flow.async_step_import({"host": "0.0.0.0"})

    assert result["type"] == "abort"
    assert result["reason"] == "cannot_connect"
コード例 #14
0
async def test_flow_one_bridge_discovered(hass, aioclient_mock):
    """Test config flow discovers one bridge."""
    aioclient_mock.get(const.API_NUPNP, json=[
        {'internalipaddress': '1.2.3.4', 'id': 'bla'}
    ])
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_init()
    assert result['type'] == 'form'
    assert result['step_id'] == 'link'
コード例 #15
0
async def test_flow_link_button_not_pressed(hass):
    """Test config flow ."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    with patch("aiohue.Bridge.create_user", side_effect=aiohue.LinkButtonNotPressed):
        result = await flow.async_step_link({})

    assert result["type"] == "form"
    assert result["step_id"] == "link"
    assert result["errors"] == {"base": "register_failed"}
コード例 #16
0
async def test_flow_link_unknown_host(hass):
    """Test config flow ."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    with patch("aiohue.Bridge.create_user", side_effect=aiohue.RequestError):
        result = await flow.async_step_link({})

    assert result["type"] == "form"
    assert result["step_id"] == "link"
    assert result["errors"] == {"base": "linking"}
コード例 #17
0
async def test_bridge_discovery_emulated_hue(hass):
    """Test if discovery info is from an emulated hue instance."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_discovery({
        'name': 'HASS Bridge',
        'host': '0.0.0.0',
        'serial': '1234'
    })

    assert result['type'] == 'abort'
コード例 #18
0
async def test_flow_link_button_not_pressed(hass):
    """Test config flow ."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    with patch('aiohue.Bridge.create_user',
               side_effect=aiohue.LinkButtonNotPressed):
        result = await flow.async_step_link({})

    assert result['type'] == 'form'
    assert result['step_id'] == 'link'
    assert result['errors'] == {'base': 'register_failed'}
コード例 #19
0
async def test_flow_link_timeout(hass):
    """Test config flow ."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass
    flow.bridge = Mock()

    with patch("aiohue.Bridge.create_user", side_effect=asyncio.TimeoutError):
        result = await flow.async_step_link({})

    assert result["type"] == "form"
    assert result["step_id"] == "link"
    assert result["errors"] == {"base": "linking"}
コード例 #20
0
async def test_flow_timeout_discovery(hass):
    """Test config flow ."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    with patch(
            "homeassistant.components.hue.config_flow.discover_nupnp",
            side_effect=asyncio.TimeoutError,
    ):
        result = await flow.async_step_init()

    assert result["type"] == "abort"
コード例 #21
0
async def test_flow_all_discovered_bridges_exist(hass, aioclient_mock):
    """Test config flow discovers only already configured bridges."""
    aioclient_mock.get(const.API_NUPNP, json=[
        {'internalipaddress': '1.2.3.4', 'id': 'bla'}
    ])
    MockConfigEntry(domain='hue', data={
        'host': '1.2.3.4'
    }).add_to_hass(hass)
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_init()
    assert result['type'] == 'abort'
コード例 #22
0
async def test_import_with_no_config(hass):
    """Test importing a host without an existing config file."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass
    flow.context = {}

    with patch.object(
        config_flow, "get_bridge", side_effect=errors.AuthenticationRequired
    ):
        result = await flow.async_step_import({"host": "0.0.0.0"})

    assert result["type"] == "form"
    assert result["step_id"] == "link"
コード例 #23
0
async def test_import_cannot_connect(hass):
    """Test importing a host that we cannot conncet to."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    with patch.object(config_flow, 'get_bridge',
                      side_effect=errors.CannotConnect):
        result = await flow.async_step_import({
            'host': '0.0.0.0',
        })

    assert result['type'] == 'abort'
    assert result['reason'] == 'cannot_connect'
コード例 #24
0
async def test_import_with_no_config(hass):
    """Test importing a host without an existing config file."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    with patch.object(config_flow, 'get_bridge',
                      side_effect=errors.AuthenticationRequired):
        result = await flow.async_step_import({
            'host': '0.0.0.0',
        })

    assert result['type'] == 'form'
    assert result['step_id'] == 'link'
コード例 #25
0
async def test_bridge_discovery_already_configured(hass):
    """Test if a discovered bridge has already been configured."""
    MockConfigEntry(domain='hue', data={'host': '0.0.0.0'}).add_to_hass(hass)

    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    result = await flow.async_step_discovery({
        'host': '0.0.0.0',
        'serial': '1234'
    })

    assert result['type'] == 'abort'
コード例 #26
0
async def test_flow_link_button_not_pressed(hass):
    """Test config flow ."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass
    flow.bridge = Mock(
        username=None,
        create_user=Mock(side_effect=aiohue.LinkButtonNotPressed))

    result = await flow.async_step_link({})

    assert result["type"] == "form"
    assert result["step_id"] == "link"
    assert result["errors"] == {"base": "register_failed"}
コード例 #27
0
async def test_bridge_homekit_already_configured(hass):
    """Test if a HomeKit discovered bridge has already been configured."""
    MockConfigEntry(domain='hue', data={'host': '0.0.0.0'}).add_to_hass(hass)

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

    result = await flow.async_step_homekit({
        'host': '0.0.0.0',
    })

    assert result['type'] == 'abort'
コード例 #28
0
async def test_bridge_discovery(hass):
    """Test a bridge being discovered."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass

    with patch.object(config_flow, 'get_bridge',
                      side_effect=errors.AuthenticationRequired):
        result = await flow.async_step_discovery({
            'host': '0.0.0.0',
            'serial': '1234'
        })

    assert result['type'] == 'form'
    assert result['step_id'] == 'link'
コード例 #29
0
async def test_bridge_homekit_already_configured(hass):
    """Test if a HomeKit discovered bridge has already been configured."""
    MockConfigEntry(
        domain="hue", unique_id="aabbccddeeff", data={"host": "0.0.0.0"}
    ).add_to_hass(hass)

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

    with pytest.raises(data_entry_flow.AbortFlow):
        await flow.async_step_homekit(
            {"host": "0.0.0.0", "properties": {"id": "aa:bb:cc:dd:ee:ff"}}
        )
コード例 #30
0
async def test_import_with_existing_but_invalid_config(hass):
    """Test importing a host with a config file with invalid username."""
    flow = config_flow.HueFlowHandler()
    flow.hass = hass
    flow.context = {}

    with patch.object(
        config_flow, "_find_username_from_config", return_value="mock-user"
    ), patch.object(
        config_flow, "get_bridge", side_effect=errors.AuthenticationRequired
    ):
        result = await flow.async_step_import({"host": "0.0.0.0", "path": "bla.conf"})

    assert result["type"] == "form"
    assert result["step_id"] == "link"