Fix RuntimeWarning in rest tests (#146452)

This commit is contained in:
Marc Mueller
2025-06-10 15:26:07 +02:00
committed by GitHub
parent f448f488ba
commit 6c5f7eabff
2 changed files with 18 additions and 16 deletions

View File

@ -2,7 +2,7 @@
from http import HTTPStatus from http import HTTPStatus
import ssl import ssl
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import patch
import pytest import pytest
@ -174,11 +174,12 @@ async def test_setup_ssl_ciphers(
hass: HomeAssistant, hass: HomeAssistant,
ssl_cipher_list: str, ssl_cipher_list: str,
ssl_cipher_list_expected: SSLCipherList, ssl_cipher_list_expected: SSLCipherList,
aioclient_mock: AiohttpClientMocker,
) -> None: ) -> None:
"""Test setup with minimum configuration.""" """Test setup with minimum configuration."""
with patch( with patch(
"homeassistant.components.rest.data.async_get_clientsession", "homeassistant.components.rest.data.async_get_clientsession",
return_value=MagicMock(request=AsyncMock(return_value=MagicMock())), return_value=aioclient_mock,
) as aiohttp_client: ) as aiohttp_client:
assert await async_setup_component( assert await async_setup_component(
hass, hass,

View File

@ -63,6 +63,7 @@ class AiohttpClientMocker:
cookies=None, cookies=None,
side_effect=None, side_effect=None,
closing=None, closing=None,
timeout=None,
): ):
"""Mock a request.""" """Mock a request."""
if not isinstance(url, RETYPE): if not isinstance(url, RETYPE):
@ -70,21 +71,21 @@ class AiohttpClientMocker:
if params: if params:
url = url.with_query(params) url = url.with_query(params)
self._mocks.append( resp = AiohttpClientMockResponse(
AiohttpClientMockResponse( method=method,
method=method, url=url,
url=url, status=status,
status=status, response=content,
response=content, json=json,
json=json, text=text,
text=text, cookies=cookies,
cookies=cookies, exc=exc,
exc=exc, headers=headers,
headers=headers, side_effect=side_effect,
side_effect=side_effect, closing=closing,
closing=closing,
)
) )
self._mocks.append(resp)
return resp
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
"""Register a mock get request.""" """Register a mock get request."""