2023-02-03 17:04:35 +00:00
|
|
|
import pytest
|
2023-02-03 19:09:24 +00:00
|
|
|
import os.path as path
|
2023-02-03 17:04:35 +00:00
|
|
|
|
|
|
|
from selfprivacy_api.services.test_service import DummyService
|
|
|
|
|
2023-02-08 15:14:08 +00:00
|
|
|
from selfprivacy_api.backup import Backups
|
2023-02-01 11:58:55 +00:00
|
|
|
import selfprivacy_api.backup.providers as providers
|
|
|
|
from selfprivacy_api.backup.providers import AbstractBackupProvider
|
|
|
|
|
|
|
|
from selfprivacy_api.backup.providers.backblaze import Backblaze
|
|
|
|
from selfprivacy_api.graphql.queries.providers import BackupProvider
|
|
|
|
|
|
|
|
|
2023-02-03 19:09:24 +00:00
|
|
|
TESTFILE_BODY = "testytest!"
|
2023-02-08 14:05:25 +00:00
|
|
|
REPO_NAME = "test_backup"
|
2023-02-03 19:09:24 +00:00
|
|
|
|
|
|
|
|
2023-02-03 17:04:35 +00:00
|
|
|
@pytest.fixture()
|
2023-02-20 10:35:51 +00:00
|
|
|
def test_service(tmpdir, backups):
|
2023-02-03 19:09:24 +00:00
|
|
|
testile_path = path.join(tmpdir, "testfile.txt")
|
|
|
|
with open(testile_path, "w") as file:
|
|
|
|
file.write(TESTFILE_BODY)
|
2023-02-08 14:05:25 +00:00
|
|
|
|
|
|
|
# we need this to not change get_location() much
|
2023-02-08 15:14:08 +00:00
|
|
|
class TestDummyService(DummyService, location=tmpdir):
|
2023-02-08 14:05:25 +00:00
|
|
|
pass
|
|
|
|
|
2023-02-20 10:35:51 +00:00
|
|
|
service = TestDummyService()
|
|
|
|
backups.init_repo(service)
|
|
|
|
return service
|
2023-02-03 17:04:35 +00:00
|
|
|
|
|
|
|
|
2023-02-03 18:49:24 +00:00
|
|
|
@pytest.fixture()
|
2023-02-08 14:05:25 +00:00
|
|
|
def memory_backup() -> AbstractBackupProvider:
|
2023-02-03 18:49:24 +00:00
|
|
|
ProviderClass = providers.get_provider(BackupProvider.MEMORY)
|
|
|
|
assert ProviderClass is not None
|
|
|
|
memory_provider = ProviderClass(login="", key="")
|
|
|
|
assert memory_provider is not None
|
|
|
|
return memory_provider
|
|
|
|
|
|
|
|
|
2023-02-20 11:50:52 +00:00
|
|
|
@pytest.fixture()
|
|
|
|
def file_backup(tmpdir) -> AbstractBackupProvider:
|
|
|
|
test_repo_path = path.join(tmpdir, "test_repo")
|
|
|
|
ProviderClass = providers.get_provider(BackupProvider.FILE)
|
|
|
|
assert ProviderClass is not None
|
|
|
|
provider = ProviderClass(test_repo_path)
|
|
|
|
assert provider is not None
|
|
|
|
return provider
|
|
|
|
|
|
|
|
|
2023-02-08 15:14:08 +00:00
|
|
|
@pytest.fixture()
|
2023-02-20 13:51:06 +00:00
|
|
|
def backups(tmpdir):
|
|
|
|
test_repo_path = path.join(tmpdir, "test_repo")
|
|
|
|
return Backups(test_repo_path)
|
2023-02-08 15:14:08 +00:00
|
|
|
|
|
|
|
|
2023-02-01 11:58:55 +00:00
|
|
|
def test_select_backend():
|
|
|
|
provider = providers.get_provider(BackupProvider.BACKBLAZE)
|
|
|
|
assert provider is not None
|
|
|
|
assert provider == Backblaze
|
2023-02-03 17:04:35 +00:00
|
|
|
|
|
|
|
|
2023-02-20 11:50:52 +00:00
|
|
|
def test_file_backend_init(file_backup):
|
|
|
|
file_backup.backuper.init("somerepo")
|
|
|
|
|
|
|
|
|
2023-02-08 15:14:08 +00:00
|
|
|
def test_backup_simple(test_service, memory_backup):
|
2023-02-03 17:04:35 +00:00
|
|
|
# temporarily incomplete
|
|
|
|
assert test_service is not None
|
2023-02-03 18:49:24 +00:00
|
|
|
assert memory_backup is not None
|
2023-02-08 15:14:08 +00:00
|
|
|
memory_backup.backuper.start_backup(test_service.get_location(), REPO_NAME)
|
|
|
|
|
|
|
|
|
|
|
|
def test_backup_service(test_service, backups):
|
|
|
|
backups.back_up(test_service)
|
2023-02-13 11:16:35 +00:00
|
|
|
|
|
|
|
|
2023-02-17 15:55:19 +00:00
|
|
|
def test_no_repo(memory_backup):
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
assert memory_backup.backuper.get_snapshots("") == []
|
|
|
|
|
|
|
|
|
|
|
|
# def test_one_snapshot(backups, test_service):
|
|
|
|
# backups.back_up(test_service)
|
|
|
|
# assert len(backups.get_snapshots(test_service)) == 1
|