test(backups): register dummy service

This commit is contained in:
Houkime 2023-04-12 17:18:12 +00:00
parent 4018dca184
commit 0ae4192081
2 changed files with 19 additions and 3 deletions

View file

@ -57,7 +57,6 @@ class Backups:
services = Storage.services_with_autobackup() services = Storage.services_with_autobackup()
return [id for id in services if Backups.is_time_to_backup_service(id, time)] return [id for id in services if Backups.is_time_to_backup_service(id, time)]
# untestable until the dummy service is registered
@staticmethod @staticmethod
def services_to_back_up(time: datetime) -> List[Service]: def services_to_back_up(time: datetime) -> List[Service]:
result = [] result = []
@ -243,7 +242,6 @@ class Backups:
Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folder) 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 @staticmethod
def restore_snapshot(snapshot: Snapshot): def restore_snapshot(snapshot: Snapshot):
Backups.restore_service_from_snapshot( Backups.restore_service_from_snapshot(
@ -255,7 +253,6 @@ class Backups:
repo_name = service.get_id() repo_name = service.get_id()
return Backups.provider().backuper.restored_size(repo_name, snapshot_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 @staticmethod
def snapshot_restored_size(snapshot: Snapshot) -> float: def snapshot_restored_size(snapshot: Snapshot) -> float:
return Backups.service_snapshot_size( return Backups.service_snapshot_size(

View file

@ -5,6 +5,8 @@ from os import remove
from os import listdir from os import listdir
from datetime import datetime, timedelta, timezone 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.services.test_service import DummyService
from selfprivacy_api.graphql.queries.providers import BackupProvider from selfprivacy_api.graphql.queries.providers import BackupProvider
@ -58,6 +60,11 @@ def dummy_service(tmpdir, backups, raw_dummy_service):
# assert not repo_path # assert not repo_path
Backups.init_repo(service) Backups.init_repo(service)
# register our service
services.services.append(service)
assert get_service_by_id(service.get_id()) is not None
return service return service
@ -354,3 +361,15 @@ def test_provider_storage(backups_backblaze):
assert isinstance(restored_provider, Backblaze) assert isinstance(restored_provider, Backblaze)
assert restored_provider.login == "ID" assert restored_provider.login == "ID"
assert restored_provider.key == "KEY" 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()