diff --git a/tests/components/unifi/test_update.py b/tests/components/unifi/test_update.py index 4094c544431..5f9039aa48e 100644 --- a/tests/components/unifi/test_update.py +++ b/tests/components/unifi/test_update.py @@ -3,6 +3,7 @@ from copy import deepcopy from aiounifi.models.message import MessageKey +import pytest from yarl import URL from homeassistant.components.unifi.const import CONF_SITE_ID @@ -26,8 +27,6 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant -from .test_hub import SITE, setup_unifi_integration - from tests.test_util.aiohttp import AiohttpClientMocker DEVICE_1 = { @@ -60,28 +59,14 @@ DEVICE_2 = { } -async def test_no_entities( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker -) -> None: - """Test the update_clients function when no clients are found.""" - await setup_unifi_integration(hass, aioclient_mock) - - assert len(hass.states.async_entity_ids(UPDATE_DOMAIN)) == 0 - - -async def test_device_updates( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_unifi_websocket -) -> None: +@pytest.mark.parametrize("device_payload", [[DEVICE_1, DEVICE_2]]) +@pytest.mark.usefixtures("config_entry_setup") +async def test_device_updates(hass: HomeAssistant, mock_unifi_websocket) -> None: """Test the update_items function with some devices.""" - device_1 = deepcopy(DEVICE_1) - await setup_unifi_integration( - hass, - aioclient_mock, - devices_response=[device_1, DEVICE_2], - ) - assert len(hass.states.async_entity_ids(UPDATE_DOMAIN)) == 2 + # Device with new firmware available + device_1_state = hass.states.get("update.device_1") assert device_1_state.state == STATE_ON assert device_1_state.attributes[ATTR_INSTALLED_VERSION] == "4.0.42.10433" @@ -93,6 +78,8 @@ async def test_device_updates( == UpdateEntityFeature.PROGRESS | UpdateEntityFeature.INSTALL ) + # Device without new firmware available + device_2_state = hass.states.get("update.device_2") assert device_2_state.state == STATE_OFF assert device_2_state.attributes[ATTR_INSTALLED_VERSION] == "4.0.42.10433" @@ -106,6 +93,7 @@ async def test_device_updates( # Simulate start of update + device_1 = deepcopy(DEVICE_1) device_1["state"] = 4 mock_unifi_websocket(message=MessageKey.DEVICE, data=device_1) await hass.async_block_till_done() @@ -132,17 +120,14 @@ async def test_device_updates( assert device_1_state.attributes[ATTR_IN_PROGRESS] is False -async def test_not_admin( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker -) -> None: +@pytest.mark.parametrize("device_payload", [[DEVICE_1]]) +@pytest.mark.parametrize( + "site_payload", + [[{"desc": "Site name", "name": "site_id", "role": "not admin", "_id": "1"}]], +) +@pytest.mark.usefixtures("config_entry_setup") +async def test_not_admin(hass: HomeAssistant) -> None: """Test that the INSTALL feature is not available on a non-admin account.""" - site = deepcopy(SITE) - site[0]["role"] = "not admin" - - await setup_unifi_integration( - hass, aioclient_mock, sites=site, devices_response=[DEVICE_1] - ) - assert len(hass.states.async_entity_ids(UPDATE_DOMAIN)) == 1 device_state = hass.states.get("update.device_1") assert device_state.state == STATE_ON @@ -151,13 +136,12 @@ async def test_not_admin( ) +@pytest.mark.parametrize("device_payload", [[DEVICE_1]]) async def test_install( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, config_entry_setup ) -> None: """Test the device update install call.""" - config_entry = await setup_unifi_integration( - hass, aioclient_mock, devices_response=[DEVICE_1] - ) + config_entry = config_entry_setup assert len(hass.states.async_entity_ids(UPDATE_DOMAIN)) == 1 device_state = hass.states.get("update.device_1") @@ -187,12 +171,10 @@ async def test_install( ) -async def test_hub_state_change( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, websocket_mock -) -> None: +@pytest.mark.parametrize("device_payload", [[DEVICE_1]]) +@pytest.mark.usefixtures("config_entry_setup") +async def test_hub_state_change(hass: HomeAssistant, websocket_mock) -> None: """Verify entities state reflect on hub becoming unavailable.""" - await setup_unifi_integration(hass, aioclient_mock, devices_response=[DEVICE_1]) - assert len(hass.states.async_entity_ids(UPDATE_DOMAIN)) == 1 assert hass.states.get("update.device_1").state == STATE_ON