2017-11-13 16:32:23 +00:00
|
|
|
"""The tests for google-assistant init."""
|
2019-12-09 19:00:14 +00:00
|
|
|
from homeassistant.components import google_assistant as ga
|
2019-10-03 11:02:38 +00:00
|
|
|
from homeassistant.core import Context
|
2017-11-13 16:32:23 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
2020-02-05 17:50:00 +00:00
|
|
|
from .test_http import DUMMY_CONFIG
|
2017-11-13 16:32:23 +00:00
|
|
|
|
|
|
|
|
2020-01-01 23:24:30 +00:00
|
|
|
async def test_request_sync_service(aioclient_mock, hass):
|
2017-11-13 16:32:23 +00:00
|
|
|
"""Test that it posts to the request_sync url."""
|
2020-02-05 17:50:00 +00:00
|
|
|
aioclient_mock.post(
|
|
|
|
ga.const.HOMEGRAPH_TOKEN_URL,
|
|
|
|
status=200,
|
|
|
|
json={"access_token": "1234", "expires_in": 3600},
|
|
|
|
)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
aioclient_mock.post(ga.const.REQUEST_SYNC_BASE_URL, status=200)
|
2017-11-13 16:32:23 +00:00
|
|
|
|
2020-01-01 23:24:30 +00:00
|
|
|
await async_setup_component(
|
2020-08-27 11:56:20 +00:00
|
|
|
hass,
|
|
|
|
"google_assistant",
|
|
|
|
{"google_assistant": DUMMY_CONFIG},
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2017-11-13 16:32:23 +00:00
|
|
|
|
|
|
|
assert aioclient_mock.call_count == 0
|
2020-01-01 23:24:30 +00:00
|
|
|
await hass.services.async_call(
|
2019-10-03 11:02:38 +00:00
|
|
|
ga.const.DOMAIN,
|
|
|
|
ga.const.SERVICE_REQUEST_SYNC,
|
|
|
|
blocking=True,
|
|
|
|
context=Context(user_id="123"),
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2017-11-13 16:32:23 +00:00
|
|
|
|
2020-02-05 17:50:00 +00:00
|
|
|
assert aioclient_mock.call_count == 2 # token + request
|