mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-10 10:46:29 +00:00
Handle get users API returning None (#4628)
* Handle get users API returning None * Skip throttle during test
This commit is contained in:
parent
b7721420fa
commit
a24657e565
@ -491,11 +491,13 @@ class HomeAssistant(FileConfiguration, CoreSysAttributes):
|
|||||||
{ATTR_TYPE: "config/auth/list"}
|
{ATTR_TYPE: "config/auth/list"}
|
||||||
)
|
)
|
||||||
|
|
||||||
return [
|
if list_of_users:
|
||||||
IngressSessionDataUser(
|
return [
|
||||||
id=data["id"],
|
IngressSessionDataUser(
|
||||||
username=data.get("username"),
|
id=data["id"],
|
||||||
display_name=data.get("name"),
|
username=data.get("username"),
|
||||||
)
|
display_name=data.get("name"),
|
||||||
for data in list_of_users
|
)
|
||||||
]
|
for data in list_of_users
|
||||||
|
]
|
||||||
|
return []
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from supervisor.const import CoreState
|
from supervisor.const import CoreState
|
||||||
from supervisor.coresys import CoreSys
|
from supervisor.coresys import CoreSys
|
||||||
@ -10,9 +10,10 @@ from supervisor.docker.interface import DockerInterface
|
|||||||
from supervisor.homeassistant.secrets import HomeAssistantSecrets
|
from supervisor.homeassistant.secrets import HomeAssistantSecrets
|
||||||
|
|
||||||
|
|
||||||
async def test_load(coresys: CoreSys, tmp_supervisor_data: Path):
|
async def test_load(
|
||||||
|
coresys: CoreSys, tmp_supervisor_data: Path, ha_ws_client: AsyncMock
|
||||||
|
):
|
||||||
"""Test homeassistant module load."""
|
"""Test homeassistant module load."""
|
||||||
client = coresys.homeassistant.websocket._client # pylint: disable=protected-access
|
|
||||||
with open(tmp_supervisor_data / "homeassistant" / "secrets.yaml", "w") as secrets:
|
with open(tmp_supervisor_data / "homeassistant" / "secrets.yaml", "w") as secrets:
|
||||||
secrets.write("hello: world\n")
|
secrets.write("hello: world\n")
|
||||||
|
|
||||||
@ -30,8 +31,16 @@ async def test_load(coresys: CoreSys, tmp_supervisor_data: Path):
|
|||||||
|
|
||||||
coresys.core.state = CoreState.SETUP
|
coresys.core.state = CoreState.SETUP
|
||||||
await coresys.homeassistant.websocket.async_send_message({"lorem": "ipsum"})
|
await coresys.homeassistant.websocket.async_send_message({"lorem": "ipsum"})
|
||||||
client.async_send_command.assert_not_called()
|
ha_ws_client.async_send_command.assert_not_called()
|
||||||
|
|
||||||
coresys.core.state = CoreState.RUNNING
|
coresys.core.state = CoreState.RUNNING
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
assert client.async_send_command.call_args_list[0][0][0] == {"lorem": "ipsum"}
|
assert ha_ws_client.async_send_command.call_args_list[0][0][0] == {"lorem": "ipsum"}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_users_none(coresys: CoreSys, ha_ws_client: AsyncMock):
|
||||||
|
"""Test get users returning none does not fail."""
|
||||||
|
ha_ws_client.async_send_command.return_value = None
|
||||||
|
assert [] == await coresys.homeassistant.get_users.__wrapped__(
|
||||||
|
coresys.homeassistant
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user