コード例 #1
0
async def test_refresh_token_expired(hass):
    """Test handling Unauthenticated error raised if refresh token expired."""
    cloud = Cloud(hass, MODE_DEV, None, None)

    with patch('homeassistant.components.cloud.auth_api.check_token',
               side_effect=auth_api.Unauthenticated) as mock_check_token, \
            patch.object(hass.components.persistent_notification,
                         'async_create') as mock_create:
        await cloud.iot.connect()

    assert len(mock_check_token.mock_calls) == 1
    assert len(mock_create.mock_calls) == 1
コード例 #2
0
ファイル: test_iot.py プロジェクト: yottatsa/home-assistant
async def test_webhook_msg(hass):
    """Test webhook msg."""
    cloud = Cloud(hass, MODE_DEV, None, None)
    await cloud.prefs.async_initialize()
    await cloud.prefs.async_update(cloudhooks={
        'hello': {
            'webhook_id': 'mock-webhook-id',
            'cloudhook_id': 'mock-cloud-id'
        }
    })

    received = []

    async def handler(hass, webhook_id, request):
        """Handle a webhook."""
        received.append(request)
        return web.json_response({'from': 'handler'})

    hass.components.webhook.async_register(
        'test', 'Test', 'mock-webhook-id', handler)

    response = await iot.async_handle_webhook(hass, cloud, {
        'cloudhook_id': 'mock-cloud-id',
        'body': '{"hello": "world"}',
        'headers': {
            'content-type': 'application/json'
        },
        'method': 'POST',
        'query': None,
    })

    assert response == {
        'status': 200,
        'body': '{"from": "handler"}',
        'headers': {
            'Content-Type': 'application/json'
        }
    }

    assert len(received) == 1
    assert await received[0].json() == {
        'hello': 'world'
    }