mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-18 16:39:13 +00:00
test(backups): test restoring a file
This commit is contained in:
parent
c8a8d45110
commit
1d403b0e94
|
@ -94,8 +94,15 @@ class ResticBackuper(AbstractBackuper):
|
||||||
"""
|
"""
|
||||||
Restore from backup with restic
|
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(
|
restore_command = self.restic_command(
|
||||||
repo_name, "restore", snapshot_id, "--target", folder
|
repo_name,
|
||||||
|
"restore",
|
||||||
|
snapshot_id,
|
||||||
|
"--target",
|
||||||
|
"/",
|
||||||
)
|
)
|
||||||
|
|
||||||
with subprocess.Popen(
|
with subprocess.Popen(
|
||||||
|
@ -103,7 +110,7 @@ class ResticBackuper(AbstractBackuper):
|
||||||
) as handle:
|
) as handle:
|
||||||
|
|
||||||
output = handle.communicate()[0].decode("utf-8")
|
output = handle.communicate()[0].decode("utf-8")
|
||||||
if "restored" not in output:
|
if "restoring" not in output:
|
||||||
raise ValueError("cannot restore a snapshot: " + output)
|
raise ValueError("cannot restore a snapshot: " + output)
|
||||||
|
|
||||||
def _load_snapshots(self, repo_name) -> object:
|
def _load_snapshots(self, repo_name) -> object:
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import pytest
|
import pytest
|
||||||
import os.path as path
|
import os.path as path
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
|
from os import remove
|
||||||
|
from os import listdir
|
||||||
|
|
||||||
from selfprivacy_api.services.test_service import DummyService
|
from selfprivacy_api.services.test_service import DummyService
|
||||||
|
|
||||||
|
@ -107,3 +109,21 @@ def test_one_snapshot(backups, dummy_service):
|
||||||
assert len(snaps) == 1
|
assert len(snaps) == 1
|
||||||
snap = snaps[0]
|
snap = snaps[0]
|
||||||
assert snap.service_name == dummy_service.get_id()
|
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)
|
||||||
|
|
Loading…
Reference in a new issue