mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-22 08:46:37 +00:00
test(backups): setting autobackup period
This commit is contained in:
parent
b5e2499a30
commit
25f3115c05
|
@ -73,7 +73,11 @@ class BackupMutations:
|
||||||
self, period: typing.Optional[int] = None
|
self, period: typing.Optional[int] = None
|
||||||
) -> GenericBackupConfigReturn:
|
) -> GenericBackupConfigReturn:
|
||||||
"""Set autobackup period. None is to disable autobackup"""
|
"""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(
|
return GenericBackupConfigReturn(
|
||||||
success=True, message="", code="200", configuration=Backup().configuration()
|
success=True, message="", code="200", configuration=Backup().configuration()
|
||||||
)
|
)
|
||||||
|
|
|
@ -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.graphql.common_types.service import service_to_graphql_service
|
||||||
from selfprivacy_api.jobs import Jobs, JobStatus
|
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 = """
|
API_REMOVE_REPOSITORY_MUTATION = """
|
||||||
mutation TestRemoveRepo {
|
mutation TestRemoveRepo {
|
||||||
removeRepository {
|
removeRepository {
|
||||||
|
@ -103,6 +121,17 @@ def api_backup(authorized_client, service):
|
||||||
return response
|
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):
|
def api_remove(authorized_client):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
|
@ -236,3 +265,50 @@ def test_remove(authorized_client, generic_userdata):
|
||||||
# still generated every time it is missing
|
# still generated every time it is missing
|
||||||
assert len(configuration["encryptionKey"]) > 1
|
assert len(configuration["encryptionKey"]) > 1
|
||||||
assert configuration["isInitialized"] is False
|
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
|
||||||
|
|
Loading…
Reference in a new issue