feat(backups): return proper snapshot structs when listing

This commit is contained in:
Houkime 2023-02-22 13:35:55 +00:00
parent 8a1b3be9fa
commit c32353fe9b
2 changed files with 14 additions and 3 deletions

View file

@ -128,9 +128,14 @@ class ResticBackuper(AbstractBackuper):
def get_snapshots(self, repo_name) -> List[Snapshot]:
"""Get all snapshots from the repo"""
# No transformation for now
snapshots = []
for snapshot in self._load_snapshots(repo_name):
for restic_snapshot in self._load_snapshots(repo_name):
snapshot = Snapshot(
id=restic_snapshot["short_id"],
created_at=restic_snapshot["time"],
service_name=repo_name,
)
snapshots.append(snapshot)
return snapshots

View file

@ -4,6 +4,8 @@ from os import makedirs
from selfprivacy_api.services.test_service import DummyService
from selfprivacy_api.models.backup.snapshot import Snapshot
from selfprivacy_api.backup import Backups
import selfprivacy_api.backup.providers as providers
from selfprivacy_api.backup.providers import AbstractBackupProvider
@ -100,4 +102,8 @@ def test_no_repo(memory_backup):
def test_one_snapshot(backups, dummy_service):
backups.back_up(dummy_service)
assert len(backups.get_snapshots(dummy_service)) == 1
snaps = backups.get_snapshots(dummy_service)
assert len(snaps) == 1
snap = snaps[0]
assert snap.service_name == dummy_service.get_id()