From b67777835dfaf8fe69762584262061e42083efef Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 7 Aug 2024 12:35:34 +0000 Subject: [PATCH] fix(backup): make last slice return a correct list --- selfprivacy_api/backup/tasks.py | 2 +- selfprivacy_api/graphql/queries/backup.py | 2 +- tests/test_graphql/test_api_backup.py | 30 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/selfprivacy_api/backup/tasks.py b/selfprivacy_api/backup/tasks.py index 515c56a..4c4426d 100644 --- a/selfprivacy_api/backup/tasks.py +++ b/selfprivacy_api/backup/tasks.py @@ -118,7 +118,7 @@ def do_autobackup() -> None: def eligible_for_full_restoration(snap: Snapshot): - service = ServiceManager.get_service_by_id(Snapshot.service_name) + service = ServiceManager.get_service_by_id(snap.service_name) if service is None: return False if service.is_enabled() is False: diff --git a/selfprivacy_api/graphql/queries/backup.py b/selfprivacy_api/graphql/queries/backup.py index 7df050f..ad5b0da 100644 --- a/selfprivacy_api/graphql/queries/backup.py +++ b/selfprivacy_api/graphql/queries/backup.py @@ -102,4 +102,4 @@ class Backup: def last_slice(self) -> typing.List[SnapshotInfo]: if not Backups.is_initted(): return [] - result = [snapshot_to_api(snap) for snap in which_snapshots_to_full_restore()] + return [snapshot_to_api(snap) for snap in which_snapshots_to_full_restore()] diff --git a/tests/test_graphql/test_api_backup.py b/tests/test_graphql/test_api_backup.py index f5cc061..350d111 100644 --- a/tests/test_graphql/test_api_backup.py +++ b/tests/test_graphql/test_api_backup.py @@ -161,6 +161,18 @@ mutation TestForgetSnapshot($snapshot_id: String!) { } """ +API_LAST_SLICE_QUERY = """ +lastSlice { + id + service { + id + displayName + } + createdAt + reason +} +""" + API_SNAPSHOTS_QUERY = """ allSnapshots { id @@ -349,6 +361,17 @@ def api_snapshots(authorized_client): return result +def api_last_slice(authorized_client): + response = authorized_client.post( + "/graphql", + json={"query": generate_backup_query([API_LAST_SLICE_QUERY])}, + ) + data = get_data(response) + result = data["backup"]["lastSlice"] + assert result is not None + return result + + def api_settings(authorized_client): response = authorized_client.post( "/graphql", @@ -633,3 +656,10 @@ def test_forget_nonexistent_snapshot(authorized_client, dummy_service, backups): snaps = api_snapshots(authorized_client) assert len(snaps) == 0 + + +def test_last_slice(authorized_client, only_dummy_service_and_api, backups): + api_manual_autobackup(authorized_client) + snaps = api_last_slice(authorized_client) + + assert len(snaps) == 2