Files
core/tests/components/websocket_api/conftest.py
T

32 lines
886 B
Python
Raw Normal View History

2018-10-01 11:21:00 +02:00
"""Fixtures for websocket tests."""
import pytest
2018-10-01 16:09:31 +02:00
from homeassistant.components.websocket_api.auth import TYPE_AUTH_REQUIRED
from homeassistant.components.websocket_api.http import URL
from homeassistant.setup import async_setup_component
2018-10-01 11:21:00 +02:00
@pytest.fixture
2020-04-13 18:50:36 -07:00
async def websocket_client(hass, hass_ws_client):
2018-10-01 11:21:00 +02:00
"""Create a websocket client."""
2020-04-13 18:50:36 -07:00
return await hass_ws_client(hass)
2018-10-01 11:21:00 +02:00
@pytest.fixture
2020-04-13 18:50:36 -07:00
async def no_auth_websocket_client(hass, aiohttp_client):
2018-10-01 11:21:00 +02:00
"""Websocket connection that requires authentication."""
2020-04-13 18:50:36 -07:00
assert await async_setup_component(hass, "websocket_api", {})
await hass.async_block_till_done()
2018-10-01 11:21:00 +02:00
2020-04-13 18:50:36 -07:00
client = await aiohttp_client(hass.http.app)
ws = await client.ws_connect(URL)
2018-10-01 11:21:00 +02:00
2020-04-13 18:50:36 -07:00
auth_ok = await ws.receive_json()
2019-07-31 12:25:30 -07:00
assert auth_ok["type"] == TYPE_AUTH_REQUIRED
2018-10-01 11:21:00 +02:00
ws.client = client
2018-10-01 11:21:00 +02:00
yield ws
if not ws.closed:
2020-04-13 18:50:36 -07:00
await ws.close()