Add websocket call for adding item to shopping-list (#18623)
This commit is contained in:
1 parent
1364114dc1
commit
2ba521caf8
2 files changed
+56
-2
No files matched your search
@@ -228,7 +228,7 @@ def test_api_clear_completed(hass, aiohttp_client):
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_api_create(hass, aiohttp_client):
|
||||
def test_deprecated_api_create(hass, aiohttp_client):
|
||||
"""Test the API."""
|
||||
yield from async_setup_component(hass, 'shopping_list', {})
|
||||
|
||||
@@ -249,7 +249,7 @@ def test_api_create(hass, aiohttp_client):
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_api_create_fail(hass, aiohttp_client):
|
||||
def test_deprecated_api_create_fail(hass, aiohttp_client):
|
||||
"""Test the API."""
|
||||
yield from async_setup_component(hass, 'shopping_list', {})
|
||||
|
||||
@@ -260,3 +260,37 @@ def test_api_create_fail(hass, aiohttp_client):
|
||||
|
||||
assert resp.status == 400
|
||||
assert len(hass.data['shopping_list'].items) == 0
|
||||
|
||||
|
||||
async def test_ws_add_item(hass, hass_ws_client):
|
||||
"""Test adding shopping_list item websocket command."""
|
||||
await async_setup_component(hass, 'shopping_list', {})
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'shopping_list/items/add',
|
||||
'name': 'soda',
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
assert msg['success'] is True
|
||||
data = msg['result']
|
||||
assert data['name'] == 'soda'
|
||||
assert data['complete'] is False
|
||||
items = hass.data['shopping_list'].items
|
||||
assert len(items) == 1
|
||||
assert items[0]['name'] == 'soda'
|
||||
assert items[0]['complete'] is False
|
||||
|
||||
|
||||
async def test_ws_add_item_fail(hass, hass_ws_client):
|
||||
"""Test adding shopping_list item failure websocket command."""
|
||||
await async_setup_component(hass, 'shopping_list', {})
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'shopping_list/items/add',
|
||||
'name': 123,
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
assert msg['success'] is False
|
||||
assert len(hass.data['shopping_list'].items) == 0
|
||||
Reference in new issue
Block a user