test(backups): test last backup date retrieval

pull/35/head
Houkime 2023-04-07 15:18:54 +00:00 committed by Inex Code
parent 054b07baa3
commit ed0861aacc
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):