"""Unit tests for ForceRefreshButton and PromoteFromNextButton. Uses object.__new__ to bypass HA entity setup — valid because async_press only calls coordinator methods, not HA lifecycle hooks. """ from unittest.mock import AsyncMock, MagicMock import pytest from custom_components.room_cal_ha.button import ForceRefreshButton, PromoteFromNextButton def _button(cls): btn = object.__new__(cls) btn._coordinator = MagicMock() btn._coordinator.async_refresh = AsyncMock() btn._coordinator.async_promote_next_to_current = AsyncMock() return btn async def test_force_refresh_calls_coordinator_refresh(): btn = _button(ForceRefreshButton) await btn.async_press() btn._coordinator.async_refresh.assert_awaited_once() async def test_promote_from_next_calls_coordinator_promote(): btn = _button(PromoteFromNextButton) await btn.async_press() btn._coordinator.async_promote_next_to_current.assert_awaited_once() async def test_force_refresh_does_not_call_promote(): btn = _button(ForceRefreshButton) await btn.async_press() btn._coordinator.async_promote_next_to_current.assert_not_called() async def test_promote_does_not_call_refresh(): btn = _button(PromoteFromNextButton) await btn.async_press() btn._coordinator.async_refresh.assert_not_called()