test(backups): test setting autobackup period

This commit is contained in:
Houkime 2023-04-03 22:39:04 +00:00
parent 3c42d8c413
commit d4cad61d56
2 changed files with 30 additions and 2 deletions

View file

@ -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

View file

@ -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