2019-06-01 06:01:45 +00:00
|
|
|
"""Tests for mobile_app component."""
|
|
|
|
# pylint: disable=redefined-outer-name,unused-import
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from tests.common import mock_device_registry
|
|
|
|
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from homeassistant.components.mobile_app.const import DOMAIN
|
|
|
|
|
|
|
|
from .const import REGISTER, REGISTER_CLEARTEXT
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def registry(hass):
|
|
|
|
"""Return a configured device registry."""
|
|
|
|
return mock_device_registry(hass)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2019-12-04 06:39:12 +00:00
|
|
|
async def create_registrations(hass, authed_api_client):
|
2019-06-01 06:01:45 +00:00
|
|
|
"""Return two new registrations."""
|
|
|
|
enc_reg = await authed_api_client.post(
|
2019-07-31 19:25:30 +00:00
|
|
|
"/api/mobile_app/registrations", json=REGISTER
|
2019-06-01 06:01:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert enc_reg.status == 201
|
|
|
|
enc_reg_json = await enc_reg.json()
|
|
|
|
|
|
|
|
clear_reg = await authed_api_client.post(
|
2019-07-31 19:25:30 +00:00
|
|
|
"/api/mobile_app/registrations", json=REGISTER_CLEARTEXT
|
2019-06-01 06:01:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert clear_reg.status == 201
|
|
|
|
clear_reg_json = await clear_reg.json()
|
|
|
|
|
2019-12-04 06:39:12 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2019-06-01 06:01:45 +00:00
|
|
|
return (enc_reg_json, clear_reg_json)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
async def webhook_client(hass, aiohttp_client):
|
|
|
|
"""mobile_app mock client."""
|
|
|
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
return await aiohttp_client(hass.http.app)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
async def authed_api_client(hass, hass_client):
|
|
|
|
"""Provide an authenticated client for mobile_app to use."""
|
|
|
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
return await hass_client()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
async def setup_ws(hass):
|
|
|
|
"""Configure the websocket_api component."""
|
2019-07-31 19:25:30 +00:00
|
|
|
assert await async_setup_component(hass, "websocket_api", {})
|
2019-06-01 06:01:45 +00:00
|
|
|
await hass.async_block_till_done()
|