Skip to content

Commit

Permalink
Fix tests for 2023.11
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Oct 28, 2023
1 parent b5bd48f commit 076f872
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
14 changes: 10 additions & 4 deletions tests/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from aiohttp import WSMessage, WSMsgType
from homeassistant import core
from homeassistant.components import demo
from homeassistant.const import Platform
from homeassistant.const import MAJOR_VERSION, MINOR_VERSION, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION
from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION, _make_key
from homeassistant.setup import async_setup_component
import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry
Expand Down Expand Up @@ -59,14 +59,20 @@ async def ws_connect(self, *args, **kwargs):
return self.ws


def mock_client_session(hass, session):
if MAJOR_VERSION > 2023 or (MAJOR_VERSION == 2023 and MINOR_VERSION >= 11):
hass.data[DATA_CLIENTSESSION] = {_make_key(): session}
else:
hass.data[DATA_CLIENTSESSION] = session


async def async_setup_entry(
hass: HomeAssistant,
config_entry: MockConfigEntry,
session: MockSession | None = None,
aiohttp_client: Any | None = None,
):
hass.data[DATA_CLIENTSESSION] = session or MockSession(aiohttp_client)

mock_client_session(hass, session or MockSession(aiohttp_client))
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
Expand Down
3 changes: 1 addition & 2 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from homeassistant import config_entries, data_entry_flow
from homeassistant.config import YAML_CONFIG_FILE
from homeassistant.const import CONF_ENTITIES
from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION
from homeassistant.helpers.reload import async_integration_yaml_config
from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import async_setup_component
Expand Down Expand Up @@ -65,7 +64,7 @@ async def test_config_flow_empty_entities(hass):


async def test_config_flow_cloud(hass, aioclient_mock):
hass.data[DATA_CLIENTSESSION] = test_cloud.MockSession(aioclient_mock)
test_cloud.mock_client_session(hass, test_cloud.MockSession(aioclient_mock))

result = await hass.config_entries.flow.async_init(DOMAIN, context={"source": config_entries.SOURCE_USER})
assert result["type"] == "form"
Expand Down
11 changes: 5 additions & 6 deletions tests/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from homeassistant.components.light import ATTR_BRIGHTNESS
from homeassistant.const import ATTR_DEVICE_CLASS, EVENT_HOMEASSISTANT_STARTED, STATE_UNAVAILABLE
from homeassistant.core import CoreState, State
from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION
from homeassistant.helpers.template import Template
from homeassistant.setup import async_setup_component
import pytest
Expand Down Expand Up @@ -82,14 +81,14 @@ async def test_notifier_setup_config_invalid(hass, hass_admin_user, config_entry
component: YandexSmartHome = hass.data[DOMAIN]
with pytest.raises(KeyError):
component.get_entry_data(config_entry_direct)
assert (
caplog.messages[-1] == "Config entry 'Mock Title' for yandex_smart_home integration not ready yet: "
"User invalid does not exist; Retrying in background"
assert caplog.messages[-1].startswith(
"Config entry 'Mock Title' for yandex_smart_home integration not ready yet: "
"User invalid does not exist; Retrying in"
)


async def test_notifier_setup_not_discovered(hass, hass_admin_user, aioclient_mock):
hass.data[DATA_CLIENTSESSION] = test_cloud.MockSession(aioclient_mock)
test_cloud.mock_client_session(hass, test_cloud.MockSession(aioclient_mock))

yaml_config = {
const.CONF_NOTIFIER: [
Expand Down Expand Up @@ -129,7 +128,7 @@ async def test_notifier_setup_not_discovered(hass, hass_admin_user, aioclient_mo


async def test_notifier_lifecycle_discovered(hass, hass_admin_user, aioclient_mock):
hass.data[DATA_CLIENTSESSION] = test_cloud.MockSession(aioclient_mock)
test_cloud.mock_client_session(hass, test_cloud.MockSession(aioclient_mock))

yaml_config = {
const.CONF_NOTIFIER: [
Expand Down

0 comments on commit 076f872

Please sign in to comment.