Shopping list: add item HTTP API (#10674)

* Shopping list: add item HTTP API

* Fix order of decorators
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2017-11-20 21:44:22 -08:00
1 parent f0fe8cb2fe
commit 6e27e73474
3 files changed
+70 -14

No files matched your search

+39 -2
View File
@@ -9,9 +9,11 @@ from homeassistant.helpers import intent
@pytest.fixture(autouse=True)
def mock_shopping_list_save():
def mock_shopping_list_io():
"""Stub out the persistence."""
with patch('homeassistant.components.shopping_list.ShoppingData.save'):
with patch('homeassistant.components.shopping_list.ShoppingData.save'), \
patch('homeassistant.components.shopping_list.'
'ShoppingData.async_load'):
yield
@@ -192,3 +194,38 @@ def test_api_clear_completed(hass, test_client):
'name': 'wine',
'complete': False
}
@asyncio.coroutine
def test_api_create(hass, test_client):
"""Test the API."""
yield from async_setup_component(hass, 'shopping_list', {})
client = yield from test_client(hass.http.app)
resp = yield from client.post('/api/shopping_list/item', json={
'name': 'soda'
})
assert resp.status == 200
data = yield from resp.json()
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
@asyncio.coroutine
def test_api_create_fail(hass, test_client):
"""Test the API."""
yield from async_setup_component(hass, 'shopping_list', {})
client = yield from test_client(hass.http.app)
resp = yield from client.post('/api/shopping_list/item', json={
'name': 1234
})
assert resp.status == 400
assert len(hass.data['shopping_list'].items) == 0