Clean up Google Assistant (#11375)
* Clean up Google Assistant * Fix tests
This commit is contained in:
parent
fcbf7abdaa
commit
fc8b25a71f
6 changed files with 165 additions and 183 deletions
|
@ -5,43 +5,41 @@ import json
|
|||
|
||||
from aiohttp.hdrs import CONTENT_TYPE, AUTHORIZATION
|
||||
import pytest
|
||||
from tests.common import get_test_instance_port
|
||||
|
||||
from homeassistant import core, const, setup
|
||||
from homeassistant.components import (
|
||||
fan, http, cover, light, switch, climate, async_setup, media_player)
|
||||
fan, cover, light, switch, climate, async_setup, media_player)
|
||||
from homeassistant.components import google_assistant as ga
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from . import DEMO_DEVICES
|
||||
|
||||
API_PASSWORD = "test1234"
|
||||
SERVER_PORT = get_test_instance_port()
|
||||
BASE_API_URL = "http://127.0.0.1:{}".format(SERVER_PORT)
|
||||
|
||||
HA_HEADERS = {
|
||||
const.HTTP_HEADER_HA_AUTH: API_PASSWORD,
|
||||
CONTENT_TYPE: const.CONTENT_TYPE_JSON,
|
||||
}
|
||||
|
||||
AUTHCFG = {
|
||||
'project_id': 'hasstest-1234',
|
||||
'client_id': 'helloworld',
|
||||
'access_token': 'superdoublesecret'
|
||||
}
|
||||
AUTH_HEADER = {AUTHORIZATION: 'Bearer {}'.format(AUTHCFG['access_token'])}
|
||||
PROJECT_ID = 'hasstest-1234'
|
||||
CLIENT_ID = 'helloworld'
|
||||
ACCESS_TOKEN = 'superdoublesecret'
|
||||
AUTH_HEADER = {AUTHORIZATION: 'Bearer {}'.format(ACCESS_TOKEN)}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def assistant_client(loop, hass_fixture, test_client):
|
||||
def assistant_client(loop, hass, test_client):
|
||||
"""Create web client for the Google Assistant API."""
|
||||
hass = hass_fixture
|
||||
web_app = hass.http.app
|
||||
loop.run_until_complete(
|
||||
setup.async_setup_component(hass, 'google_assistant', {
|
||||
'google_assistant': {
|
||||
'project_id': PROJECT_ID,
|
||||
'client_id': CLIENT_ID,
|
||||
'access_token': ACCESS_TOKEN,
|
||||
}
|
||||
}))
|
||||
|
||||
ga.http.GoogleAssistantView(hass, AUTHCFG).register(web_app.router)
|
||||
ga.auth.GoogleAssistantAuthView(hass, AUTHCFG).register(web_app.router)
|
||||
|
||||
return loop.run_until_complete(test_client(web_app))
|
||||
return loop.run_until_complete(test_client(hass.http.app))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -50,13 +48,6 @@ def hass_fixture(loop, hass):
|
|||
# We need to do this to get access to homeassistant/turn_(on,off)
|
||||
loop.run_until_complete(async_setup(hass, {core.DOMAIN: {}}))
|
||||
|
||||
loop.run_until_complete(
|
||||
setup.async_setup_component(hass, http.DOMAIN, {
|
||||
http.DOMAIN: {
|
||||
http.CONF_SERVER_PORT: SERVER_PORT
|
||||
}
|
||||
}))
|
||||
|
||||
loop.run_until_complete(
|
||||
setup.async_setup_component(hass, light.DOMAIN, {
|
||||
'light': [{
|
||||
|
@ -121,20 +112,20 @@ def hass_fixture(loop, hass):
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_auth(hass_fixture, assistant_client):
|
||||
def test_auth(assistant_client):
|
||||
"""Test the auth process."""
|
||||
result = yield from assistant_client.get(
|
||||
ga.const.GOOGLE_ASSISTANT_API_ENDPOINT + '/auth',
|
||||
params={
|
||||
'redirect_uri':
|
||||
'http://testurl/r/{}'.format(AUTHCFG['project_id']),
|
||||
'client_id': AUTHCFG['client_id'],
|
||||
'http://testurl/r/{}'.format(PROJECT_ID),
|
||||
'client_id': CLIENT_ID,
|
||||
'state': 'random1234',
|
||||
},
|
||||
allow_redirects=False)
|
||||
assert result.status == 301
|
||||
loc = result.headers.get('Location')
|
||||
assert AUTHCFG['access_token'] in loc
|
||||
assert ACCESS_TOKEN in loc
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
@ -167,9 +158,6 @@ def test_sync_request(hass_fixture, assistant_client):
|
|||
@asyncio.coroutine
|
||||
def test_query_request(hass_fixture, assistant_client):
|
||||
"""Test a query request."""
|
||||
# hass.states.set("light.bedroom", "on")
|
||||
# hass.states.set("switch.outside", "off")
|
||||
# res = _sync_req()
|
||||
reqid = '5711642932632160984'
|
||||
data = {
|
||||
'requestId':
|
||||
|
@ -301,9 +289,6 @@ def test_query_climate_request_f(hass_fixture, assistant_client):
|
|||
@asyncio.coroutine
|
||||
def test_execute_request(hass_fixture, assistant_client):
|
||||
"""Test a execute request."""
|
||||
# hass.states.set("light.bedroom", "on")
|
||||
# hass.states.set("switch.outside", "off")
|
||||
# res = _sync_req()
|
||||
reqid = '5711642932632160985'
|
||||
data = {
|
||||
'requestId':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue