Move HomeAssistantView to separate file. Convert http to async syntax. [skip ci] (#12982)

* Move HomeAssistantView to separate file. Convert http to async syntax.

* pylint

* websocket api

* update emulated_hue for async/await

* Lint
This commit is contained in:
Boyi C 2018-03-09 09:51:49 +08:00 committed by Paulus Schoutsen
parent 2ee73ca911
commit 321eb2ec6f
17 changed files with 292 additions and 344 deletions

View file

@ -1,6 +1,4 @@
"""The tests for the Home Assistant HTTP component."""
import asyncio
from homeassistant.setup import async_setup_component
import homeassistant.components.http as http
@ -12,16 +10,14 @@ class TestView(http.HomeAssistantView):
name = 'test'
url = '/hello'
@asyncio.coroutine
def get(self, request):
async def get(self, request):
"""Return a get request."""
return 'hello'
@asyncio.coroutine
def test_registering_view_while_running(hass, test_client, unused_port):
async def test_registering_view_while_running(hass, test_client, unused_port):
"""Test that we can register a view while the server is running."""
yield from async_setup_component(
await async_setup_component(
hass, http.DOMAIN, {
http.DOMAIN: {
http.CONF_SERVER_PORT: unused_port(),
@ -29,15 +25,14 @@ def test_registering_view_while_running(hass, test_client, unused_port):
}
)
yield from hass.async_start()
await hass.async_start()
# This raises a RuntimeError if app is frozen
hass.http.register_view(TestView)
@asyncio.coroutine
def test_api_base_url_with_domain(hass):
async def test_api_base_url_with_domain(hass):
"""Test setting API URL."""
result = yield from async_setup_component(hass, 'http', {
result = await async_setup_component(hass, 'http', {
'http': {
'base_url': 'example.com'
}
@ -46,10 +41,9 @@ def test_api_base_url_with_domain(hass):
assert hass.config.api.base_url == 'http://example.com'
@asyncio.coroutine
def test_api_base_url_with_ip(hass):
async def test_api_base_url_with_ip(hass):
"""Test setting api url."""
result = yield from async_setup_component(hass, 'http', {
result = await async_setup_component(hass, 'http', {
'http': {
'server_host': '1.1.1.1'
}
@ -58,10 +52,9 @@ def test_api_base_url_with_ip(hass):
assert hass.config.api.base_url == 'http://1.1.1.1:8123'
@asyncio.coroutine
def test_api_base_url_with_ip_port(hass):
async def test_api_base_url_with_ip_port(hass):
"""Test setting api url."""
result = yield from async_setup_component(hass, 'http', {
result = await async_setup_component(hass, 'http', {
'http': {
'base_url': '1.1.1.1:8124'
}
@ -70,10 +63,9 @@ def test_api_base_url_with_ip_port(hass):
assert hass.config.api.base_url == 'http://1.1.1.1:8124'
@asyncio.coroutine
def test_api_no_base_url(hass):
async def test_api_no_base_url(hass):
"""Test setting api url."""
result = yield from async_setup_component(hass, 'http', {
result = await async_setup_component(hass, 'http', {
'http': {
}
})
@ -81,10 +73,9 @@ def test_api_no_base_url(hass):
assert hass.config.api.base_url == 'http://127.0.0.1:8123'
@asyncio.coroutine
def test_not_log_password(hass, unused_port, test_client, caplog):
async def test_not_log_password(hass, unused_port, test_client, caplog):
"""Test access with password doesn't get logged."""
result = yield from async_setup_component(hass, 'api', {
result = await async_setup_component(hass, 'api', {
'http': {
http.CONF_SERVER_PORT: unused_port(),
http.CONF_API_PASSWORD: 'some-pass'
@ -92,9 +83,9 @@ def test_not_log_password(hass, unused_port, test_client, caplog):
})
assert result
client = yield from test_client(hass.http.app)
client = await test_client(hass.http.app)
resp = yield from client.get('/api/', params={
resp = await client.get('/api/', params={
'api_password': 'some-pass'
})