From 644a0b96b85df2cabd3f4a7f26fb1633b159cadd Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 7 Apr 2023 15:18:54 +0000 Subject: [PATCH] test(backups): test last backup date retrieval --- selfprivacy_api/backup/__init__.py | 3 ++- tests/test_graphql/test_backup.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/selfprivacy_api/backup/__init__.py b/selfprivacy_api/backup/__init__.py index f58d4c4..7e73ebd 100644 --- a/selfprivacy_api/backup/__init__.py +++ b/selfprivacy_api/backup/__init__.py @@ -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 diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index 31ecefa..f6ad24a 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -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):