From 77c267b9c8a310c7b657158c9c777f76d8cf9666 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 20 Nov 2023 11:14:22 +0000 Subject: [PATCH] beauty(backup): remove stray comments and imports, format --- selfprivacy_api/backup/__init__.py | 9 +++--- selfprivacy_api/backup/tasks.py | 1 - .../graphql/mutations/backup_mutations.py | 2 +- tests/test_graphql/test_backup.py | 30 ++++++++----------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/selfprivacy_api/backup/__init__.py b/selfprivacy_api/backup/__init__.py index 62fec61..66a4eac 100644 --- a/selfprivacy_api/backup/__init__.py +++ b/selfprivacy_api/backup/__init__.py @@ -395,8 +395,6 @@ class Backups: auto_snaps = Backups._auto_snaps(service) new_snaplist = Backups._prune_snaps_with_quotas(auto_snaps) - # TODO: Can be optimized since there is forgetting of an array in one restic op - # but most of the time this will be only one snap to forget. deletable_snaps = [snap for snap in auto_snaps if snap not in new_snaplist] Backups.forget_snapshots(deletable_snaps) @@ -629,9 +627,10 @@ class Backups: @staticmethod def forget_all_snapshots(): - """deliberately erase all snapshots we made""" - # there is no dedicated optimized command for this, - # but maybe we can have a multi-erase + """ + Mark all snapshots we have made for deletion and make them inaccessible + (this is done by cloud, we only issue a command) + """ Backups.forget_snapshots(Backups.get_all_snapshots()) @staticmethod diff --git a/selfprivacy_api/backup/tasks.py b/selfprivacy_api/backup/tasks.py index 6fddd1e..f0422ca 100644 --- a/selfprivacy_api/backup/tasks.py +++ b/selfprivacy_api/backup/tasks.py @@ -6,7 +6,6 @@ from datetime import datetime, timezone from selfprivacy_api.graphql.common_types.backup import ( RestoreStrategy, BackupReason, - AutobackupQuotas, ) from selfprivacy_api.models.backup.snapshot import Snapshot diff --git a/selfprivacy_api/graphql/mutations/backup_mutations.py b/selfprivacy_api/graphql/mutations/backup_mutations.py index 4bb6331..cc1538e 100644 --- a/selfprivacy_api/graphql/mutations/backup_mutations.py +++ b/selfprivacy_api/graphql/mutations/backup_mutations.py @@ -110,7 +110,7 @@ class BackupMutations: """ job = Jobs.add( - name="trimming autobackup snapshots", + name="Trimming autobackup snapshots", type_id="backups.autobackup_trimming", description="Pruning the excessive snapshots after the new autobackup quotas are set", ) diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index ede0e2b..b66a90d 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -1,53 +1,49 @@ import pytest + import os import os.path as path from os import makedirs from os import remove from os import listdir from os import urandom -from datetime import datetime, timedelta, timezone, date, time -from subprocess import Popen + +from datetime import datetime, timedelta, timezone from copy import copy - -import secrets - - import tempfile from selfprivacy_api.utils.huey import huey import selfprivacy_api.services as services from selfprivacy_api.services import Service, get_all_services -from selfprivacy_api.services.service import ServiceStatus - from selfprivacy_api.services import get_service_by_id +from selfprivacy_api.services.service import ServiceStatus from selfprivacy_api.services.test_service import DummyService + from selfprivacy_api.graphql.queries.providers import BackupProvider -from selfprivacy_api.graphql.common_types.backup import RestoreStrategy, BackupReason +from selfprivacy_api.graphql.common_types.backup import ( + RestoreStrategy, + BackupReason, + AutobackupQuotas, +) + from selfprivacy_api.jobs import Jobs, JobStatus from selfprivacy_api.models.backup.snapshot import Snapshot -from selfprivacy_api.graphql.common_types.backup import AutobackupQuotas - from selfprivacy_api.backup import Backups, BACKUP_PROVIDER_ENVS import selfprivacy_api.backup.providers as providers from selfprivacy_api.backup.providers import AbstractBackupProvider from selfprivacy_api.backup.providers.backblaze import Backblaze from selfprivacy_api.backup.providers.none import NoBackups from selfprivacy_api.backup.util import sync -from selfprivacy_api.backup.backuppers.restic_backupper import ResticBackupper -from selfprivacy_api.backup.jobs import add_backup_job, add_restore_job - from selfprivacy_api.backup.tasks import ( start_backup, restore_snapshot, reload_snapshot_cache, - prune_autobackup_snapshots + prune_autobackup_snapshots, ) from selfprivacy_api.backup.storage import Storage -from selfprivacy_api.backup.jobs import get_backup_job TESTFILE_BODY = "testytest!" @@ -653,7 +649,7 @@ def test_too_many_auto(backups, dummy_service): quota.last = 1 Backups.set_autobackup_quotas(quota) job = Jobs.add("trimming", "test.autobackup_trimming", "trimming the snaps!") - handle=prune_autobackup_snapshots(job) + handle = prune_autobackup_snapshots(job) handle(blocking=True) snaps = Backups.get_snapshots(dummy_service) assert len(snaps) == 1