async def test_removing_backup( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, ) -> None: """Test removing backup.""" manager = BackupManager(hass) manager.backups = {TEST_BACKUP.slug: TEST_BACKUP} manager.loaded_backups = True with patch("pathlib.Path.exists", return_value=True): await manager.remove_backup(TEST_BACKUP.slug) assert "Removed backup located at" in caplog.text
async def test_generate_backup( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, ) -> None: """Test generate backup.""" manager = BackupManager(hass) manager.loaded_backups = True await _mock_backup_generation(manager) assert "Generated new backup with slug " in caplog.text assert "Creating backup directory" in caplog.text assert "Loaded 0 platforms" in caplog.text
async def test_getting_backup_that_does_not_exist( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, ): """Test getting backup that does not exist.""" manager = BackupManager(hass) manager.backups = {TEST_BACKUP.slug: TEST_BACKUP} manager.loaded_backups = True with patch("pathlib.Path.exists", return_value=False): backup = await manager.get_backup(TEST_BACKUP.slug) assert backup is None assert (f"Removing tracked backup ({TEST_BACKUP.slug}) that " f"does not exists on the expected path {TEST_BACKUP.path}" in caplog.text)
async def test_exception_plaform_post(hass: HomeAssistant) -> None: """Test exception in post step.""" manager = BackupManager(hass) manager.loaded_backups = True async def _mock_step(hass: HomeAssistant) -> None: raise HomeAssistantError("Test exception") await _setup_mock_domain( hass, Mock( async_pre_backup=AsyncMock(), async_post_backup=_mock_step, ), ) with pytest.raises(HomeAssistantError): await _mock_backup_generation(manager)