Add config_flow to shopping_list (#32388)
* Add config_flow to shopping_list
* Fix pylint unused import error
* Use _abort_if_unique_id_configured
* Remove SHOPPING_LIST const
* Use const.py for DOMAIN and CONF_TYPE
* Fix tests
* Remove unchanged variable _errors
* Revert CONF_TYPE (wrong usage)
* Use consts in test
* Remove import check
* Remove data={}
* Remove parameters and default values
* Re-add data={}, because it's needed
* Unique ID checks and reverts for default parameters
* remove pylint comment
* Remove block till done
* Address change requests
* Update homeassistant/components/shopping_list/strings.json
Co-Authored-By: Quentame <polletquentin74@me.com>
* Update homeassistant/components/shopping_list/strings.json
Co-Authored-By: Quentame <polletquentin74@me.com>
* Update tests/components/shopping_list/test_config_flow.py
Co-Authored-By: Quentame <polletquentin74@me.com>
* Update tests/components/shopping_list/test_config_flow.py
Co-Authored-By: Quentame <polletquentin74@me.com>
* Update tests/components/shopping_list/test_config_flow.py
Co-Authored-By: Quentame <polletquentin74@me.com>
* Update tests/components/shopping_list/test_config_flow.py
Co-Authored-By: Quentame <polletquentin74@me.com>
* Only test config_flow
* Generate translations
* Move data to end
* @asyncio.coroutine --> async def, yield from --> await
* @asyncio.coroutine --> async def, yield from --> await (tests)
* Remove init in config flow
* remove if not hass.config_entries.async_entries(DOMAIN)
* Add DOMAIN not in config
* Fix tests
* Update homeassistant/components/shopping_list/config_flow.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Fix tests
* Update homeassistant/components/shopping_list/__init__.py
Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Quentame <polletquentin74@me.com>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
10 files changed
+163
-65
No files matched your search
@@ -1,10 +1,10 @@
|
||||
"""Shopping list test helpers."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.shopping_list import intent as sl_intent
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -19,5 +19,10 @@ def mock_shopping_list_io():
|
||||
@pytest.fixture
|
||||
async def sl_setup(hass):
|
||||
"""Set up the shopping list."""
|
||||
assert await async_setup_component(hass, "shopping_list", {})
|
||||
|
||||
entry = MockConfigEntry(domain="shopping_list")
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
await sl_intent.async_setup_intents(hass)
|
||||
@@ -0,0 +1,36 @@
|
||||
"""Test config flow."""
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.shopping_list.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
|
||||
|
||||
async def test_import(hass):
|
||||
"""Test entry will be imported."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data={}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
|
||||
async def test_user(hass):
|
||||
"""Test we can start a config flow."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
|
||||
async def test_user_confirm(hass):
|
||||
"""Test we can finish a config flow."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data={}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["result"].data == {}
|
||||
@@ -1,36 +1,33 @@
|
||||
"""Test shopping list component."""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.websocket_api.const import TYPE_RESULT
|
||||
from homeassistant.helpers import intent
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_add_item(hass, sl_setup):
|
||||
async def test_add_item(hass, sl_setup):
|
||||
"""Test adding an item intent."""
|
||||
|
||||
response = yield from intent.async_handle(
|
||||
response = await intent.async_handle(
|
||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "beer"}}
|
||||
)
|
||||
|
||||
assert response.speech["plain"]["speech"] == "I've added beer to your shopping list"
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_recent_items_intent(hass, sl_setup):
|
||||
async def test_recent_items_intent(hass, sl_setup):
|
||||
"""Test recent items."""
|
||||
|
||||
yield from intent.async_handle(
|
||||
await intent.async_handle(
|
||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "beer"}}
|
||||
)
|
||||
yield from intent.async_handle(
|
||||
await intent.async_handle(
|
||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "wine"}}
|
||||
)
|
||||
yield from intent.async_handle(
|
||||
await intent.async_handle(
|
||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "soda"}}
|
||||
)
|
||||
|
||||
response = yield from intent.async_handle(hass, "test", "HassShoppingListLastItems")
|
||||
response = await intent.async_handle(hass, "test", "HassShoppingListLastItems")
|
||||
|
||||
assert (
|
||||
response.speech["plain"]["speech"]
|
||||
@@ -38,22 +35,21 @@ def test_recent_items_intent(hass, sl_setup):
|
||||
)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_deprecated_api_get_all(hass, hass_client, sl_setup):
|
||||
async def test_deprecated_api_get_all(hass, hass_client, sl_setup):
|
||||
"""Test the API."""
|
||||
|
||||
yield from intent.async_handle(
|
||||
await intent.async_handle(
|
||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "beer"}}
|
||||
)
|
||||
yield from intent.async_handle(
|
||||
await intent.async_handle(
|
||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "wine"}}
|
||||
)
|
||||
|
||||
client = yield from hass_client()
|
||||
resp = yield from client.get("/api/shopping_list")
|
||||
client = await hass_client()
|
||||
resp = await client.get("/api/shopping_list")
|
||||
|
||||
assert resp.status == 200
|
||||
data = yield from resp.json()
|
||||
data = await resp.json()
|
||||
assert len(data) == 2
|
||||
assert data[0]["name"] == "beer"
|
||||
assert not data[0]["complete"]
|
||||
@@ -88,35 +84,34 @@ async def test_ws_get_items(hass, hass_ws_client, sl_setup):
|
||||
assert not data[1]["complete"]
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_deprecated_api_update(hass, hass_client, sl_setup):
|
||||
async def test_deprecated_api_update(hass, hass_client, sl_setup):
|
||||
"""Test the API."""
|
||||
|
||||
yield from intent.async_handle(
|
||||
await intent.async_handle(
|
||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "beer"}}
|
||||
)
|
||||
yield from intent.async_handle(
|
||||
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 = yield from hass_client()
|
||||
resp = yield from client.post(
|
||||
client = await hass_client()
|
||||
resp = await client.post(
|
||||
"/api/shopping_list/item/{}".format(beer_id), json={"name": "soda"}
|
||||
)
|
||||
|
||||
assert resp.status == 200
|
||||
data = yield from resp.json()
|
||||
data = await resp.json()
|
||||
assert data == {"id": beer_id, "name": "soda", "complete": False}
|
||||
|
||||
resp = yield from client.post(
|
||||
resp = await client.post(
|
||||
"/api/shopping_list/item/{}".format(wine_id), json={"complete": True}
|
||||
)
|
||||
|
||||
assert resp.status == 200
|
||||
data = yield from resp.json()
|
||||
data = await resp.json()
|
||||
assert data == {"id": wine_id, "name": "wine", "complete": True}
|
||||
|
||||
beer, wine = hass.data["shopping_list"].items
|
||||
@@ -166,23 +161,20 @@ async def test_ws_update_item(hass, hass_ws_client, sl_setup):
|
||||
assert wine == {"id": wine_id, "name": "wine", "complete": True}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_api_update_fails(hass, hass_client, sl_setup):
|
||||
async def test_api_update_fails(hass, hass_client, sl_setup):
|
||||
"""Test the API."""
|
||||
|
||||
yield from intent.async_handle(
|
||||
await intent.async_handle(
|
||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "beer"}}
|
||||
)
|
||||
|
||||
client = yield from hass_client()
|
||||
resp = yield from client.post(
|
||||
"/api/shopping_list/non_existing", json={"name": "soda"}
|
||||
)
|
||||
client = await hass_client()
|
||||
resp = await client.post("/api/shopping_list/non_existing", json={"name": "soda"})
|
||||
|
||||
assert resp.status == 404
|
||||
|
||||
beer_id = hass.data["shopping_list"].items[0]["id"]
|
||||
resp = yield from client.post(
|
||||
resp = await client.post(
|
||||
"/api/shopping_list/item/{}".format(beer_id), json={"name": 123}
|
||||
)
|
||||
|
||||
@@ -212,29 +204,28 @@ async def test_ws_update_item_fail(hass, hass_ws_client, sl_setup):
|
||||
assert msg["success"] is False
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_deprecated_api_clear_completed(hass, hass_client, sl_setup):
|
||||
async def test_deprecated_api_clear_completed(hass, hass_client, sl_setup):
|
||||
"""Test the API."""
|
||||
|
||||
yield from intent.async_handle(
|
||||
await intent.async_handle(
|
||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "beer"}}
|
||||
)
|
||||
yield from intent.async_handle(
|
||||
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 = yield from hass_client()
|
||||
client = await hass_client()
|
||||
|
||||
# Mark beer as completed
|
||||
resp = yield from client.post(
|
||||
resp = await client.post(
|
||||
"/api/shopping_list/item/{}".format(beer_id), json={"complete": True}
|
||||
)
|
||||
assert resp.status == 200
|
||||
|
||||
resp = yield from client.post("/api/shopping_list/clear_completed")
|
||||
resp = await client.post("/api/shopping_list/clear_completed")
|
||||
assert resp.status == 200
|
||||
|
||||
items = hass.data["shopping_list"].items
|
||||
@@ -272,15 +263,14 @@ async def test_ws_clear_items(hass, hass_ws_client, sl_setup):
|
||||
assert items[0] == {"id": wine_id, "name": "wine", "complete": False}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_deprecated_api_create(hass, hass_client, sl_setup):
|
||||
async def test_deprecated_api_create(hass, hass_client, sl_setup):
|
||||
"""Test the API."""
|
||||
|
||||
client = yield from hass_client()
|
||||
resp = yield from client.post("/api/shopping_list/item", json={"name": "soda"})
|
||||
client = await hass_client()
|
||||
resp = await client.post("/api/shopping_list/item", json={"name": "soda"})
|
||||
|
||||
assert resp.status == 200
|
||||
data = yield from resp.json()
|
||||
data = await resp.json()
|
||||
assert data["name"] == "soda"
|
||||
assert data["complete"] is False
|
||||
|
||||
@@ -290,12 +280,11 @@ def test_deprecated_api_create(hass, hass_client, sl_setup):
|
||||
assert items[0]["complete"] is False
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_deprecated_api_create_fail(hass, hass_client, sl_setup):
|
||||
async def test_deprecated_api_create_fail(hass, hass_client, sl_setup):
|
||||
"""Test the API."""
|
||||
|
||||
client = yield from hass_client()
|
||||
resp = yield from client.post("/api/shopping_list/item", json={"name": 1234})
|
||||
client = await hass_client()
|
||||
resp = await client.post("/api/shopping_list/item", json={"name": 1234})
|
||||
|
||||
assert resp.status == 400
|
||||
assert len(hass.data["shopping_list"].items) == 0
|
||||
|
||||
Reference in new issue
Block a user