test(backups): test setting services as enabled for autobackups

This commit is contained in:
Houkime 2023-04-03 21:59:14 +00:00
parent 7f99fd044e
commit 9edfe10128
2 changed files with 13 additions and 2 deletions

View file

@ -78,12 +78,12 @@ class Backups:
redis.expire(snapshot_key, REDIS_SNAPSHOT_CACHE_EXPIRE_SECONDS)
@staticmethod
def _redis_autobackup_key(service: Service):
def _redis_autobackup_key(service: Service) -> str:
return REDIS_AUTOBACKUP_ENABLED_PREFIX + service.get_id()
@staticmethod
def enable_autobackup(service: Service):
redis.set(Backups._redis_autobackup_key(service), True)
redis.set(Backups._redis_autobackup_key(service), 1)
@staticmethod
def disable_autobackup(service: Service):
@ -159,6 +159,7 @@ class Backups:
REDIS_INITTED_CACHE_PREFIX,
REDIS_SNAPSHOTS_PREFIX,
REDIS_LAST_BACKUP_PREFIX,
REDIS_AUTOBACKUP_ENABLED_PREFIX,
]
for prefix in prefixes_to_clean:

View file

@ -218,3 +218,13 @@ def test_backup_service_task(backups, dummy_service):
snaps = Backups.get_snapshots(dummy_service)
assert len(snaps) == 1
def test_autobackup_enable_service(backups, dummy_service):
assert not Backups.is_autobackup_enabled(dummy_service)
Backups.enable_autobackup(dummy_service)
assert Backups.is_autobackup_enabled(dummy_service)
Backups.disable_autobackup(dummy_service)
assert not Backups.is_autobackup_enabled(dummy_service)