test(backups): test last backup date retrieval

This commit is contained in:
Houkime 2023-04-07 15:18:54 +00:00
parent f6402f2394
commit 644a0b96b8
2 changed files with 10 additions and 1 deletions

View file

@ -58,6 +58,7 @@ class Backups:
@staticmethod
def get_last_backed_up(service: Service) -> Optional[datetime]:
"""Get a timezone-aware time of the last backup of a service"""
return Backups._get_last_backup_time_redis(service.get_id())
@staticmethod
@ -66,7 +67,7 @@ class Backups:
if not redis.exists(key):
return None
snapshot = hash_as_model(redis, key)
snapshot = hash_as_model(redis, key, Snapshot)
return snapshot.created_at
@staticmethod

View file

@ -3,6 +3,7 @@ import os.path as path
from os import makedirs
from os import remove
from os import listdir
from datetime import datetime, timedelta, timezone
from selfprivacy_api.services.test_service import DummyService
@ -113,8 +114,15 @@ def test_backup_simple_file(raw_dummy_service, file_backup):
def test_backup_service(dummy_service, backups):
assert Backups.get_last_backed_up(dummy_service) is None
Backups.back_up(dummy_service)
now = datetime.now(timezone.utc)
date = Backups.get_last_backed_up(dummy_service)
assert date is not None
assert now > date
assert now - date < timedelta(minutes=1)
def test_no_repo(memory_backup):
with pytest.raises(ValueError):