From e3a87f1d982df083f72ee06f26bc77556b01f1f0 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 19 Jun 2023 14:12:40 +0000 Subject: [PATCH] test(backups): ensure asking to reload snaps does not explode the server --- selfprivacy_api/backup/backuppers/__init__.py | 2 +- .../backup/backuppers/none_backupper.py | 4 +- tests/test_graphql/test_api_backup.py | 46 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/selfprivacy_api/backup/backuppers/__init__.py b/selfprivacy_api/backup/backuppers/__init__.py index 61ef1ba..f20496d 100644 --- a/selfprivacy_api/backup/backuppers/__init__.py +++ b/selfprivacy_api/backup/backuppers/__init__.py @@ -21,7 +21,7 @@ class AbstractBackuper(ABC): raise NotImplementedError @abstractmethod - def get_snapshots(self, repo_name) -> List[Snapshot]: + def get_snapshots(self) -> List[Snapshot]: """Get all snapshots from the repo""" raise NotImplementedError diff --git a/selfprivacy_api/backup/backuppers/none_backupper.py b/selfprivacy_api/backup/backuppers/none_backupper.py index de51d6a..e687323 100644 --- a/selfprivacy_api/backup/backuppers/none_backupper.py +++ b/selfprivacy_api/backup/backuppers/none_backupper.py @@ -14,9 +14,9 @@ class NoneBackupper(AbstractBackuper): def start_backup(self, folders: List[str], repo_name: str): raise NotImplementedError - def get_snapshots(self, repo_name) -> List[Snapshot]: + def get_snapshots(self) -> List[Snapshot]: """Get all snapshots from the repo""" - raise NotImplementedError + return [] def init(self, repo_name): raise NotImplementedError diff --git a/tests/test_graphql/test_api_backup.py b/tests/test_graphql/test_api_backup.py index b8c09dc..3eed12a 100644 --- a/tests/test_graphql/test_api_backup.py +++ b/tests/test_graphql/test_api_backup.py @@ -6,6 +6,16 @@ from tests.common import generate_backup_query from selfprivacy_api.graphql.common_types.service import service_to_graphql_service from selfprivacy_api.jobs import Jobs, JobStatus +API_RELOAD_SNAPSHOTS = """ +mutation TestSnapshotsReload { + forceSnapshotsReload { + success + message + code + } +} +""" + API_SET_AUTOBACKUP_PERIOD_MUTATION = """ mutation TestAutobackupPeriod($period: Int) { setAutobackupPeriod(period: $period) { @@ -143,6 +153,17 @@ def api_remove(authorized_client): return response +def api_reload_snapshots(authorized_client): + response = authorized_client.post( + "/graphql", + json={ + "query": API_RELOAD_SNAPSHOTS, + "variables": {}, + }, + ) + return response + + def api_init_without_key( authorized_client, kind, login, password, location_name, location_id ): @@ -312,3 +333,28 @@ def test_autobackup_period_negative(authorized_client): configuration = data["configuration"] assert configuration["autobackupPeriod"] == None + + +# We cannot really check the effect at this level, we leave it to backend tests +# But we still make it run in both empty and full scenarios and ask for snaps afterwards +def test_reload_snapshots_bare_bare_bare(authorized_client, dummy_service): + api_remove(authorized_client) + + response = api_reload_snapshots(authorized_client) + data = get_data(response)["forceSnapshotsReload"] + assert_ok(data) + + snaps = api_snapshots(authorized_client) + assert snaps == [] + + +def test_reload_snapshots(authorized_client, dummy_service): + response = api_backup(authorized_client, dummy_service) + data = get_data(response)["startBackup"] + + response = api_reload_snapshots(authorized_client) + data = get_data(response)["forceSnapshotsReload"] + assert_ok(data) + + snaps = api_snapshots(authorized_client) + assert len(snaps) == 1