1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 00:20:30 +01:00

Simplify tests

This commit is contained in:
Erik
2026-03-30 15:09:31 +02:00
parent cfc353be69
commit 4bc29274c7
2 changed files with 8 additions and 32 deletions

View File

@@ -17,11 +17,7 @@ from homeassistant.components.calendar import (
from homeassistant.config_entries import ConfigEntry, ConfigFlow from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import ( from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
AddConfigEntryEntitiesCallback,
AddEntitiesCallback,
)
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from tests.common import ( from tests.common import (
@@ -182,29 +178,6 @@ def mock_setup_config_entry_integration(
) )
@pytest.fixture
def mock_setup_platform_integration(
hass: HomeAssistant,
config_flow_fixture: None,
test_entities: list[CalendarEntity],
) -> None:
"""Fixture to set up a mock integration without config entry."""
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
pass
mock_platform(
hass,
f"{TEST_DOMAIN}.{DOMAIN}",
MockPlatform(async_setup_platform=async_setup_platform),
)
@pytest.fixture(name="test_entities") @pytest.fixture(name="test_entities")
def mock_test_entities() -> list[MockCalendarEntity]: def mock_test_entities() -> list[MockCalendarEntity]:
"""Fixture that holdes the fake entities created during the test.""" """Fixture that holdes the fake entities created during the test."""

View File

@@ -7,6 +7,7 @@ from datetime import timedelta
from http import HTTPStatus from http import HTTPStatus
import re import re
from typing import Any from typing import Any
from unittest.mock import AsyncMock
from aiohttp.test_utils import TestClient from aiohttp.test_utils import TestClient
from freezegun import freeze_time from freezegun import freeze_time
@@ -31,6 +32,7 @@ from homeassistant.util import dt as dt_util
from .conftest import MockCalendarEntity, MockConfigEntry from .conftest import MockCalendarEntity, MockConfigEntry
from tests.common import MockPlatform, mock_platform
from tests.typing import ClientSessionGenerator, WebSocketGenerator from tests.typing import ClientSessionGenerator, WebSocketGenerator
@@ -64,7 +66,6 @@ async def mock_setup_calendar_integration(
@pytest.fixture(name="setup_calendar_config_entry_platform") @pytest.fixture(name="setup_calendar_config_entry_platform")
# @pytest.fixture(name="setup_platform", autouse=True)
async def mock_setup_config_entry_platform( async def mock_setup_config_entry_platform(
hass: HomeAssistant, hass: HomeAssistant,
set_time_zone: None, set_time_zone: None,
@@ -802,9 +803,6 @@ async def test_frontend_resources_registered_after_first_config_entry_setup(
async def test_frontend_resources_registered_after_first_platform_setup( async def test_frontend_resources_registered_after_first_platform_setup(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
set_time_zone: None,
frozen_time: str | None,
mock_setup_platform_integration: None,
) -> None: ) -> None:
"""Test that frontend resources are registered after the first platform is set up.""" """Test that frontend resources are registered after the first platform is set up."""
await async_setup_component(hass, "http", {}) await async_setup_component(hass, "http", {})
@@ -813,6 +811,11 @@ async def test_frontend_resources_registered_after_first_platform_setup(
assert "frontend_panels" not in hass.data assert "frontend_panels" not in hass.data
assert "websocket_api" not in hass.data assert "websocket_api" not in hass.data
mock_platform(
hass,
f"test.{DOMAIN}",
MockPlatform(async_setup_platform=AsyncMock()),
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}}) assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await _assert_http_api_responses(client, HTTPStatus.OK, HTTPStatus.BAD_REQUEST) await _assert_http_api_responses(client, HTTPStatus.OK, HTTPStatus.BAD_REQUEST)
assert set(hass.data["frontend_panels"]) == {"calendar"} assert set(hass.data["frontend_panels"]) == {"calendar"}