From c32353fe9b8c0764ac1d7822c9e354a95b71b364 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 22 Feb 2023 13:35:55 +0000 Subject: [PATCH] feat(backups): return proper snapshot structs when listing --- selfprivacy_api/backup/restic_backuper.py | 9 +++++++-- tests/test_graphql/test_backup.py | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/selfprivacy_api/backup/restic_backuper.py b/selfprivacy_api/backup/restic_backuper.py index 99d6a81..2a41967 100644 --- a/selfprivacy_api/backup/restic_backuper.py +++ b/selfprivacy_api/backup/restic_backuper.py @@ -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 diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index 193e8ab..2ed2f67 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -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()