From d4cad61d56d188614435ede74f350b416d6ba7c6 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 3 Apr 2023 22:39:04 +0000 Subject: [PATCH] test(backups): test setting autobackup period --- selfprivacy_api/backup/__init__.py | 10 ++++++++-- tests/test_graphql/test_backup.py | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/selfprivacy_api/backup/__init__.py b/selfprivacy_api/backup/__init__.py index e3143b5..b54482b 100644 --- a/selfprivacy_api/backup/__init__.py +++ b/selfprivacy_api/backup/__init__.py @@ -99,11 +99,17 @@ class Backups: """None means autobackup is disabled""" if not redis.exists(REDIS_AUTOBACKUP_PERIOD_KEY): return None - return redis.get(REDIS_AUTOBACKUP_PERIOD_KEY) + return int(redis.get(REDIS_AUTOBACKUP_PERIOD_KEY)) @staticmethod def set_autobackup_period_minutes(minutes: int): - """This initiates backup very soon if some services are not backed up""" + """ + 0 and negative numbers are equivalent to disable. + Setting to a positive number may result in a backup very soon if some services are not backed up. + """ + if minutes <= 0: + Backups.disable_all_autobackup() + return redis.set(REDIS_AUTOBACKUP_PERIOD_KEY, minutes) @staticmethod diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index 97dd6af..31ecefa 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -228,3 +228,25 @@ def test_autobackup_enable_service(backups, dummy_service): Backups.disable_autobackup(dummy_service) assert not Backups.is_autobackup_enabled(dummy_service) + + +def test_set_autobackup_period(backups): + assert Backups.autobackup_period_minutes() is None + + Backups.set_autobackup_period_minutes(2) + assert Backups.autobackup_period_minutes() == 2 + + Backups.disable_all_autobackup() + assert Backups.autobackup_period_minutes() is None + + Backups.set_autobackup_period_minutes(3) + assert Backups.autobackup_period_minutes() == 3 + + Backups.set_autobackup_period_minutes(0) + assert Backups.autobackup_period_minutes() is None + + Backups.set_autobackup_period_minutes(3) + assert Backups.autobackup_period_minutes() == 3 + + Backups.set_autobackup_period_minutes(-1) + assert Backups.autobackup_period_minutes() is None