mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-04-29 23:57:16 +00:00

* Notify HA Core when backup is being executed Notify Home Assistant Core using the Websocket API when the Home Assistant config directory is about to get backed up. This makes sure the Core can prepare the SQLite database (if active) so it safe to make a backup. * Only close WebSocket connection on connection errors Let regular WebSocket errors bubble to the caller so they can be handled explicitly. * Add version restriction to backup/start/end WS commands * Restore Home Assistant metadata when Home Assistant is selected
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""Mock test."""
|
|
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from supervisor.backups.const import BackupType
|
|
from supervisor.backups.validate import ALL_FOLDERS
|
|
|
|
from tests.const import TEST_ADDON_SLUG
|
|
|
|
|
|
@pytest.fixture(name="backup_mock")
|
|
def fixture_backup_mock():
|
|
"""Backup class mock."""
|
|
with patch("supervisor.backups.manager.Backup") as backup_mock:
|
|
backup_instance = MagicMock()
|
|
backup_mock.return_value = backup_instance
|
|
|
|
backup_instance.store_addons = AsyncMock(return_value=None)
|
|
backup_instance.store_folders = AsyncMock(return_value=None)
|
|
backup_instance.store_homeassistant_config_dir = AsyncMock(return_value=None)
|
|
backup_instance.store_addons = AsyncMock(return_value=None)
|
|
backup_instance.restore_folders = AsyncMock(return_value=None)
|
|
backup_instance.restore_homeassistant_config_dir = AsyncMock(return_value=None)
|
|
backup_instance.restore_addons = AsyncMock(return_value=None)
|
|
backup_instance.restore_repositories = AsyncMock(return_value=None)
|
|
|
|
yield backup_mock
|
|
|
|
|
|
@pytest.fixture
|
|
def partial_backup_mock(backup_mock):
|
|
"""Partial backup mock."""
|
|
backup_instance = backup_mock.return_value
|
|
backup_instance.sys_type = BackupType.PARTIAL
|
|
backup_instance.folders = []
|
|
backup_instance.addon_list = [TEST_ADDON_SLUG]
|
|
yield backup_mock
|
|
|
|
|
|
@pytest.fixture
|
|
def full_backup_mock(backup_mock):
|
|
"""Full backup mock."""
|
|
backup_instance = backup_mock.return_value
|
|
backup_instance.sys_type = BackupType.FULL
|
|
backup_instance.folders = ALL_FOLDERS
|
|
backup_instance.addon_list = [TEST_ADDON_SLUG]
|
|
yield backup_mock
|