From 25f3115c0554c92930cce83dbb6f5e4224680be3 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 19 Jun 2023 13:28:02 +0000 Subject: [PATCH] test(backups): setting autobackup period --- .../graphql/mutations/backup_mutations.py | 6 +- tests/test_graphql/test_api_backup.py | 76 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/selfprivacy_api/graphql/mutations/backup_mutations.py b/selfprivacy_api/graphql/mutations/backup_mutations.py index 1488a2c..ad7c0c6 100644 --- a/selfprivacy_api/graphql/mutations/backup_mutations.py +++ b/selfprivacy_api/graphql/mutations/backup_mutations.py @@ -73,7 +73,11 @@ class BackupMutations: self, period: typing.Optional[int] = None ) -> GenericBackupConfigReturn: """Set autobackup period. None is to disable autobackup""" - Backups.set_autobackup_period_minutes(period) + if period is not None: + Backups.set_autobackup_period_minutes(period) + else: + Backups.set_autobackup_period_minutes(0) + return GenericBackupConfigReturn( success=True, message="", code="200", configuration=Backup().configuration() ) diff --git a/tests/test_graphql/test_api_backup.py b/tests/test_graphql/test_api_backup.py index d65d6f1..b8c09dc 100644 --- a/tests/test_graphql/test_api_backup.py +++ b/tests/test_graphql/test_api_backup.py @@ -6,6 +6,24 @@ 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_SET_AUTOBACKUP_PERIOD_MUTATION = """ +mutation TestAutobackupPeriod($period: Int) { + setAutobackupPeriod(period: $period) { + success + message + code + configuration { + provider + encryptionKey + isInitialized + autobackupPeriod + locationName + locationId + } + } +} +""" + API_REMOVE_REPOSITORY_MUTATION = """ mutation TestRemoveRepo { removeRepository { @@ -103,6 +121,17 @@ def api_backup(authorized_client, service): return response +def api_set_period(authorized_client, period): + response = authorized_client.post( + "/graphql", + json={ + "query": API_SET_AUTOBACKUP_PERIOD_MUTATION, + "variables": {"period": period}, + }, + ) + return response + + def api_remove(authorized_client): response = authorized_client.post( "/graphql", @@ -236,3 +265,50 @@ def test_remove(authorized_client, generic_userdata): # still generated every time it is missing assert len(configuration["encryptionKey"]) > 1 assert configuration["isInitialized"] is False + + +def test_autobackup_period_nonzero(authorized_client): + new_period = 11 + response = api_set_period(authorized_client, new_period) + data = get_data(response)["setAutobackupPeriod"] + assert_ok(data) + + configuration = data["configuration"] + assert configuration["autobackupPeriod"] == new_period + + +def test_autobackup_period_zero(authorized_client): + new_period = 0 + # since it is none by default, we better first set it to something non-negative + response = api_set_period(authorized_client, 11) + # and now we nullify it + response = api_set_period(authorized_client, new_period) + data = get_data(response)["setAutobackupPeriod"] + assert_ok(data) + + configuration = data["configuration"] + assert configuration["autobackupPeriod"] == None + + +def test_autobackup_period_none(authorized_client): + # since it is none by default, we better first set it to something non-negative + response = api_set_period(authorized_client, 11) + # and now we nullify it + response = api_set_period(authorized_client, None) + data = get_data(response)["setAutobackupPeriod"] + assert_ok(data) + + configuration = data["configuration"] + assert configuration["autobackupPeriod"] == None + + +def test_autobackup_period_negative(authorized_client): + # since it is none by default, we better first set it to something non-negative + response = api_set_period(authorized_client, 11) + # and now we nullify it + response = api_set_period(authorized_client, -12) + data = get_data(response)["setAutobackupPeriod"] + assert_ok(data) + + configuration = data["configuration"] + assert configuration["autobackupPeriod"] == None