Esempio n. 1
0
async def test_full_flow_implementation(hass):
    """Test registering an implementation and finishing flow works."""
    gen_authorize_url = AsyncMock(return_value="https://example.com")
    convert_code = AsyncMock(return_value={"access_token": "yoo"})
    config_flow.register_flow_implementation(hass, "test", "Test",
                                             gen_authorize_url, convert_code)
    config_flow.register_flow_implementation(hass, "test-other", "Test Other",
                                             None, None)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "init"

    result = await flow.async_step_init({"flow_impl": "test"})
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "link"
    assert result["description_placeholders"] == {"url": "https://example.com"}

    result = await flow.async_step_link({"code": "123ABC"})
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result["data"]["tokens"] == {"access_token": "yoo"}
    assert result["data"]["impl_domain"] == "test"
    assert result["title"] == "Nest (via Test)"
Esempio n. 2
0
async def test_full_flow_implementation(hass):
    """Test registering an implementation and finishing flow works."""
    gen_authorize_url = Mock(return_value=mock_coro('https://example.com'))
    convert_code = Mock(return_value=mock_coro({'access_token': 'yoo'}))
    config_flow.register_flow_implementation(hass, 'test', 'Test',
                                             gen_authorize_url, convert_code)
    config_flow.register_flow_implementation(hass, 'test-other', 'Test Other',
                                             None, None)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'init'

    result = await flow.async_step_init({'flow_impl': 'test'})
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'link'
    assert result['description_placeholders'] == {
        'url': 'https://example.com',
    }

    result = await flow.async_step_link({'code': '123ABC'})
    assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result['data']['tokens'] == {'access_token': 'yoo'}
    assert result['data']['impl_domain'] == 'test'
    assert result['title'] == 'Nest (via Test)'
async def test_full_flow_implementation(hass):
    """Test registering an implementation and finishing flow works."""
    gen_authorize_url = Mock(return_value=mock_coro('https://example.com'))
    convert_code = Mock(return_value=mock_coro({'access_token': 'yoo'}))
    config_flow.register_flow_implementation(
        hass, 'test', 'Test', gen_authorize_url, convert_code)
    config_flow.register_flow_implementation(
        hass, 'test-other', 'Test Other', None, None)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'init'

    result = await flow.async_step_init({'flow_impl': 'test'})
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'link'
    assert result['description_placeholders'] == {
        'url': 'https://example.com',
    }

    result = await flow.async_step_link({'code': '123ABC'})
    assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result['data']['tokens'] == {'access_token': 'yoo'}
    assert result['data']['impl_domain'] == 'test'
    assert result['title'] == 'Nest (via Test)'
Esempio n. 4
0
async def test_abort_if_exception_generating_auth_url(hass):
    """Test we abort if generating authorize url blows up."""
    gen_authorize_url = Mock(side_effect=ValueError)
    config_flow.register_flow_implementation(hass, 'test', 'Test',
                                             gen_authorize_url, None)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
    assert result['reason'] == 'authorize_url_fail'
Esempio n. 5
0
async def test_not_pick_implementation_if_only_one(hass):
    """Test we allow picking implementation if we have two."""
    gen_authorize_url = Mock(return_value=mock_coro('https://example.com'))
    config_flow.register_flow_implementation(hass, 'test', 'Test',
                                             gen_authorize_url, None)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'link'
async def test_abort_if_exception_generating_auth_url(hass):
    """Test we abort if generating authorize url blows up."""
    gen_authorize_url = Mock(side_effect=ValueError)
    config_flow.register_flow_implementation(
        hass, 'test', 'Test', gen_authorize_url, None)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
    assert result['reason'] == 'authorize_url_fail'
async def test_not_pick_implementation_if_only_one(hass):
    """Test we allow picking implementation if we have two."""
    gen_authorize_url = Mock(return_value=mock_coro('https://example.com'))
    config_flow.register_flow_implementation(
        hass, 'test', 'Test', gen_authorize_url, None)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'link'
Esempio n. 8
0
async def test_abort_if_timeout_generating_auth_url(hass):
    """Test we abort if generating authorize url fails."""
    gen_authorize_url = Mock(side_effect=asyncio.TimeoutError)
    config_flow.register_flow_implementation(hass, "test", "Test",
                                             gen_authorize_url, None)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == "authorize_url_timeout"
Esempio n. 9
0
async def test_not_pick_implementation_if_only_one(hass):
    """Test we allow picking implementation if we have two."""
    gen_authorize_url = AsyncMock(return_value="https://example.com")
    config_flow.register_flow_implementation(hass, "test", "Test",
                                             gen_authorize_url, None)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "link"
Esempio n. 10
0
async def test_verify_code_exception(hass):
    """Test verify code blows up."""
    gen_authorize_url = Mock(return_value=mock_coro('https://example.com'))
    convert_code = Mock(side_effect=ValueError)
    config_flow.register_flow_implementation(hass, 'test', 'Test',
                                             gen_authorize_url, convert_code)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'link'

    result = await flow.async_step_link({'code': '123ABC'})
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'link'
    assert result['errors'] == {'code': 'internal_error'}
async def test_verify_code_exception(hass):
    """Test verify code blows up."""
    gen_authorize_url = Mock(return_value=mock_coro('https://example.com'))
    convert_code = Mock(side_effect=ValueError)
    config_flow.register_flow_implementation(
        hass, 'test', 'Test', gen_authorize_url, convert_code)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'link'

    result = await flow.async_step_link({'code': '123ABC'})
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'link'
    assert result['errors'] == {'code': 'internal_error'}
Esempio n. 12
0
async def test_verify_code_exception(hass):
    """Test verify code blows up."""
    gen_authorize_url = AsyncMock(return_value="https://example.com")
    convert_code = Mock(side_effect=ValueError)
    config_flow.register_flow_implementation(hass, "test", "Test",
                                             gen_authorize_url, convert_code)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "link"

    result = await flow.async_step_link({"code": "123ABC"})
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "link"
    assert result["errors"] == {"code": "internal_error"}
Esempio n. 13
0
async def test_verify_code_timeout(hass):
    """Test verify code timing out."""
    gen_authorize_url = Mock(return_value=mock_coro("https://example.com"))
    convert_code = Mock(side_effect=asyncio.TimeoutError)
    config_flow.register_flow_implementation(hass, "test", "Test",
                                             gen_authorize_url, convert_code)

    flow = config_flow.NestFlowHandler()
    flow.hass = hass
    result = await flow.async_step_init()
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "link"

    result = await flow.async_step_link({"code": "123ABC"})
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "link"
    assert result["errors"] == {"code": "timeout"}
Esempio n. 14
0
async def test_full_flow_implementation(hass):
    """Test registering an implementation and finishing flow works."""
    assert await async_setup_component(hass, DOMAIN, CONFIG)
    await hass.async_block_till_done()
    # Register an additional implementation to select from during the flow
    config_flow.register_flow_implementation(hass, "test-other", "Test Other",
                                             None, None)

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": config_entries.SOURCE_USER})
    assert result["type"] == data_entry_flow.FlowResultType.FORM
    assert result["step_id"] == "init"

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {"flow_impl": "nest"},
    )
    assert result["type"] == data_entry_flow.FlowResultType.FORM
    assert result["step_id"] == "link"
    assert (result["description_placeholders"].get("url").startswith(
        "https://home.nest.com/login/oauth2?client_id=some-client-id"))

    def mock_login(auth):
        assert auth.pin == "123ABC"
        auth.auth_callback({"access_token": "yoo"})

    with patch(
            "homeassistant.components.nest.legacy.local_auth.NestAuth.login",
            new=mock_login), patch(
                "homeassistant.components.nest.async_setup_legacy_entry",
                return_value=True) as mock_setup:
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"], {"code": "123ABC"})
        await hass.async_block_till_done()
        assert len(mock_setup.mock_calls) == 1
        assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
        assert result["data"]["tokens"] == {"access_token": "yoo"}
        assert result["data"]["impl_domain"] == "nest"
        assert result["title"] == "Nest (via configuration.yaml)"