mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add Backup integration (#66395)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
83
tests/components/backup/test_websocket.py
Normal file
83
tests/components/backup/test_websocket.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""Tests for the Backup integration."""
|
||||
from collections.abc import Awaitable, Callable
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiohttp import ClientWebSocketResponse
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import TEST_BACKUP, setup_backup_integration
|
||||
|
||||
|
||||
async def test_info(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: Callable[[HomeAssistant], Awaitable[ClientWebSocketResponse]],
|
||||
) -> None:
|
||||
"""Test getting backup info."""
|
||||
await setup_backup_integration(hass)
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await client.send_json({"id": 1, "type": "backup/info"})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["id"] == 1
|
||||
assert msg["success"]
|
||||
assert msg["result"] == {"backing_up": False, "backups": []}
|
||||
|
||||
|
||||
async def test_remove(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: Callable[[HomeAssistant], Awaitable[ClientWebSocketResponse]],
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removing a backup file."""
|
||||
await setup_backup_integration(hass)
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.backup.websocket.BackupManager._backups",
|
||||
{TEST_BACKUP.slug: TEST_BACKUP},
|
||||
), patch(
|
||||
"homeassistant.components.backup.websocket.BackupManager._loaded",
|
||||
True,
|
||||
), patch(
|
||||
"pathlib.Path.unlink"
|
||||
), patch(
|
||||
"pathlib.Path.exists", return_value=True
|
||||
):
|
||||
await client.send_json({"id": 1, "type": "backup/remove", "slug": "abc123"})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["id"] == 1
|
||||
assert msg["success"]
|
||||
assert f"Removed backup located at {TEST_BACKUP.path}" in caplog.text
|
||||
|
||||
|
||||
async def test_generate(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: Callable[[HomeAssistant], Awaitable[ClientWebSocketResponse]],
|
||||
) -> None:
|
||||
"""Test removing a backup file."""
|
||||
await setup_backup_integration(hass)
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.backup.websocket.BackupManager._backups",
|
||||
{TEST_BACKUP.slug: TEST_BACKUP},
|
||||
), patch(
|
||||
"homeassistant.components.backup.websocket.BackupManager.generate_backup",
|
||||
return_value=TEST_BACKUP,
|
||||
):
|
||||
await client.send_json({"id": 1, "type": "backup/generate"})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["id"] == 1
|
||||
assert msg["success"]
|
||||
assert msg["result"] == TEST_BACKUP.as_dict()
|
||||
Reference in New Issue
Block a user