From 0ae4192081ce66fb128244df1b8ad62133dbc73f Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 12 Apr 2023 17:18:12 +0000 Subject: [PATCH] test(backups): register dummy service --- selfprivacy_api/backup/__init__.py | 3 --- tests/test_graphql/test_backup.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/selfprivacy_api/backup/__init__.py b/selfprivacy_api/backup/__init__.py index d9b811c..674abf0 100644 --- a/selfprivacy_api/backup/__init__.py +++ b/selfprivacy_api/backup/__init__.py @@ -57,7 +57,6 @@ class Backups: services = Storage.services_with_autobackup() return [id for id in services if Backups.is_time_to_backup_service(id, time)] - # untestable until the dummy service is registered @staticmethod def services_to_back_up(time: datetime) -> List[Service]: result = [] @@ -243,7 +242,6 @@ class Backups: Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folder) - # Our dummy service is not yet globally registered so this is not testable yet @staticmethod def restore_snapshot(snapshot: Snapshot): Backups.restore_service_from_snapshot( @@ -255,7 +253,6 @@ class Backups: repo_name = service.get_id() return Backups.provider().backuper.restored_size(repo_name, snapshot_id) - # Our dummy service is not yet globally registered so this is not testable yet @staticmethod def snapshot_restored_size(snapshot: Snapshot) -> float: return Backups.service_snapshot_size( diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index 710e7b8..4d4f421 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -5,6 +5,8 @@ from os import remove from os import listdir from datetime import datetime, timedelta, timezone +import selfprivacy_api.services as services +from selfprivacy_api.services import get_service_by_id from selfprivacy_api.services.test_service import DummyService from selfprivacy_api.graphql.queries.providers import BackupProvider @@ -58,6 +60,11 @@ def dummy_service(tmpdir, backups, raw_dummy_service): # assert not repo_path Backups.init_repo(service) + + # register our service + services.services.append(service) + + assert get_service_by_id(service.get_id()) is not None return service @@ -354,3 +361,15 @@ def test_provider_storage(backups_backblaze): assert isinstance(restored_provider, Backblaze) assert restored_provider.login == "ID" assert restored_provider.key == "KEY" + + +def test_services_to_back_up(backups, dummy_service): + backup_period = 13 # minutes + now = datetime.now(timezone.utc) + + Backups.enable_autobackup(dummy_service) + Backups.set_autobackup_period_minutes(backup_period) + + services = Backups.services_to_back_up(now) + assert len(services) == 1 + assert services[0].get_id() == dummy_service.get_id() \ No newline at end of file