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]: def get_snapshots(self, repo_name) -> List[Snapshot]:
"""Get all snapshots from the repo""" """Get all snapshots from the repo"""
# No transformation for now
snapshots = [] 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) snapshots.append(snapshot)
return snapshots return snapshots

View file

@ -4,6 +4,8 @@ from os import makedirs
from selfprivacy_api.services.test_service import DummyService from selfprivacy_api.services.test_service import DummyService
from selfprivacy_api.models.backup.snapshot import Snapshot
from selfprivacy_api.backup import Backups from selfprivacy_api.backup import Backups
import selfprivacy_api.backup.providers as providers import selfprivacy_api.backup.providers as providers
from selfprivacy_api.backup.providers import AbstractBackupProvider from selfprivacy_api.backup.providers import AbstractBackupProvider
@ -100,4 +102,8 @@ def test_no_repo(memory_backup):
def test_one_snapshot(backups, dummy_service): def test_one_snapshot(backups, dummy_service):
backups.back_up(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()