From 7ec62a8f79c865b7693a8a2c4fc7c27805dad6c3 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 12 Jan 2024 13:27:02 +0000 Subject: [PATCH] fix(backups): do not autobackup disabled services --- selfprivacy_api/backup/__init__.py | 10 +++++++--- tests/test_backup.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/selfprivacy_api/backup/__init__.py b/selfprivacy_api/backup/__init__.py index 66a4eac..0fa845e 100644 --- a/selfprivacy_api/backup/__init__.py +++ b/selfprivacy_api/backup/__init__.py @@ -731,11 +731,14 @@ class Backups: def is_time_to_backup_service(service: Service, time: datetime): """Returns True if it is time to back up a service""" period = Backups.autobackup_period_minutes() - if not service.can_be_backed_up(): - return False if period is None: return False + if not service.is_enabled(): + return False + if not service.can_be_backed_up(): + return False + last_error = Backups.get_last_backup_error_time(service) if last_error is not None: @@ -743,8 +746,9 @@ class Backups: return False last_backup = Backups.get_last_backed_up(service) + + # Queue a backup immediately if there are no previous backups if last_backup is None: - # queue a backup immediately if there are no previous backups return True if time > last_backup + timedelta(minutes=period): diff --git a/tests/test_backup.py b/tests/test_backup.py index 036dd42..646d9aa 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -889,7 +889,7 @@ def backuppable_services() -> list[Service]: return [service for service in get_all_services() if service.can_be_backed_up()] -def test_services_to_back_up(backups, dummy_service): +def test_services_to_autobackup(backups, dummy_service): backup_period = 13 # minutes now = datetime.now(timezone.utc) @@ -911,6 +911,15 @@ def test_services_to_back_up(backups, dummy_service): ] +def test_do_not_autobackup_disabled_services(backups, dummy_service): + now = datetime.now(timezone.utc) + Backups.set_autobackup_period_minutes(3) + assert Backups.is_time_to_backup_service(dummy_service, now) is True + + dummy_service.disable() + assert Backups.is_time_to_backup_service(dummy_service, now) is False + + def test_autobackup_timer_periods(backups, dummy_service): now = datetime.now(timezone.utc) backup_period = 13 # minutes