mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-24 13:01:28 +00:00
test(backups): test last backup date retrieval
This commit is contained in:
parent
f6402f2394
commit
644a0b96b8
|
@ -58,6 +58,7 @@ class Backups:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_last_backed_up(service: Service) -> Optional[datetime]:
|
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())
|
return Backups._get_last_backup_time_redis(service.get_id())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -66,7 +67,7 @@ class Backups:
|
||||||
if not redis.exists(key):
|
if not redis.exists(key):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
snapshot = hash_as_model(redis, key)
|
snapshot = hash_as_model(redis, key, Snapshot)
|
||||||
return snapshot.created_at
|
return snapshot.created_at
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -3,6 +3,7 @@ import os.path as path
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
from os import remove
|
from os import remove
|
||||||
from os import listdir
|
from os import listdir
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
from selfprivacy_api.services.test_service import DummyService
|
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):
|
def test_backup_service(dummy_service, backups):
|
||||||
|
assert Backups.get_last_backed_up(dummy_service) is None
|
||||||
Backups.back_up(dummy_service)
|
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):
|
def test_no_repo(memory_backup):
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
|
|
Loading…
Reference in a new issue