Convert shopping-list update to WebSockets (#18713)
* Convert shopping-list update to WebSockets * Update shopping_list.py * Update test_shopping_list.py
This commit is contained in:
1 parent
d290ce3c9e
commit
b5b5bc2de8
2 files changed
+116
-1
No files matched your search
@@ -110,7 +110,7 @@ async def test_ws_get_items(hass, hass_ws_client):
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_api_update(hass, aiohttp_client):
|
||||
def test_deprecated_api_update(hass, aiohttp_client):
|
||||
"""Test the API."""
|
||||
yield from async_setup_component(hass, 'shopping_list', {})
|
||||
|
||||
@@ -164,6 +164,61 @@ def test_api_update(hass, aiohttp_client):
|
||||
}
|
||||
|
||||
|
||||
async def test_ws_update_item(hass, hass_ws_client):
|
||||
"""Test update shopping_list item websocket command."""
|
||||
await async_setup_component(hass, 'shopping_list', {})
|
||||
await intent.async_handle(
|
||||
hass, 'test', 'HassShoppingListAddItem', {'item': {'value': 'beer'}}
|
||||
)
|
||||
await intent.async_handle(
|
||||
hass, 'test', 'HassShoppingListAddItem', {'item': {'value': 'wine'}}
|
||||
)
|
||||
|
||||
beer_id = hass.data['shopping_list'].items[0]['id']
|
||||
wine_id = hass.data['shopping_list'].items[1]['id']
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'shopping_list/items/update',
|
||||
'item_id': beer_id,
|
||||
'name': 'soda'
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
assert msg['success'] is True
|
||||
data = msg['result']
|
||||
assert data == {
|
||||
'id': beer_id,
|
||||
'name': 'soda',
|
||||
'complete': False
|
||||
}
|
||||
await client.send_json({
|
||||
'id': 6,
|
||||
'type': 'shopping_list/items/update',
|
||||
'item_id': wine_id,
|
||||
'complete': True
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
assert msg['success'] is True
|
||||
data = msg['result']
|
||||
assert data == {
|
||||
'id': wine_id,
|
||||
'name': 'wine',
|
||||
'complete': True
|
||||
}
|
||||
|
||||
beer, wine = hass.data['shopping_list'].items
|
||||
assert beer == {
|
||||
'id': beer_id,
|
||||
'name': 'soda',
|
||||
'complete': False
|
||||
}
|
||||
assert wine == {
|
||||
'id': wine_id,
|
||||
'name': 'wine',
|
||||
'complete': True
|
||||
}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_api_update_fails(hass, aiohttp_client):
|
||||
"""Test the API."""
|
||||
@@ -190,6 +245,35 @@ def test_api_update_fails(hass, aiohttp_client):
|
||||
assert resp.status == 400
|
||||
|
||||
|
||||
async def test_ws_update_item_fail(hass, hass_ws_client):
|
||||
"""Test failure of update shopping_list item websocket command."""
|
||||
await async_setup_component(hass, 'shopping_list', {})
|
||||
await intent.async_handle(
|
||||
hass, 'test', 'HassShoppingListAddItem', {'item': {'value': 'beer'}}
|
||||
)
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'shopping_list/items/update',
|
||||
'item_id': 'non_existing',
|
||||
'name': 'soda'
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
assert msg['success'] is False
|
||||
data = msg['error']
|
||||
assert data == {
|
||||
'code': 'item_not_found',
|
||||
'message': 'Item not found'
|
||||
}
|
||||
await client.send_json({
|
||||
'id': 6,
|
||||
'type': 'shopping_list/items/update',
|
||||
'name': 123,
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
assert msg['success'] is False
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_api_clear_completed(hass, aiohttp_client):
|
||||
"""Test the API."""
|
||||
|
||||
Reference in new issue
Block a user