Shopping List: edit name / complete status (#8666)
* Shopping List: edit name / complete status * Change ID to be UUID based
This commit is contained in:
1 parent
931f4d8161
commit
1749859cdf
2 files changed
+154
-8
No files matched your search
@@ -42,7 +42,7 @@ def test_recent_items_intent(hass):
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_api(hass, test_client):
|
||||
def test_api_get_all(hass, test_client):
|
||||
"""Test the API."""
|
||||
yield from async_setup_component(hass, 'shopping_list', {})
|
||||
|
||||
@@ -58,4 +58,90 @@ def test_api(hass, test_client):
|
||||
|
||||
assert resp.status == 200
|
||||
data = yield from resp.json()
|
||||
assert data == ['beer', 'wine']
|
||||
assert len(data) == 2
|
||||
assert data[0]['name'] == 'beer'
|
||||
assert not data[0]['complete']
|
||||
assert data[1]['name'] == 'wine'
|
||||
assert not data[1]['complete']
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_api_update(hass, test_client):
|
||||
"""Test the API."""
|
||||
yield from async_setup_component(hass, 'shopping_list', {})
|
||||
|
||||
yield from intent.async_handle(
|
||||
hass, 'test', 'HassShoppingListAddItem', {'item': {'value': 'beer'}}
|
||||
)
|
||||
yield from 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 = yield from test_client(hass.http.app)
|
||||
resp = yield from client.post(
|
||||
'/api/shopping_list/{}'.format(beer_id), json={
|
||||
'name': 'soda'
|
||||
})
|
||||
|
||||
assert resp.status == 200
|
||||
data = yield from resp.json()
|
||||
assert data == {
|
||||
'id': beer_id,
|
||||
'name': 'soda',
|
||||
'complete': False
|
||||
}
|
||||
|
||||
resp = yield from client.post(
|
||||
'/api/shopping_list/{}'.format(wine_id), json={
|
||||
'complete': True
|
||||
})
|
||||
|
||||
assert resp.status == 200
|
||||
data = yield from resp.json()
|
||||
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, test_client):
|
||||
"""Test the API."""
|
||||
yield from async_setup_component(hass, 'shopping_list', {})
|
||||
|
||||
yield from intent.async_handle(
|
||||
hass, 'test', 'HassShoppingListAddItem', {'item': {'value': 'beer'}}
|
||||
)
|
||||
|
||||
client = yield from test_client(hass.http.app)
|
||||
resp = yield from client.post(
|
||||
'/api/shopping_list/non_existing', json={
|
||||
'name': 'soda'
|
||||
})
|
||||
|
||||
assert resp.status == 404
|
||||
|
||||
beer_id = hass.data['shopping_list'].items[0]['id']
|
||||
client = yield from test_client(hass.http.app)
|
||||
resp = yield from client.post(
|
||||
'/api/shopping_list/{}'.format(beer_id), json={
|
||||
'name': 123,
|
||||
})
|
||||
|
||||
assert resp.status == 400
|
||||
Reference in new issue
Block a user