Ejemplo n.º 1
0
async def test_webhook_post(
    hass: HomeAssistant,
    component_factory: ComponentFactory,
    aiohttp_client,
    user_id: int,
    arg_user_id: Any,
    arg_appli: Any,
    expected_code: int,
) -> None:
    """Test webhook callback."""
    person0 = new_profile_config("person0", user_id)

    await component_factory.configure_component(profile_configs=(person0, ))
    await component_factory.setup_profile(person0.user_id)
    data_manager = get_data_manager_by_user_id(hass, user_id)

    client: TestClient = await aiohttp_client(hass.http.app)

    post_data = {}
    if arg_user_id is not None:
        post_data["userid"] = arg_user_id
    if arg_appli is not None:
        post_data["appli"] = arg_appli

    resp = await client.post(urlparse(data_manager.webhook_config.url).path,
                             data=post_data)

    # Wait for remaining tasks to complete.
    await hass.async_block_till_done()

    data = await resp.json()
    resp.close()

    assert data["code"] == expected_code
Ejemplo n.º 2
0
async def test_webhook_head(
    hass: HomeAssistant, component_factory: ComponentFactory, aiohttp_client,
) -> None:
    """Test head method on webhook view."""
    person0 = new_profile_config("person0", 0)

    await component_factory.configure_component(profile_configs=(person0,))
    await component_factory.setup_profile(person0.user_id)
    data_manager = get_data_manager_by_user_id(hass, person0.user_id)

    client: TestClient = await aiohttp_client(hass.http.app)
    resp = await client.head(urlparse(data_manager.webhook_config.url).path)
    assert resp.status == 200
Ejemplo n.º 3
0
async def test_webhook_put(
    hass: HomeAssistant, component_factory: ComponentFactory, aiohttp_client,
) -> None:
    """Test webhook callback."""
    person0 = new_profile_config("person0", 0)

    await component_factory.configure_component(profile_configs=(person0,))
    await component_factory.setup_profile(person0.user_id)
    data_manager = get_data_manager_by_user_id(hass, person0.user_id)

    client: TestClient = await aiohttp_client(hass.http.app)
    resp = await client.put(urlparse(data_manager.webhook_config.url).path)

    # Wait for remaining tasks to complete.
    await hass.async_block_till_done()

    assert resp.status == 200
    data = await resp.json()
    assert data
    assert data["code"] == 2