mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Migrate config tests from coroutine to async/await (#30366)
This commit is contained in:
parent
4e7b35355d
commit
320dc52bb3
@ -1,6 +1,5 @@
|
|||||||
"""Test config entries API."""
|
"""Test config entries API."""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@ -94,16 +93,15 @@ async def test_get_entries(hass, client):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_remove_entry(hass, client):
|
||||||
def test_remove_entry(hass, client):
|
|
||||||
"""Test removing an entry via the API."""
|
"""Test removing an entry via the API."""
|
||||||
entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED)
|
entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
resp = yield from client.delete(
|
resp = await client.delete(
|
||||||
"/api/config/config_entries/entry/{}".format(entry.entry_id)
|
"/api/config/config_entries/entry/{}".format(entry.entry_id)
|
||||||
)
|
)
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
data = yield from resp.json()
|
data = await resp.json()
|
||||||
assert data == {"require_restart": True}
|
assert data == {"require_restart": True}
|
||||||
assert len(hass.config_entries.async_entries()) == 0
|
assert len(hass.config_entries.async_entries()) == 0
|
||||||
|
|
||||||
@ -120,13 +118,12 @@ async def test_remove_entry_unauth(hass, client, hass_admin_user):
|
|||||||
assert len(hass.config_entries.async_entries()) == 1
|
assert len(hass.config_entries.async_entries()) == 1
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_available_flows(hass, client):
|
||||||
def test_available_flows(hass, client):
|
|
||||||
"""Test querying the available flows."""
|
"""Test querying the available flows."""
|
||||||
with patch.object(config_flows, "FLOWS", ["hello", "world"]):
|
with patch.object(config_flows, "FLOWS", ["hello", "world"]):
|
||||||
resp = yield from client.get("/api/config/config_entries/flow_handlers")
|
resp = await client.get("/api/config/config_entries/flow_handlers")
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
data = yield from resp.json()
|
data = await resp.json()
|
||||||
assert set(data) == set(["hello", "world"])
|
assert set(data) == set(["hello", "world"])
|
||||||
|
|
||||||
|
|
||||||
@ -135,14 +132,12 @@ def test_available_flows(hass, client):
|
|||||||
############################
|
############################
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_initialize_flow(hass, client):
|
||||||
def test_initialize_flow(hass, client):
|
|
||||||
"""Test we can initialize a flow."""
|
"""Test we can initialize a flow."""
|
||||||
mock_entity_platform(hass, "config_flow.test", None)
|
mock_entity_platform(hass, "config_flow.test", None)
|
||||||
|
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
@asyncio.coroutine
|
async def async_step_user(self, user_input=None):
|
||||||
def async_step_user(self, user_input=None):
|
|
||||||
schema = OrderedDict()
|
schema = OrderedDict()
|
||||||
schema[vol.Required("username")] = str
|
schema[vol.Required("username")] = str
|
||||||
schema[vol.Required("password")] = str
|
schema[vol.Required("password")] = str
|
||||||
@ -155,12 +150,12 @@ def test_initialize_flow(hass, client):
|
|||||||
)
|
)
|
||||||
|
|
||||||
with patch.dict(HANDLERS, {"test": TestFlow}):
|
with patch.dict(HANDLERS, {"test": TestFlow}):
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/config_entries/flow", json={"handler": "test"}
|
"/api/config/config_entries/flow", json={"handler": "test"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
data = yield from resp.json()
|
data = await resp.json()
|
||||||
|
|
||||||
data.pop("flow_id")
|
data.pop("flow_id")
|
||||||
|
|
||||||
@ -182,8 +177,7 @@ async def test_initialize_flow_unauth(hass, client, hass_admin_user):
|
|||||||
hass_admin_user.groups = []
|
hass_admin_user.groups = []
|
||||||
|
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
@asyncio.coroutine
|
async def async_step_user(self, user_input=None):
|
||||||
def async_step_user(self, user_input=None):
|
|
||||||
schema = OrderedDict()
|
schema = OrderedDict()
|
||||||
schema[vol.Required("username")] = str
|
schema[vol.Required("username")] = str
|
||||||
schema[vol.Required("password")] = str
|
schema[vol.Required("password")] = str
|
||||||
@ -203,23 +197,21 @@ async def test_initialize_flow_unauth(hass, client, hass_admin_user):
|
|||||||
assert resp.status == 401
|
assert resp.status == 401
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_abort(hass, client):
|
||||||
def test_abort(hass, client):
|
|
||||||
"""Test a flow that aborts."""
|
"""Test a flow that aborts."""
|
||||||
mock_entity_platform(hass, "config_flow.test", None)
|
mock_entity_platform(hass, "config_flow.test", None)
|
||||||
|
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
@asyncio.coroutine
|
async def async_step_user(self, user_input=None):
|
||||||
def async_step_user(self, user_input=None):
|
|
||||||
return self.async_abort(reason="bla")
|
return self.async_abort(reason="bla")
|
||||||
|
|
||||||
with patch.dict(HANDLERS, {"test": TestFlow}):
|
with patch.dict(HANDLERS, {"test": TestFlow}):
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/config_entries/flow", json={"handler": "test"}
|
"/api/config/config_entries/flow", json={"handler": "test"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
data = yield from resp.json()
|
data = await resp.json()
|
||||||
data.pop("flow_id")
|
data.pop("flow_id")
|
||||||
assert data == {
|
assert data == {
|
||||||
"description_placeholders": None,
|
"description_placeholders": None,
|
||||||
@ -229,8 +221,7 @@ def test_abort(hass, client):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_create_account(hass, client):
|
||||||
def test_create_account(hass, client):
|
|
||||||
"""Test a flow that creates an account."""
|
"""Test a flow that creates an account."""
|
||||||
mock_entity_platform(hass, "config_flow.test", None)
|
mock_entity_platform(hass, "config_flow.test", None)
|
||||||
|
|
||||||
@ -239,14 +230,13 @@ def test_create_account(hass, client):
|
|||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_step_user(self, user_input=None):
|
||||||
def async_step_user(self, user_input=None):
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title="Test Entry", data={"secret": "account_token"}
|
title="Test Entry", data={"secret": "account_token"}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch.dict(HANDLERS, {"test": TestFlow}):
|
with patch.dict(HANDLERS, {"test": TestFlow}):
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/config_entries/flow", json={"handler": "test"}
|
"/api/config/config_entries/flow", json={"handler": "test"}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -255,7 +245,7 @@ def test_create_account(hass, client):
|
|||||||
entries = hass.config_entries.async_entries("test")
|
entries = hass.config_entries.async_entries("test")
|
||||||
assert len(entries) == 1
|
assert len(entries) == 1
|
||||||
|
|
||||||
data = yield from resp.json()
|
data = await resp.json()
|
||||||
data.pop("flow_id")
|
data.pop("flow_id")
|
||||||
assert data == {
|
assert data == {
|
||||||
"handler": "test",
|
"handler": "test",
|
||||||
@ -268,8 +258,7 @@ def test_create_account(hass, client):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_two_step_flow(hass, client):
|
||||||
def test_two_step_flow(hass, client):
|
|
||||||
"""Test we can finish a two step flow."""
|
"""Test we can finish a two step flow."""
|
||||||
mock_integration(hass, MockModule("test", async_setup_entry=mock_coro_func(True)))
|
mock_integration(hass, MockModule("test", async_setup_entry=mock_coro_func(True)))
|
||||||
mock_entity_platform(hass, "config_flow.test", None)
|
mock_entity_platform(hass, "config_flow.test", None)
|
||||||
@ -277,24 +266,22 @@ def test_two_step_flow(hass, client):
|
|||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_step_user(self, user_input=None):
|
||||||
def async_step_user(self, user_input=None):
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="account", data_schema=vol.Schema({"user_title": str})
|
step_id="account", data_schema=vol.Schema({"user_title": str})
|
||||||
)
|
)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_step_account(self, user_input=None):
|
||||||
def async_step_account(self, user_input=None):
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input["user_title"], data={"secret": "account_token"}
|
title=user_input["user_title"], data={"secret": "account_token"}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch.dict(HANDLERS, {"test": TestFlow}):
|
with patch.dict(HANDLERS, {"test": TestFlow}):
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/config_entries/flow", json={"handler": "test"}
|
"/api/config/config_entries/flow", json={"handler": "test"}
|
||||||
)
|
)
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
data = yield from resp.json()
|
data = await resp.json()
|
||||||
flow_id = data.pop("flow_id")
|
flow_id = data.pop("flow_id")
|
||||||
assert data == {
|
assert data == {
|
||||||
"type": "form",
|
"type": "form",
|
||||||
@ -306,7 +293,7 @@ def test_two_step_flow(hass, client):
|
|||||||
}
|
}
|
||||||
|
|
||||||
with patch.dict(HANDLERS, {"test": TestFlow}):
|
with patch.dict(HANDLERS, {"test": TestFlow}):
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/config_entries/flow/{}".format(flow_id),
|
"/api/config/config_entries/flow/{}".format(flow_id),
|
||||||
json={"user_title": "user-title"},
|
json={"user_title": "user-title"},
|
||||||
)
|
)
|
||||||
@ -315,7 +302,7 @@ def test_two_step_flow(hass, client):
|
|||||||
entries = hass.config_entries.async_entries("test")
|
entries = hass.config_entries.async_entries("test")
|
||||||
assert len(entries) == 1
|
assert len(entries) == 1
|
||||||
|
|
||||||
data = yield from resp.json()
|
data = await resp.json()
|
||||||
data.pop("flow_id")
|
data.pop("flow_id")
|
||||||
assert data == {
|
assert data == {
|
||||||
"handler": "test",
|
"handler": "test",
|
||||||
@ -336,14 +323,12 @@ async def test_continue_flow_unauth(hass, client, hass_admin_user):
|
|||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_step_user(self, user_input=None):
|
||||||
def async_step_user(self, user_input=None):
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="account", data_schema=vol.Schema({"user_title": str})
|
step_id="account", data_schema=vol.Schema({"user_title": str})
|
||||||
)
|
)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_step_account(self, user_input=None):
|
||||||
def async_step_account(self, user_input=None):
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input["user_title"], data={"secret": "account_token"}
|
title=user_input["user_title"], data={"secret": "account_token"}
|
||||||
)
|
)
|
||||||
@ -415,14 +400,12 @@ async def test_get_progress_index_unauth(hass, hass_ws_client, hass_admin_user):
|
|||||||
assert response["error"]["code"] == "unauthorized"
|
assert response["error"]["code"] == "unauthorized"
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_progress_flow(hass, client):
|
||||||
def test_get_progress_flow(hass, client):
|
|
||||||
"""Test we can query the API for same result as we get from init a flow."""
|
"""Test we can query the API for same result as we get from init a flow."""
|
||||||
mock_entity_platform(hass, "config_flow.test", None)
|
mock_entity_platform(hass, "config_flow.test", None)
|
||||||
|
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
@asyncio.coroutine
|
async def async_step_user(self, user_input=None):
|
||||||
def async_step_user(self, user_input=None):
|
|
||||||
schema = OrderedDict()
|
schema = OrderedDict()
|
||||||
schema[vol.Required("username")] = str
|
schema[vol.Required("username")] = str
|
||||||
schema[vol.Required("password")] = str
|
schema[vol.Required("password")] = str
|
||||||
@ -434,19 +417,19 @@ def test_get_progress_flow(hass, client):
|
|||||||
)
|
)
|
||||||
|
|
||||||
with patch.dict(HANDLERS, {"test": TestFlow}):
|
with patch.dict(HANDLERS, {"test": TestFlow}):
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/config_entries/flow", json={"handler": "test"}
|
"/api/config/config_entries/flow", json={"handler": "test"}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
data = yield from resp.json()
|
data = await resp.json()
|
||||||
|
|
||||||
resp2 = yield from client.get(
|
resp2 = await client.get(
|
||||||
"/api/config/config_entries/flow/{}".format(data["flow_id"])
|
"/api/config/config_entries/flow/{}".format(data["flow_id"])
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp2.status == 200
|
assert resp2.status == 200
|
||||||
data2 = yield from resp2.json()
|
data2 = await resp2.json()
|
||||||
|
|
||||||
assert data == data2
|
assert data == data2
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Test Customize config panel."""
|
"""Test Customize config panel."""
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@ -8,13 +7,12 @@ from homeassistant.components import config
|
|||||||
from homeassistant.config import DATA_CUSTOMIZE
|
from homeassistant.config import DATA_CUSTOMIZE
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_entity(hass, hass_client):
|
||||||
def test_get_entity(hass, hass_client):
|
|
||||||
"""Test getting entity."""
|
"""Test getting entity."""
|
||||||
with patch.object(config, "SECTIONS", ["customize"]):
|
with patch.object(config, "SECTIONS", ["customize"]):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
client = yield from hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
def mock_read(path):
|
def mock_read(path):
|
||||||
"""Mock reading data."""
|
"""Mock reading data."""
|
||||||
@ -22,21 +20,20 @@ def test_get_entity(hass, hass_client):
|
|||||||
|
|
||||||
hass.data[DATA_CUSTOMIZE] = {"hello.beer": {"cold": "beer"}}
|
hass.data[DATA_CUSTOMIZE] = {"hello.beer": {"cold": "beer"}}
|
||||||
with patch("homeassistant.components.config._read", mock_read):
|
with patch("homeassistant.components.config._read", mock_read):
|
||||||
resp = yield from client.get("/api/config/customize/config/hello.beer")
|
resp = await client.get("/api/config/customize/config/hello.beer")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {"local": {"free": "beer"}, "global": {"cold": "beer"}}
|
assert result == {"local": {"free": "beer"}, "global": {"cold": "beer"}}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_entity(hass, hass_client):
|
||||||
def test_update_entity(hass, hass_client):
|
|
||||||
"""Test updating entity."""
|
"""Test updating entity."""
|
||||||
with patch.object(config, "SECTIONS", ["customize"]):
|
with patch.object(config, "SECTIONS", ["customize"]):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
client = yield from hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
orig_data = {
|
orig_data = {
|
||||||
"hello.beer": {"ignored": True},
|
"hello.beer": {"ignored": True},
|
||||||
@ -57,7 +54,7 @@ def test_update_entity(hass, hass_client):
|
|||||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||||
"homeassistant.components.config._write", mock_write
|
"homeassistant.components.config._write", mock_write
|
||||||
):
|
):
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/customize/config/hello.world",
|
"/api/config/customize/config/hello.world",
|
||||||
data=json.dumps(
|
data=json.dumps(
|
||||||
{"name": "Beer", "entities": ["light.top", "light.bottom"]}
|
{"name": "Beer", "entities": ["light.top", "light.bottom"]}
|
||||||
@ -65,7 +62,7 @@ def test_update_entity(hass, hass_client):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
assert result == {"result": "ok"}
|
assert result == {"result": "ok"}
|
||||||
|
|
||||||
state = hass.states.get("hello.world")
|
state = hass.states.get("hello.world")
|
||||||
@ -82,31 +79,27 @@ def test_update_entity(hass, hass_client):
|
|||||||
assert written[0] == orig_data
|
assert written[0] == orig_data
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_entity_invalid_key(hass, hass_client):
|
||||||
def test_update_entity_invalid_key(hass, hass_client):
|
|
||||||
"""Test updating entity."""
|
"""Test updating entity."""
|
||||||
with patch.object(config, "SECTIONS", ["customize"]):
|
with patch.object(config, "SECTIONS", ["customize"]):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
client = yield from hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/customize/config/not_entity", data=json.dumps({"name": "YO"})
|
"/api/config/customize/config/not_entity", data=json.dumps({"name": "YO"})
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 400
|
assert resp.status == 400
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_entity_invalid_json(hass, hass_client):
|
||||||
def test_update_entity_invalid_json(hass, hass_client):
|
|
||||||
"""Test updating entity."""
|
"""Test updating entity."""
|
||||||
with patch.object(config, "SECTIONS", ["customize"]):
|
with patch.object(config, "SECTIONS", ["customize"]):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
client = yield from hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
resp = yield from client.post(
|
resp = await client.post("/api/config/customize/config/hello.beer", data="not json")
|
||||||
"/api/config/customize/config/hello.beer", data="not json"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert resp.status == 400
|
assert resp.status == 400
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Test Group config panel."""
|
"""Test Group config panel."""
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
@ -9,34 +8,32 @@ from homeassistant.components import config
|
|||||||
VIEW_NAME = "api:config:group:config"
|
VIEW_NAME = "api:config:group:config"
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_device_config(hass, hass_client):
|
||||||
def test_get_device_config(hass, hass_client):
|
|
||||||
"""Test getting device config."""
|
"""Test getting device config."""
|
||||||
with patch.object(config, "SECTIONS", ["group"]):
|
with patch.object(config, "SECTIONS", ["group"]):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
client = yield from hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
def mock_read(path):
|
def mock_read(path):
|
||||||
"""Mock reading data."""
|
"""Mock reading data."""
|
||||||
return {"hello.beer": {"free": "beer"}, "other.entity": {"do": "something"}}
|
return {"hello.beer": {"free": "beer"}, "other.entity": {"do": "something"}}
|
||||||
|
|
||||||
with patch("homeassistant.components.config._read", mock_read):
|
with patch("homeassistant.components.config._read", mock_read):
|
||||||
resp = yield from client.get("/api/config/group/config/hello.beer")
|
resp = await client.get("/api/config/group/config/hello.beer")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {"free": "beer"}
|
assert result == {"free": "beer"}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_device_config(hass, hass_client):
|
||||||
def test_update_device_config(hass, hass_client):
|
|
||||||
"""Test updating device config."""
|
"""Test updating device config."""
|
||||||
with patch.object(config, "SECTIONS", ["group"]):
|
with patch.object(config, "SECTIONS", ["group"]):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
client = yield from hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
orig_data = {
|
orig_data = {
|
||||||
"hello.beer": {"ignored": True},
|
"hello.beer": {"ignored": True},
|
||||||
@ -58,7 +55,7 @@ def test_update_device_config(hass, hass_client):
|
|||||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||||
"homeassistant.components.config._write", mock_write
|
"homeassistant.components.config._write", mock_write
|
||||||
), patch.object(hass.services, "async_call", mock_call):
|
), patch.object(hass.services, "async_call", mock_call):
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/group/config/hello_beer",
|
"/api/config/group/config/hello_beer",
|
||||||
data=json.dumps(
|
data=json.dumps(
|
||||||
{"name": "Beer", "entities": ["light.top", "light.bottom"]}
|
{"name": "Beer", "entities": ["light.top", "light.bottom"]}
|
||||||
@ -66,7 +63,7 @@ def test_update_device_config(hass, hass_client):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
assert result == {"result": "ok"}
|
assert result == {"result": "ok"}
|
||||||
|
|
||||||
orig_data["hello_beer"]["name"] = "Beer"
|
orig_data["hello_beer"]["name"] = "Beer"
|
||||||
@ -76,46 +73,41 @@ def test_update_device_config(hass, hass_client):
|
|||||||
mock_call.assert_called_once_with("group", "reload")
|
mock_call.assert_called_once_with("group", "reload")
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_device_config_invalid_key(hass, hass_client):
|
||||||
def test_update_device_config_invalid_key(hass, hass_client):
|
|
||||||
"""Test updating device config."""
|
"""Test updating device config."""
|
||||||
with patch.object(config, "SECTIONS", ["group"]):
|
with patch.object(config, "SECTIONS", ["group"]):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
client = yield from hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/group/config/not a slug", data=json.dumps({"name": "YO"})
|
"/api/config/group/config/not a slug", data=json.dumps({"name": "YO"})
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 400
|
assert resp.status == 400
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_device_config_invalid_data(hass, hass_client):
|
||||||
def test_update_device_config_invalid_data(hass, hass_client):
|
|
||||||
"""Test updating device config."""
|
"""Test updating device config."""
|
||||||
with patch.object(config, "SECTIONS", ["group"]):
|
with patch.object(config, "SECTIONS", ["group"]):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
client = yield from hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/group/config/hello_beer", data=json.dumps({"invalid_option": 2})
|
"/api/config/group/config/hello_beer", data=json.dumps({"invalid_option": 2})
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 400
|
assert resp.status == 400
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_device_config_invalid_json(hass, hass_client):
|
||||||
def test_update_device_config_invalid_json(hass, hass_client):
|
|
||||||
"""Test updating device config."""
|
"""Test updating device config."""
|
||||||
with patch.object(config, "SECTIONS", ["group"]):
|
with patch.object(config, "SECTIONS", ["group"]):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
client = yield from hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
resp = yield from client.post(
|
resp = await client.post("/api/config/group/config/hello_beer", data="not json")
|
||||||
"/api/config/group/config/hello_beer", data="not json"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert resp.status == 400
|
assert resp.status == 400
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Test config init."""
|
"""Test config init."""
|
||||||
import asyncio
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components import config
|
from homeassistant.components import config
|
||||||
@ -9,15 +8,13 @@ from homeassistant.setup import ATTR_COMPONENT, async_setup_component
|
|||||||
from tests.common import mock_component, mock_coro
|
from tests.common import mock_component, mock_coro
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_config_setup(hass, loop):
|
||||||
def test_config_setup(hass, loop):
|
|
||||||
"""Test it sets up hassbian."""
|
"""Test it sets up hassbian."""
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
assert "config" in hass.config.components
|
assert "config" in hass.config.components
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_load_on_demand_already_loaded(hass, aiohttp_client):
|
||||||
def test_load_on_demand_already_loaded(hass, aiohttp_client):
|
|
||||||
"""Test getting suites."""
|
"""Test getting suites."""
|
||||||
mock_component(hass, "zwave")
|
mock_component(hass, "zwave")
|
||||||
|
|
||||||
@ -26,25 +23,24 @@ def test_load_on_demand_already_loaded(hass, aiohttp_client):
|
|||||||
), patch("homeassistant.components.config.zwave.async_setup") as stp:
|
), patch("homeassistant.components.config.zwave.async_setup") as stp:
|
||||||
stp.return_value = mock_coro(True)
|
stp.return_value = mock_coro(True)
|
||||||
|
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert stp.called
|
assert stp.called
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_load_on_demand_on_load(hass, aiohttp_client):
|
||||||
def test_load_on_demand_on_load(hass, aiohttp_client):
|
|
||||||
"""Test getting suites."""
|
"""Test getting suites."""
|
||||||
with patch.object(config, "SECTIONS", []), patch.object(
|
with patch.object(config, "SECTIONS", []), patch.object(
|
||||||
config, "ON_DEMAND", ["zwave"]
|
config, "ON_DEMAND", ["zwave"]
|
||||||
):
|
):
|
||||||
yield from async_setup_component(hass, "config", {})
|
await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
assert "config.zwave" not in hass.config.components
|
assert "config.zwave" not in hass.config.components
|
||||||
|
|
||||||
with patch("homeassistant.components.config.zwave.async_setup") as stp:
|
with patch("homeassistant.components.config.zwave.async_setup") as stp:
|
||||||
stp.return_value = mock_coro(True)
|
stp.return_value = mock_coro(True)
|
||||||
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: "zwave"})
|
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: "zwave"})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert stp.called
|
assert stp.called
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Test Z-Wave config panel."""
|
"""Test Z-Wave config panel."""
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
@ -23,8 +22,7 @@ def client(loop, hass, hass_client):
|
|||||||
return loop.run_until_complete(hass_client())
|
return loop.run_until_complete(hass_client())
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_device_config(client):
|
||||||
def test_get_device_config(client):
|
|
||||||
"""Test getting device config."""
|
"""Test getting device config."""
|
||||||
|
|
||||||
def mock_read(path):
|
def mock_read(path):
|
||||||
@ -32,16 +30,15 @@ def test_get_device_config(client):
|
|||||||
return {"hello.beer": {"free": "beer"}, "other.entity": {"do": "something"}}
|
return {"hello.beer": {"free": "beer"}, "other.entity": {"do": "something"}}
|
||||||
|
|
||||||
with patch("homeassistant.components.config._read", mock_read):
|
with patch("homeassistant.components.config._read", mock_read):
|
||||||
resp = yield from client.get("/api/config/zwave/device_config/hello.beer")
|
resp = await client.get("/api/config/zwave/device_config/hello.beer")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {"free": "beer"}
|
assert result == {"free": "beer"}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_device_config(client):
|
||||||
def test_update_device_config(client):
|
|
||||||
"""Test updating device config."""
|
"""Test updating device config."""
|
||||||
orig_data = {
|
orig_data = {
|
||||||
"hello.beer": {"ignored": True},
|
"hello.beer": {"ignored": True},
|
||||||
@ -61,13 +58,13 @@ def test_update_device_config(client):
|
|||||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||||
"homeassistant.components.config._write", mock_write
|
"homeassistant.components.config._write", mock_write
|
||||||
):
|
):
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/zwave/device_config/hello.beer",
|
"/api/config/zwave/device_config/hello.beer",
|
||||||
data=json.dumps({"polling_intensity": 2}),
|
data=json.dumps({"polling_intensity": 2}),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
assert result == {"result": "ok"}
|
assert result == {"result": "ok"}
|
||||||
|
|
||||||
orig_data["hello.beer"]["polling_intensity"] = 2
|
orig_data["hello.beer"]["polling_intensity"] = 2
|
||||||
@ -75,10 +72,9 @@ def test_update_device_config(client):
|
|||||||
assert written[0] == orig_data
|
assert written[0] == orig_data
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_device_config_invalid_key(client):
|
||||||
def test_update_device_config_invalid_key(client):
|
|
||||||
"""Test updating device config."""
|
"""Test updating device config."""
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/zwave/device_config/invalid_entity",
|
"/api/config/zwave/device_config/invalid_entity",
|
||||||
data=json.dumps({"polling_intensity": 2}),
|
data=json.dumps({"polling_intensity": 2}),
|
||||||
)
|
)
|
||||||
@ -86,10 +82,9 @@ def test_update_device_config_invalid_key(client):
|
|||||||
assert resp.status == 400
|
assert resp.status == 400
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_device_config_invalid_data(client):
|
||||||
def test_update_device_config_invalid_data(client):
|
|
||||||
"""Test updating device config."""
|
"""Test updating device config."""
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/zwave/device_config/hello.beer",
|
"/api/config/zwave/device_config/hello.beer",
|
||||||
data=json.dumps({"invalid_option": 2}),
|
data=json.dumps({"invalid_option": 2}),
|
||||||
)
|
)
|
||||||
@ -97,18 +92,16 @@ def test_update_device_config_invalid_data(client):
|
|||||||
assert resp.status == 400
|
assert resp.status == 400
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_update_device_config_invalid_json(client):
|
||||||
def test_update_device_config_invalid_json(client):
|
|
||||||
"""Test updating device config."""
|
"""Test updating device config."""
|
||||||
resp = yield from client.post(
|
resp = await client.post(
|
||||||
"/api/config/zwave/device_config/hello.beer", data="not json"
|
"/api/config/zwave/device_config/hello.beer", data="not json"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == 400
|
assert resp.status == 400
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_values(hass, client):
|
||||||
def test_get_values(hass, client):
|
|
||||||
"""Test getting values on node."""
|
"""Test getting values on node."""
|
||||||
node = MockNode(node_id=1)
|
node = MockNode(node_id=1)
|
||||||
value = MockValue(
|
value = MockValue(
|
||||||
@ -125,10 +118,10 @@ def test_get_values(hass, client):
|
|||||||
values2 = MockEntityValues(primary=value2)
|
values2 = MockEntityValues(primary=value2)
|
||||||
hass.data[const.DATA_ENTITY_VALUES] = [values, values2]
|
hass.data[const.DATA_ENTITY_VALUES] = [values, values2]
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/values/1")
|
resp = await client.get("/api/zwave/values/1")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {
|
assert result == {
|
||||||
"123456": {
|
"123456": {
|
||||||
@ -140,8 +133,7 @@ def test_get_values(hass, client):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_groups(hass, client):
|
||||||
def test_get_groups(hass, client):
|
|
||||||
"""Test getting groupdata on node."""
|
"""Test getting groupdata on node."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
node = MockNode(node_id=2)
|
node = MockNode(node_id=2)
|
||||||
@ -152,10 +144,10 @@ def test_get_groups(hass, client):
|
|||||||
node.groups = {1: node.groups}
|
node.groups = {1: node.groups}
|
||||||
network.nodes = {2: node}
|
network.nodes = {2: node}
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/groups/2")
|
resp = await client.get("/api/zwave/groups/2")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {
|
assert result == {
|
||||||
"1": {
|
"1": {
|
||||||
@ -167,38 +159,35 @@ def test_get_groups(hass, client):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_groups_nogroups(hass, client):
|
||||||
def test_get_groups_nogroups(hass, client):
|
|
||||||
"""Test getting groupdata on node with no groups."""
|
"""Test getting groupdata on node with no groups."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
node = MockNode(node_id=2)
|
node = MockNode(node_id=2)
|
||||||
|
|
||||||
network.nodes = {2: node}
|
network.nodes = {2: node}
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/groups/2")
|
resp = await client.get("/api/zwave/groups/2")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {}
|
assert result == {}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_groups_nonode(hass, client):
|
||||||
def test_get_groups_nonode(hass, client):
|
|
||||||
"""Test getting groupdata on nonexisting node."""
|
"""Test getting groupdata on nonexisting node."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
network.nodes = {1: 1, 5: 5}
|
network.nodes = {1: 1, 5: 5}
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/groups/2")
|
resp = await client.get("/api/zwave/groups/2")
|
||||||
|
|
||||||
assert resp.status == 404
|
assert resp.status == 404
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {"message": "Node not found"}
|
assert result == {"message": "Node not found"}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_config(hass, client):
|
||||||
def test_get_config(hass, client):
|
|
||||||
"""Test getting config on node."""
|
"""Test getting config on node."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
node = MockNode(node_id=2)
|
node = MockNode(node_id=2)
|
||||||
@ -214,10 +203,10 @@ def test_get_config(hass, client):
|
|||||||
network.nodes = {2: node}
|
network.nodes = {2: node}
|
||||||
node.get_values.return_value = node.values
|
node.get_values.return_value = node.values
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/config/2")
|
resp = await client.get("/api/zwave/config/2")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {
|
assert result == {
|
||||||
"12": {
|
"12": {
|
||||||
@ -232,8 +221,7 @@ def test_get_config(hass, client):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_config_noconfig_node(hass, client):
|
||||||
def test_get_config_noconfig_node(hass, client):
|
|
||||||
"""Test getting config on node without config."""
|
"""Test getting config on node without config."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
node = MockNode(node_id=2)
|
node = MockNode(node_id=2)
|
||||||
@ -241,44 +229,41 @@ def test_get_config_noconfig_node(hass, client):
|
|||||||
network.nodes = {2: node}
|
network.nodes = {2: node}
|
||||||
node.get_values.return_value = node.values
|
node.get_values.return_value = node.values
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/config/2")
|
resp = await client.get("/api/zwave/config/2")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {}
|
assert result == {}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_config_nonode(hass, client):
|
||||||
def test_get_config_nonode(hass, client):
|
|
||||||
"""Test getting config on nonexisting node."""
|
"""Test getting config on nonexisting node."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
network.nodes = {1: 1, 5: 5}
|
network.nodes = {1: 1, 5: 5}
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/config/2")
|
resp = await client.get("/api/zwave/config/2")
|
||||||
|
|
||||||
assert resp.status == 404
|
assert resp.status == 404
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {"message": "Node not found"}
|
assert result == {"message": "Node not found"}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_usercodes_nonode(hass, client):
|
||||||
def test_get_usercodes_nonode(hass, client):
|
|
||||||
"""Test getting usercodes on nonexisting node."""
|
"""Test getting usercodes on nonexisting node."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
network.nodes = {1: 1, 5: 5}
|
network.nodes = {1: 1, 5: 5}
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/usercodes/2")
|
resp = await client.get("/api/zwave/usercodes/2")
|
||||||
|
|
||||||
assert resp.status == 404
|
assert resp.status == 404
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {"message": "Node not found"}
|
assert result == {"message": "Node not found"}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_usercodes(hass, client):
|
||||||
def test_get_usercodes(hass, client):
|
|
||||||
"""Test getting usercodes on node."""
|
"""Test getting usercodes on node."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
node = MockNode(node_id=18, command_classes=[const.COMMAND_CLASS_USER_CODE])
|
node = MockNode(node_id=18, command_classes=[const.COMMAND_CLASS_USER_CODE])
|
||||||
@ -290,16 +275,15 @@ def test_get_usercodes(hass, client):
|
|||||||
network.nodes = {18: node}
|
network.nodes = {18: node}
|
||||||
node.get_values.return_value = node.values
|
node.get_values.return_value = node.values
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/usercodes/18")
|
resp = await client.get("/api/zwave/usercodes/18")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {"0": {"code": "1234", "label": "label", "length": 4}}
|
assert result == {"0": {"code": "1234", "label": "label", "length": 4}}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_usercode_nousercode_node(hass, client):
|
||||||
def test_get_usercode_nousercode_node(hass, client):
|
|
||||||
"""Test getting usercodes on node without usercodes."""
|
"""Test getting usercodes on node without usercodes."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
node = MockNode(node_id=18)
|
node = MockNode(node_id=18)
|
||||||
@ -307,16 +291,15 @@ def test_get_usercode_nousercode_node(hass, client):
|
|||||||
network.nodes = {18: node}
|
network.nodes = {18: node}
|
||||||
node.get_values.return_value = node.values
|
node.get_values.return_value = node.values
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/usercodes/18")
|
resp = await client.get("/api/zwave/usercodes/18")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {}
|
assert result == {}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_usercodes_no_genreuser(hass, client):
|
||||||
def test_get_usercodes_no_genreuser(hass, client):
|
|
||||||
"""Test getting usercodes on node missing genre user."""
|
"""Test getting usercodes on node missing genre user."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
node = MockNode(node_id=18, command_classes=[const.COMMAND_CLASS_USER_CODE])
|
node = MockNode(node_id=18, command_classes=[const.COMMAND_CLASS_USER_CODE])
|
||||||
@ -328,33 +311,31 @@ def test_get_usercodes_no_genreuser(hass, client):
|
|||||||
network.nodes = {18: node}
|
network.nodes = {18: node}
|
||||||
node.get_values.return_value = node.values
|
node.get_values.return_value = node.values
|
||||||
|
|
||||||
resp = yield from client.get("/api/zwave/usercodes/18")
|
resp = await client.get("/api/zwave/usercodes/18")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result == {}
|
assert result == {}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_save_config_no_network(hass, client):
|
||||||
def test_save_config_no_network(hass, client):
|
|
||||||
"""Test saving configuration without network data."""
|
"""Test saving configuration without network data."""
|
||||||
resp = yield from client.post("/api/zwave/saveconfig")
|
resp = await client.post("/api/zwave/saveconfig")
|
||||||
|
|
||||||
assert resp.status == 404
|
assert resp.status == 404
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
assert result == {"message": "No Z-Wave network data found"}
|
assert result == {"message": "No Z-Wave network data found"}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_save_config(hass, client):
|
||||||
def test_save_config(hass, client):
|
|
||||||
"""Test saving configuration."""
|
"""Test saving configuration."""
|
||||||
network = hass.data[DATA_NETWORK] = MagicMock()
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
||||||
|
|
||||||
resp = yield from client.post("/api/zwave/saveconfig")
|
resp = await client.post("/api/zwave/saveconfig")
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
result = yield from resp.json()
|
result = await resp.json()
|
||||||
assert network.write_config.called
|
assert network.write_config.called
|
||||||
assert result == {"message": "Z-Wave configuration saved to file."}
|
assert result == {"message": "Z-Wave configuration saved to file."}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user