Migrate config tests from coroutine to async/await (#30366)
This commit is contained in:
1 parent
4e7b35355d
commit
320dc52bb3
5 files changed
+133
-188
No files matched your search
@@ -1,5 +1,4 @@
|
||||
"""Test Customize config panel."""
|
||||
import asyncio
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -8,13 +7,12 @@ from homeassistant.components import config
|
||||
from homeassistant.config import DATA_CUSTOMIZE
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_entity(hass, hass_client):
|
||||
async def test_get_entity(hass, hass_client):
|
||||
"""Test getting entity."""
|
||||
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):
|
||||
"""Mock reading data."""
|
||||
@@ -22,21 +20,20 @@ def test_get_entity(hass, hass_client):
|
||||
|
||||
hass.data[DATA_CUSTOMIZE] = {"hello.beer": {"cold": "beer"}}
|
||||
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
|
||||
result = yield from resp.json()
|
||||
result = await resp.json()
|
||||
|
||||
assert result == {"local": {"free": "beer"}, "global": {"cold": "beer"}}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_update_entity(hass, hass_client):
|
||||
async def test_update_entity(hass, hass_client):
|
||||
"""Test updating entity."""
|
||||
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 = {
|
||||
"hello.beer": {"ignored": True},
|
||||
@@ -57,7 +54,7 @@ def test_update_entity(hass, hass_client):
|
||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||
"homeassistant.components.config._write", mock_write
|
||||
):
|
||||
resp = yield from client.post(
|
||||
resp = await client.post(
|
||||
"/api/config/customize/config/hello.world",
|
||||
data=json.dumps(
|
||||
{"name": "Beer", "entities": ["light.top", "light.bottom"]}
|
||||
@@ -65,7 +62,7 @@ def test_update_entity(hass, hass_client):
|
||||
)
|
||||
|
||||
assert resp.status == 200
|
||||
result = yield from resp.json()
|
||||
result = await resp.json()
|
||||
assert result == {"result": "ok"}
|
||||
|
||||
state = hass.states.get("hello.world")
|
||||
@@ -82,31 +79,27 @@ def test_update_entity(hass, hass_client):
|
||||
assert written[0] == orig_data
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_update_entity_invalid_key(hass, hass_client):
|
||||
async def test_update_entity_invalid_key(hass, hass_client):
|
||||
"""Test updating entity."""
|
||||
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"})
|
||||
)
|
||||
|
||||
assert resp.status == 400
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_update_entity_invalid_json(hass, hass_client):
|
||||
async def test_update_entity_invalid_json(hass, hass_client):
|
||||
"""Test updating entity."""
|
||||
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(
|
||||
"/api/config/customize/config/hello.beer", data="not json"
|
||||
)
|
||||
resp = await client.post("/api/config/customize/config/hello.beer", data="not json")
|
||||
|
||||
assert resp.status == 400
|
||||
Reference in new issue
Block a user