From 1d403b0e948ae758b75692b21cd7805c9c501025 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 22 Feb 2023 15:58:36 +0000 Subject: [PATCH] test(backups): test restoring a file --- selfprivacy_api/backup/restic_backuper.py | 11 +++++++++-- tests/test_graphql/test_backup.py | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/selfprivacy_api/backup/restic_backuper.py b/selfprivacy_api/backup/restic_backuper.py index 0db5a42..04461ca 100644 --- a/selfprivacy_api/backup/restic_backuper.py +++ b/selfprivacy_api/backup/restic_backuper.py @@ -94,8 +94,15 @@ class ResticBackuper(AbstractBackuper): """ Restore from backup with restic """ + # snapshots save the path of the folder in the file system + # I do not alter the signature yet because maybe this can be + # changed with flags restore_command = self.restic_command( - repo_name, "restore", snapshot_id, "--target", folder + repo_name, + "restore", + snapshot_id, + "--target", + "/", ) with subprocess.Popen( @@ -103,7 +110,7 @@ class ResticBackuper(AbstractBackuper): ) as handle: output = handle.communicate()[0].decode("utf-8") - if "restored" not in output: + if "restoring" not in output: raise ValueError("cannot restore a snapshot: " + output) def _load_snapshots(self, repo_name) -> object: diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index 2ed2f67..0e8e246 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -1,6 +1,8 @@ import pytest import os.path as path from os import makedirs +from os import remove +from os import listdir from selfprivacy_api.services.test_service import DummyService @@ -107,3 +109,21 @@ def test_one_snapshot(backups, dummy_service): assert len(snaps) == 1 snap = snaps[0] assert snap.service_name == dummy_service.get_id() + + +def test_restore(backups, dummy_service): + service_folder = dummy_service.get_location() + file_to_nuke = listdir(service_folder)[0] + assert file_to_nuke is not None + path_to_nuke = path.join(service_folder, file_to_nuke) + + backups.back_up(dummy_service) + snap = backups.get_snapshots(dummy_service)[0] + assert snap is not None + + assert path.exists(path_to_nuke) + remove(path_to_nuke) + assert not path.exists(path_to_nuke) + + backups.restore_service_from_snapshot(dummy_service, snap.id) + assert path.exists(path_to_nuke)