Add type hints for AiohttpClientMocker in test fixtures (#118691)

This commit is contained in:
epenet 2024-06-03 10:13:22 +02:00 committed by GitHub
parent c93d42d59b
commit 666fc2333a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 17 additions and 9 deletions

View File

@ -13,7 +13,7 @@ from tests.typing import ClientSessionGenerator
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_all(aioclient_mock): def mock_all(aioclient_mock: AiohttpClientMocker) -> None:
"""Mock all setup requests.""" """Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"}) aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})

View File

@ -17,7 +17,7 @@ MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_all(aioclient_mock, request): def mock_all(aioclient_mock: AiohttpClientMocker) -> None:
"""Mock all setup requests.""" """Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"}) aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})

View File

@ -11,13 +11,14 @@ from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"} MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_all(aioclient_mock, request): def mock_all(aioclient_mock: AiohttpClientMocker) -> None:
"""Mock all setup requests.""" """Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"}) aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})

View File

@ -52,7 +52,7 @@ def os_info(extra_os_info):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_all(aioclient_mock, request, os_info): def mock_all(aioclient_mock: AiohttpClientMocker, os_info) -> None:
"""Mock all setup requests.""" """Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"}) aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})

View File

@ -21,7 +21,7 @@ MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_all(aioclient_mock, request): def mock_all(aioclient_mock: AiohttpClientMocker) -> None:
"""Mock all setup requests.""" """Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"}) aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})

View File

@ -23,7 +23,7 @@ from tests.typing import WebSocketGenerator
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_all(aioclient_mock): def mock_all(aioclient_mock: AiohttpClientMocker) -> None:
"""Mock all setup requests.""" """Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"}) aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})

View File

@ -1,6 +1,7 @@
"""Test the onboarding views.""" """Test the onboarding views."""
import asyncio import asyncio
from collections.abc import AsyncGenerator
from http import HTTPStatus from http import HTTPStatus
import os import os
from typing import Any from typing import Any
@ -35,7 +36,9 @@ def auth_active(hass):
@pytest.fixture(name="rpi") @pytest.fixture(name="rpi")
async def rpi_fixture(hass, aioclient_mock, mock_supervisor): async def rpi_fixture(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_supervisor
) -> None:
"""Mock core info with rpi.""" """Mock core info with rpi."""
aioclient_mock.get( aioclient_mock.get(
"http://127.0.0.1/core/info", "http://127.0.0.1/core/info",
@ -49,7 +52,9 @@ async def rpi_fixture(hass, aioclient_mock, mock_supervisor):
@pytest.fixture(name="no_rpi") @pytest.fixture(name="no_rpi")
async def no_rpi_fixture(hass, aioclient_mock, mock_supervisor): async def no_rpi_fixture(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_supervisor
) -> None:
"""Mock core info with rpi.""" """Mock core info with rpi."""
aioclient_mock.get( aioclient_mock.get(
"http://127.0.0.1/core/info", "http://127.0.0.1/core/info",
@ -63,7 +68,9 @@ async def no_rpi_fixture(hass, aioclient_mock, mock_supervisor):
@pytest.fixture(name="mock_supervisor") @pytest.fixture(name="mock_supervisor")
async def mock_supervisor_fixture(hass, aioclient_mock): async def mock_supervisor_fixture(
aioclient_mock: AiohttpClientMocker,
) -> AsyncGenerator[None, None]:
"""Mock supervisor.""" """Mock supervisor."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})