mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 16:17:20 +00:00
Add ClientSessionGenerator type hints in tests (#118377)
This commit is contained in:
parent
d10362e226
commit
461ac1e0bc
@ -26,7 +26,7 @@ from tests.common import (
|
|||||||
mock_integration,
|
mock_integration,
|
||||||
mock_platform,
|
mock_platform,
|
||||||
)
|
)
|
||||||
from tests.typing import WebSocketGenerator
|
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -43,7 +43,9 @@ def mock_test_component(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def client(hass, hass_client) -> TestClient:
|
async def client(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Fixture that can interact with the config manager API."""
|
"""Fixture that can interact with the config manager API."""
|
||||||
await async_setup_component(hass, "http", {})
|
await async_setup_component(hass, "http", {})
|
||||||
config_entries.async_setup(hass)
|
config_entries.async_setup(hass)
|
||||||
|
@ -13,6 +13,8 @@ from homeassistant.core import HomeAssistant, ServiceCall, callback
|
|||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
SESSION_ID = "a9b84cec-46b6-484e-8f31-f65dba03ae6d"
|
SESSION_ID = "a9b84cec-46b6-484e-8f31-f65dba03ae6d"
|
||||||
INTENT_ID = "c6a74079-a8f0-46cd-b372-5a934d23591c"
|
INTENT_ID = "c6a74079-a8f0-46cd-b372-5a934d23591c"
|
||||||
INTENT_NAME = "tests"
|
INTENT_NAME = "tests"
|
||||||
@ -37,7 +39,7 @@ async def calls(hass: HomeAssistant, fixture) -> list[ServiceCall]:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def fixture(hass, hass_client_no_auth):
|
async def fixture(hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator):
|
||||||
"""Initialize a Home Assistant server for testing this module."""
|
"""Initialize a Home Assistant server for testing this module."""
|
||||||
await async_setup_component(hass, dialogflow.DOMAIN, {"dialogflow": {}})
|
await async_setup_component(hass, dialogflow.DOMAIN, {"dialogflow": {}})
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
@ -8,6 +8,7 @@ import json
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from aiohttp.hdrs import CONTENT_TYPE
|
from aiohttp.hdrs import CONTENT_TYPE
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import const, setup
|
from homeassistant import const, setup
|
||||||
@ -243,7 +244,9 @@ def _mock_hue_endpoints(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def hue_client(hass_hue, hass_client_no_auth):
|
async def hue_client(
|
||||||
|
hass_hue, hass_client_no_auth: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Create web client for emulated hue api."""
|
"""Create web client for emulated hue api."""
|
||||||
_mock_hue_endpoints(
|
_mock_hue_endpoints(
|
||||||
hass_hue,
|
hass_hue,
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
"""The tests for the emulated Hue component."""
|
"""The tests for the emulated Hue component."""
|
||||||
|
|
||||||
from asyncio import AbstractEventLoop
|
from asyncio import AbstractEventLoop
|
||||||
|
from collections.abc import Generator
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import json
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import defusedxml.ElementTree as ET
|
import defusedxml.ElementTree as ET
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -45,7 +47,9 @@ def aiohttp_client(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hue_client(aiohttp_client):
|
def hue_client(
|
||||||
|
aiohttp_client: ClientSessionGenerator,
|
||||||
|
) -> Generator[TestClient, None, None]:
|
||||||
"""Return a hue API client."""
|
"""Return a hue API client."""
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
with unittest.mock.patch(
|
with unittest.mock.patch(
|
||||||
|
@ -16,7 +16,9 @@ from tests.typing import ClientSessionGenerator
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def uploaded_file_dir(hass: HomeAssistant, hass_client) -> Path:
|
async def uploaded_file_dir(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> Path:
|
||||||
"""Test uploading and using a file."""
|
"""Test uploading and using a file."""
|
||||||
assert await async_setup_component(hass, "file_upload", {})
|
assert await async_setup_component(hass, "file_upload", {})
|
||||||
client = await hass_client()
|
client = await hass_client()
|
||||||
|
@ -6,6 +6,7 @@ import re
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -99,13 +100,17 @@ def aiohttp_client(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def mock_http_client(hass, aiohttp_client, frontend):
|
async def mock_http_client(
|
||||||
|
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator, frontend
|
||||||
|
) -> TestClient:
|
||||||
"""Start the Home Assistant HTTP component."""
|
"""Start the Home Assistant HTTP component."""
|
||||||
return await aiohttp_client(hass.http.app)
|
return await aiohttp_client(hass.http.app)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def themes_ws_client(hass, hass_ws_client, frontend_themes):
|
async def themes_ws_client(
|
||||||
|
hass: HomeAssistant, hass_ws_client: ClientSessionGenerator, frontend_themes
|
||||||
|
) -> TestClient:
|
||||||
"""Start the Home Assistant HTTP component."""
|
"""Start the Home Assistant HTTP component."""
|
||||||
return await hass_ws_client(hass)
|
return await hass_ws_client(hass)
|
||||||
|
|
||||||
@ -117,7 +122,9 @@ async def ws_client(hass, hass_ws_client, frontend):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def mock_http_client_with_extra_js(hass, aiohttp_client, ignore_frontend_deps):
|
async def mock_http_client_with_extra_js(
|
||||||
|
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator, ignore_frontend_deps
|
||||||
|
) -> TestClient:
|
||||||
"""Start the Home Assistant HTTP component."""
|
"""Start the Home Assistant HTTP component."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -21,6 +22,8 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
|
|||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
HOME_LATITUDE = 37.239622
|
HOME_LATITUDE = 37.239622
|
||||||
HOME_LONGITUDE = -115.815811
|
HOME_LONGITUDE = -115.815811
|
||||||
|
|
||||||
@ -118,7 +121,9 @@ def mock_dev_track(mock_device_tracker_conf):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def geofency_client(hass, hass_client_no_auth):
|
async def geofency_client(
|
||||||
|
hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Geofency mock client (unauthenticated)."""
|
"""Geofency mock client (unauthenticated)."""
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
@ -90,9 +90,9 @@ async def test_full_flow(
|
|||||||
)
|
)
|
||||||
async def test_reauth(
|
async def test_reauth(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client_no_auth,
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
current_request_with_host,
|
current_request_with_host: None,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
fixture: str,
|
fixture: str,
|
||||||
abort_reason: str,
|
abort_reason: str,
|
||||||
|
@ -19,6 +19,7 @@ from homeassistant.helpers import config_entry_oauth2_flow
|
|||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, load_fixture
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
CLIENT_ID = "1234"
|
CLIENT_ID = "1234"
|
||||||
CLIENT_SECRET = "5678"
|
CLIENT_SECRET = "5678"
|
||||||
@ -43,9 +44,9 @@ def setup_userinfo(user_identifier: str) -> Generator[Mock, None, None]:
|
|||||||
|
|
||||||
async def test_full_flow(
|
async def test_full_flow(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client_no_auth,
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
current_request_with_host,
|
current_request_with_host: None,
|
||||||
setup_credentials,
|
setup_credentials,
|
||||||
setup_userinfo,
|
setup_userinfo,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -98,9 +99,9 @@ async def test_full_flow(
|
|||||||
|
|
||||||
async def test_api_not_enabled(
|
async def test_api_not_enabled(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client_no_auth,
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
current_request_with_host,
|
current_request_with_host: None,
|
||||||
setup_credentials,
|
setup_credentials,
|
||||||
setup_userinfo,
|
setup_userinfo,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -159,9 +160,9 @@ async def test_api_not_enabled(
|
|||||||
|
|
||||||
async def test_general_exception(
|
async def test_general_exception(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client_no_auth,
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
current_request_with_host,
|
current_request_with_host: None,
|
||||||
setup_credentials,
|
setup_credentials,
|
||||||
setup_userinfo,
|
setup_userinfo,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -236,9 +237,9 @@ async def test_general_exception(
|
|||||||
)
|
)
|
||||||
async def test_reauth(
|
async def test_reauth(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client_no_auth,
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
current_request_with_host,
|
current_request_with_host: None,
|
||||||
setup_credentials,
|
setup_credentials,
|
||||||
setup_userinfo,
|
setup_userinfo,
|
||||||
user_identifier: str,
|
user_identifier: str,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -17,6 +18,8 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
|
|||||||
from homeassistant.helpers.dispatcher import DATA_DISPATCHER
|
from homeassistant.helpers.dispatcher import DATA_DISPATCHER
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
HOME_LATITUDE = 37.239622
|
HOME_LATITUDE = 37.239622
|
||||||
HOME_LONGITUDE = -115.815811
|
HOME_LONGITUDE = -115.815811
|
||||||
|
|
||||||
@ -27,7 +30,9 @@ def mock_dev_track(mock_device_tracker_conf):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def gpslogger_client(hass, hass_client_no_auth):
|
async def gpslogger_client(
|
||||||
|
hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Mock client for GPSLogger (unauthenticated)."""
|
"""Mock client for GPSLogger (unauthenticated)."""
|
||||||
|
|
||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||||
|
@ -4,6 +4,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.hassio.handler import HassIO, HassioAPIError
|
from homeassistant.components.hassio.handler import HassIO, HassioAPIError
|
||||||
@ -84,19 +85,25 @@ def hassio_stubs(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hassio_client(hassio_stubs, hass, hass_client):
|
def hassio_client(
|
||||||
|
hassio_stubs, hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Return a Hass.io HTTP client."""
|
"""Return a Hass.io HTTP client."""
|
||||||
return hass.loop.run_until_complete(hass_client())
|
return hass.loop.run_until_complete(hass_client())
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hassio_noauth_client(hassio_stubs, hass, aiohttp_client):
|
def hassio_noauth_client(
|
||||||
|
hassio_stubs, hass: HomeAssistant, aiohttp_client: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Return a Hass.io HTTP client without auth."""
|
"""Return a Hass.io HTTP client without auth."""
|
||||||
return hass.loop.run_until_complete(aiohttp_client(hass.http.app))
|
return hass.loop.run_until_complete(aiohttp_client(hass.http.app))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def hassio_client_supervisor(hass, aiohttp_client, hassio_stubs):
|
async def hassio_client_supervisor(
|
||||||
|
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator, hassio_stubs
|
||||||
|
) -> TestClient:
|
||||||
"""Return an authenticated HTTP client."""
|
"""Return an authenticated HTTP client."""
|
||||||
access_token = hass.auth.async_create_access_token(hassio_stubs)
|
access_token = hass.auth.async_create_access_token(hassio_stubs)
|
||||||
return await aiohttp_client(
|
return await aiohttp_client(
|
||||||
|
@ -32,9 +32,9 @@ from tests.typing import ClientSessionGenerator
|
|||||||
)
|
)
|
||||||
async def test_full_flow(
|
async def test_full_flow(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client_no_auth,
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
current_request_with_host,
|
current_request_with_host: None,
|
||||||
jwt: str,
|
jwt: str,
|
||||||
new_scope: str,
|
new_scope: str,
|
||||||
amount: int,
|
amount: int,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -15,6 +16,8 @@ from homeassistant.data_entry_flow import FlowResultType
|
|||||||
from homeassistant.helpers.dispatcher import DATA_DISPATCHER
|
from homeassistant.helpers.dispatcher import DATA_DISPATCHER
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def mock_dev_track(mock_device_tracker_conf):
|
def mock_dev_track(mock_device_tracker_conf):
|
||||||
@ -22,7 +25,9 @@ def mock_dev_track(mock_device_tracker_conf):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def locative_client(hass, hass_client):
|
async def locative_client(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Locative mock client."""
|
"""Locative mock client."""
|
||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -15,14 +15,15 @@ from homeassistant.helpers.network import get_url
|
|||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, load_fixture
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
async def test_webhook_accepts_valid_message(
|
async def test_webhook_accepts_valid_message(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client_no_auth,
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
integration: MockConfigEntry,
|
integration: MockConfigEntry,
|
||||||
lock: loqed.Lock,
|
lock: loqed.Lock,
|
||||||
):
|
) -> None:
|
||||||
"""Test webhook called with valid message."""
|
"""Test webhook called with valid message."""
|
||||||
await async_setup_component(hass, "http", {"http": {}})
|
await async_setup_component(hass, "http", {"http": {}})
|
||||||
client = await hass_client_no_auth()
|
client = await hass_client_no_auth()
|
||||||
|
@ -3,21 +3,26 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import mailgun, webhook
|
from homeassistant.components import mailgun, webhook
|
||||||
from homeassistant.config import async_process_ha_core_config
|
from homeassistant.config import async_process_ha_core_config
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_DOMAIN
|
from homeassistant.const import CONF_API_KEY, CONF_DOMAIN
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
API_KEY = "abc123"
|
API_KEY = "abc123"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def http_client(hass, hass_client_no_auth):
|
async def http_client(
|
||||||
|
hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Initialize a Home Assistant Server for testing this module."""
|
"""Initialize a Home Assistant Server for testing this module."""
|
||||||
await async_setup_component(hass, webhook.DOMAIN, {})
|
await async_setup_component(hass, webhook.DOMAIN, {})
|
||||||
return await hass_client_no_auth()
|
return await hass_client_no_auth()
|
||||||
|
@ -2,13 +2,17 @@
|
|||||||
|
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.mobile_app.const import DOMAIN
|
from homeassistant.components.mobile_app.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .const import REGISTER, REGISTER_CLEARTEXT
|
from .const import REGISTER, REGISTER_CLEARTEXT
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def create_registrations(hass, webhook_client):
|
async def create_registrations(hass, webhook_client):
|
||||||
@ -53,7 +57,9 @@ async def push_registration(hass, webhook_client):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def webhook_client(hass, hass_client):
|
async def webhook_client(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Provide an authenticated client for mobile_app to use."""
|
"""Provide an authenticated client for mobile_app to use."""
|
||||||
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -98,7 +98,7 @@ def aiohttp_client(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def auth(aiohttp_client):
|
async def auth(aiohttp_client: ClientSessionGenerator) -> FakeAuth:
|
||||||
"""Fixture for an AbstractAuth."""
|
"""Fixture for an AbstractAuth."""
|
||||||
auth = FakeAuth()
|
auth = FakeAuth()
|
||||||
app = aiohttp.web.Application()
|
app = aiohttp.web.Application()
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
"""Test the owntracks_http platform."""
|
"""Test the owntracks_http platform."""
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import owntracks
|
from homeassistant.components import owntracks
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_component
|
from tests.common import MockConfigEntry, mock_component
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
MINIMAL_LOCATION_MESSAGE = {
|
MINIMAL_LOCATION_MESSAGE = {
|
||||||
"_type": "location",
|
"_type": "location",
|
||||||
@ -39,7 +42,9 @@ def mock_dev_track(mock_device_tracker_conf):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_client(hass, hass_client_no_auth):
|
def mock_client(
|
||||||
|
hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Start the Home Assistant HTTP component."""
|
"""Start the Home Assistant HTTP component."""
|
||||||
mock_component(hass, "group")
|
mock_component(hass, "group")
|
||||||
mock_component(hass, "zone")
|
mock_component(hass, "zone")
|
||||||
|
@ -20,6 +20,7 @@ from .conftest import CONFIG_ENTRY_DATA_OLD_FORMAT, mock_response, mock_response
|
|||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
from tests.test_util.aiohttp import AiohttpClientMockResponse
|
from tests.test_util.aiohttp import AiohttpClientMockResponse
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
TEST_ENTITY = "calendar.rain_bird_controller"
|
TEST_ENTITY = "calendar.rain_bird_controller"
|
||||||
type GetEventsFn = Callable[[str, str], Awaitable[dict[str, Any]]]
|
type GetEventsFn = Callable[[str, str], Awaitable[dict[str, Any]]]
|
||||||
@ -237,7 +238,7 @@ async def test_no_schedule(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
get_events: GetEventsFn,
|
get_events: GetEventsFn,
|
||||||
responses: list[AiohttpClientMockResponse],
|
responses: list[AiohttpClientMockResponse],
|
||||||
hass_client: Callable[..., Awaitable[ClientSession]],
|
hass_client: ClientSessionGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test calendar error when fetching the calendar."""
|
"""Test calendar error when fetching the calendar."""
|
||||||
responses.extend([mock_response_error(HTTPStatus.BAD_GATEWAY)]) # Arbitrary error
|
responses.extend([mock_response_error(HTTPStatus.BAD_GATEWAY)]) # Arbitrary error
|
||||||
|
@ -13,6 +13,7 @@ from .const import DEMAND, NETWORK_INFO, PRICE_CLUSTER, SUMMATION
|
|||||||
|
|
||||||
from tests.common import patch
|
from tests.common import patch
|
||||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -47,8 +48,11 @@ async def mock_entry_no_meters(hass: HomeAssistant, mock_device):
|
|||||||
|
|
||||||
|
|
||||||
async def test_entry_diagnostics_no_meters(
|
async def test_entry_diagnostics_no_meters(
|
||||||
hass, hass_client, mock_device, mock_entry_no_meters
|
hass: HomeAssistant,
|
||||||
):
|
hass_client: ClientSessionGenerator,
|
||||||
|
mock_device,
|
||||||
|
mock_entry_no_meters,
|
||||||
|
) -> None:
|
||||||
"""Test RAVEn diagnostics before the coordinator has updated."""
|
"""Test RAVEn diagnostics before the coordinator has updated."""
|
||||||
result = await get_diagnostics_for_config_entry(
|
result = await get_diagnostics_for_config_entry(
|
||||||
hass, hass_client, mock_entry_no_meters
|
hass, hass_client, mock_entry_no_meters
|
||||||
@ -66,7 +70,9 @@ async def test_entry_diagnostics_no_meters(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_diagnostics(hass, hass_client, mock_device, mock_entry):
|
async def test_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_device, mock_entry
|
||||||
|
) -> None:
|
||||||
"""Test RAVEn diagnostics."""
|
"""Test RAVEn diagnostics."""
|
||||||
result = await get_diagnostics_for_config_entry(hass, hass_client, mock_entry)
|
result = await get_diagnostics_for_config_entry(hass, hass_client, mock_entry)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.spaceapi import DOMAIN, SPACEAPI_VERSION, URL_API_SPACEAPI
|
from homeassistant.components.spaceapi import DOMAIN, SPACEAPI_VERSION, URL_API_SPACEAPI
|
||||||
@ -10,6 +11,8 @@ from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, UnitOfTemp
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
DOMAIN: {
|
DOMAIN: {
|
||||||
"space": "Home",
|
"space": "Home",
|
||||||
@ -80,7 +83,7 @@ SENSOR_OUTPUT = {
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_client(hass, hass_client):
|
def mock_client(hass: HomeAssistant, hass_client: ClientSessionGenerator) -> TestClient:
|
||||||
"""Start the Home Assistant HTTP component."""
|
"""Start the Home Assistant HTTP component."""
|
||||||
with patch("homeassistant.components.spaceapi", return_value=True):
|
with patch("homeassistant.components.spaceapi", return_value=True):
|
||||||
hass.loop.run_until_complete(async_setup_component(hass, "spaceapi", CONFIG))
|
hass.loop.run_until_complete(async_setup_component(hass, "spaceapi", CONFIG))
|
||||||
|
@ -69,7 +69,7 @@ class HlsClient:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hls_stream(hass, hass_client):
|
def hls_stream(hass: HomeAssistant, hass_client: ClientSessionGenerator):
|
||||||
"""Create test fixture for creating an HLS client for a stream."""
|
"""Create test fixture for creating an HLS client for a stream."""
|
||||||
|
|
||||||
async def create_client_for_stream(stream):
|
async def create_client_for_stream(stream):
|
||||||
|
@ -33,6 +33,8 @@ from .common import (
|
|||||||
)
|
)
|
||||||
from .test_hls import STREAM_SOURCE, HlsClient, make_playlist
|
from .test_hls import STREAM_SOURCE, HlsClient, make_playlist
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
SEGMENT_DURATION = 6
|
SEGMENT_DURATION = 6
|
||||||
TEST_PART_DURATION = 0.75
|
TEST_PART_DURATION = 0.75
|
||||||
NUM_PART_SEGMENTS = int(-(-SEGMENT_DURATION // TEST_PART_DURATION))
|
NUM_PART_SEGMENTS = int(-(-SEGMENT_DURATION // TEST_PART_DURATION))
|
||||||
@ -45,7 +47,7 @@ VERY_LARGE_LAST_BYTE_POS = 9007199254740991
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hls_stream(hass, hass_client):
|
def hls_stream(hass: HomeAssistant, hass_client: ClientSessionGenerator):
|
||||||
"""Create test fixture for creating an HLS client for a stream."""
|
"""Create test fixture for creating an HLS client for a stream."""
|
||||||
|
|
||||||
async def create_client_for_stream(stream):
|
async def create_client_for_stream(stream):
|
||||||
|
@ -5,6 +5,7 @@ from ipaddress import ip_address
|
|||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import webhook
|
from homeassistant.components import webhook
|
||||||
@ -12,11 +13,11 @@ from homeassistant.config import async_process_ha_core_config
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.typing import WebSocketGenerator
|
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_client(hass, hass_client):
|
def mock_client(hass: HomeAssistant, hass_client: ClientSessionGenerator) -> TestClient:
|
||||||
"""Create http client for webhooks."""
|
"""Create http client for webhooks."""
|
||||||
hass.loop.run_until_complete(async_setup_component(hass, "webhook", {}))
|
hass.loop.run_until_complete(async_setup_component(hass, "webhook", {}))
|
||||||
return hass.loop.run_until_complete(hass_client())
|
return hass.loop.run_until_complete(hass_client())
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Fixtures for websocket tests."""
|
"""Fixtures for websocket tests."""
|
||||||
|
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.websocket_api.auth import TYPE_AUTH_REQUIRED
|
from homeassistant.components.websocket_api.auth import TYPE_AUTH_REQUIRED
|
||||||
@ -7,7 +8,11 @@ from homeassistant.components.websocket_api.http import URL
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.typing import MockHAClientWebSocket, WebSocketGenerator
|
from tests.typing import (
|
||||||
|
ClientSessionGenerator,
|
||||||
|
MockHAClientWebSocket,
|
||||||
|
WebSocketGenerator,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -19,7 +24,9 @@ async def websocket_client(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def no_auth_websocket_client(hass, hass_client_no_auth):
|
async def no_auth_websocket_client(
|
||||||
|
hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator
|
||||||
|
) -> TestClient:
|
||||||
"""Websocket connection that requires authentication."""
|
"""Websocket connection that requires authentication."""
|
||||||
assert await async_setup_component(hass, "websocket_api", {})
|
assert await async_setup_component(hass, "websocket_api", {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -231,9 +231,9 @@ async def test_flow_http_error(
|
|||||||
)
|
)
|
||||||
async def test_reauth(
|
async def test_reauth(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client_no_auth,
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
current_request_with_host,
|
current_request_with_host: None,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
fixture: str,
|
fixture: str,
|
||||||
abort_reason: str,
|
abort_reason: str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user