test(backups): register dummy service

This commit is contained in:
Houkime 2023-04-12 17:18:12 +00:00 committed by Inex Code
parent a7feda02ec
commit 5101f41437
2 changed files with 19 additions and 3 deletions

View file

@ -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(

View file

@ -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()