Allow adding items Picnic shopping cart by searching (#102862)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
adc56b6b67
commit
62473936e2
5 changed files with 204 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue