Allow adding items Picnic shopping cart by searching (#102862)

Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Duco Sebel 2023-11-24 13:06:32 +01:00 committed by GitHub
parent adc56b6b67
commit 62473936e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 204 additions and 12 deletions

View file

@ -1,4 +1,5 @@
"""Conftest for Picnic tests."""
from collections.abc import Awaitable, Callable
import json
from unittest.mock import MagicMock, patch
@ -9,6 +10,9 @@ from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture
from tests.typing import WebSocketGenerator
ENTITY_ID = "todo.mock_title_shopping_cart"
@pytest.fixture
@ -50,3 +54,42 @@ async def init_integration(
await hass.async_block_till_done()
return mock_config_entry
@pytest.fixture
def ws_req_id() -> Callable[[], int]:
"""Fixture for incremental websocket requests."""
id = 0
def next_id() -> int:
nonlocal id
id += 1
return id
return next_id
@pytest.fixture
async def get_items(
hass_ws_client: WebSocketGenerator, ws_req_id: Callable[[], int]
) -> Callable[[], Awaitable[dict[str, str]]]:
"""Fixture to fetch items from the todo websocket."""
async def get() -> list[dict[str, str]]:
# Fetch items using To-do platform
client = await hass_ws_client()
id = ws_req_id()
await client.send_json(
{
"id": id,
"type": "todo/item/list",
"entity_id": ENTITY_ID,
}
)
resp = await client.receive_json()
assert resp.get("id") == id
assert resp.get("success")
return resp.get("result", {}).get("items", [])
return get