Add AiohttpClientMocker type hints in tests (#118373)
This commit is contained in:
parent
d69431ea48
commit
d10362e226
13 changed files with 41 additions and 19 deletions
|
@ -7,10 +7,11 @@ import pytest
|
|||
from homeassistant.const import CONTENT_TYPE_JSON
|
||||
|
||||
from tests.common import load_fixture
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def aioclient_mock_fixture(aioclient_mock) -> None:
|
||||
def aioclient_mock_fixture(aioclient_mock: AiohttpClientMocker) -> None:
|
||||
"""Fixture to provide a aioclient mocker."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1:8080/status.json?show_avail=1",
|
||||
|
|
|
@ -175,7 +175,7 @@ class OAuthFixture:
|
|||
async def oauth_fixture(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: Any,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
) -> OAuthFixture:
|
||||
"""Fixture for testing the OAuth flow."""
|
||||
return OAuthFixture(hass, hass_client_no_auth, aioclient_mock)
|
||||
|
|
|
@ -33,7 +33,7 @@ async def async_set_txt(hass, txt):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def setup_duckdns(hass, aioclient_mock):
|
||||
def setup_duckdns(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
|
||||
"""Fixture that sets up DuckDNS."""
|
||||
aioclient_mock.get(
|
||||
duckdns.UPDATE_URL, params={"domains": DOMAIN, "token": TOKEN}, text="OK"
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, CONTENT_TYPE_JSON
|
|||
from .common import TEST_EMAIL_ADDRESS, TEST_PASSWORD, TEST_TOKEN, TEST_USER_ID
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -25,7 +26,7 @@ def config_entry(hass):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def aioclient_mock_fixture(aioclient_mock):
|
||||
def aioclient_mock_fixture(aioclient_mock: AiohttpClientMocker) -> None:
|
||||
"""Fixture to provide a aioclient mocker."""
|
||||
now = round(time.time())
|
||||
# Mocks the login response for flo.
|
||||
|
|
|
@ -16,7 +16,7 @@ UPDATE_URL = freedns.UPDATE_URL
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def setup_freedns(hass, aioclient_mock):
|
||||
def setup_freedns(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
|
||||
"""Fixture that sets up FreeDNS."""
|
||||
params = {}
|
||||
params[ACCESS_TOKEN] = ""
|
||||
|
|
|
@ -20,7 +20,9 @@ UPDATE_URL = f"https://{USERNAME}:{PASSWORD}@domains.google.com/nic/update"
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def setup_google_domains(hass, aioclient_mock):
|
||||
def setup_google_domains(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Fixture that sets up NamecheapDNS."""
|
||||
aioclient_mock.get(UPDATE_URL, params={"hostname": DOMAIN}, text="ok 0.0.0.0")
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ from homeassistant.const import ATTR_NAME
|
|||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, async_capture_events
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
TEST_API_CALL_ARGS = {"text": "Use API from Home Assistant", "type": "todo"}
|
||||
TEST_USER_NAME = "test_user"
|
||||
|
@ -45,7 +46,7 @@ def habitica_entry(hass):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def common_requests(aioclient_mock):
|
||||
def common_requests(aioclient_mock: AiohttpClientMocker) -> AiohttpClientMocker:
|
||||
"""Register requests for the tests."""
|
||||
aioclient_mock.get(
|
||||
"https://habitica.com/api/v3/user",
|
||||
|
|
|
@ -7,13 +7,14 @@ from unittest.mock import Mock, patch
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.hassio.handler import HassIO, HassioAPIError
|
||||
from homeassistant.core import CoreState
|
||||
from homeassistant.core import CoreState, HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import SUPERVISOR_TOKEN
|
||||
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -45,7 +46,12 @@ def hassio_env():
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def hassio_stubs(hassio_env, hass, hass_client, aioclient_mock):
|
||||
def hassio_stubs(
|
||||
hassio_env,
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
):
|
||||
"""Create mock hassio http client."""
|
||||
with (
|
||||
patch(
|
||||
|
@ -100,7 +106,7 @@ async def hassio_client_supervisor(hass, aiohttp_client, hassio_stubs):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
async def hassio_handler(hass, aioclient_mock):
|
||||
async def hassio_handler(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
|
||||
"""Create mock hassio handler."""
|
||||
with patch.dict(os.environ, {"SUPERVISOR_TOKEN": SUPERVISOR_TOKEN}):
|
||||
yield HassIO(hass.loop, async_get_clientsession(hass), "127.0.0.1")
|
||||
|
@ -109,7 +115,7 @@ async def hassio_handler(hass, aioclient_mock):
|
|||
@pytest.fixture
|
||||
def all_setup_requests(
|
||||
aioclient_mock: AiohttpClientMocker, request: pytest.FixtureRequest
|
||||
):
|
||||
) -> None:
|
||||
"""Mock all setup requests."""
|
||||
include_addons = hasattr(request, "param") and request.param.get(
|
||||
"include_addons", False
|
||||
|
|
|
@ -10,13 +10,15 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, MockUser
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def setup_push_receiver(hass, aioclient_mock, hass_admin_user):
|
||||
async def setup_push_receiver(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, hass_admin_user: MockUser
|
||||
) -> None:
|
||||
"""Fixture that sets up a mocked push receiver."""
|
||||
push_url = "https://mobile-push.home-assistant.dev/push"
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ CURRENT_SCOPE = "WRITESYSTEM READSYSTEM offline_access"
|
|||
|
||||
async def test_full_flow(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth,
|
||||
aioclient_mock,
|
||||
current_request_with_host,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
setup_credentials,
|
||||
) -> None:
|
||||
"""Check full flow."""
|
||||
|
|
|
@ -18,7 +18,9 @@ PASSWORD = "abcdefgh"
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def setup_namecheapdns(hass, aioclient_mock):
|
||||
def setup_namecheapdns(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Fixture that sets up NamecheapDNS."""
|
||||
aioclient_mock.get(
|
||||
namecheapdns.UPDATE_URL,
|
||||
|
|
|
@ -35,6 +35,8 @@ from .common import (
|
|||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
WEB_REDIRECT_URL = "https://example.com/auth/external/callback"
|
||||
APP_REDIRECT_URL = "urn:ietf:wg:oauth:2.0:oob"
|
||||
|
@ -189,7 +191,12 @@ class OAuthFixture:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
async def oauth(hass, hass_client_no_auth, aioclient_mock, current_request_with_host):
|
||||
async def oauth(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
current_request_with_host: None,
|
||||
) -> OAuthFixture:
|
||||
"""Create the simulated oauth flow."""
|
||||
return OAuthFixture(hass, hass_client_no_auth, aioclient_mock)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ USERNAME = "abc@123.com"
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def setup_no_ip(hass, aioclient_mock):
|
||||
def setup_no_ip(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
|
||||
"""Fixture that sets up NO-IP."""
|
||||
aioclient_mock.get(UPDATE_URL, params={"hostname": DOMAIN}, text="good 0.0.0.0")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue