2023-06-14 10:09:38 +00:00
|
|
|
from tests.test_graphql.test_backup import dummy_service, backups, raw_dummy_service
|
2023-06-14 11:14:52 +00:00
|
|
|
from tests.common import generate_backup_query
|
2023-06-14 10:09:38 +00:00
|
|
|
|
2023-06-14 12:08:07 +00:00
|
|
|
|
|
|
|
from selfprivacy_api.graphql.common_types.service import service_to_graphql_service
|
2023-06-14 10:09:38 +00:00
|
|
|
from selfprivacy_api.jobs import Jobs, JobStatus
|
|
|
|
|
2023-06-14 11:14:52 +00:00
|
|
|
API_SNAPSHOTS_QUERY = """
|
|
|
|
allSnapshots {
|
|
|
|
id
|
|
|
|
service {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
createdAt
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2023-06-14 10:09:38 +00:00
|
|
|
API_BACK_UP_MUTATION = """
|
|
|
|
mutation TestBackupService($service_id: String) {
|
|
|
|
startBackup(serviceId: $service_id) {
|
|
|
|
success
|
|
|
|
message
|
|
|
|
code
|
|
|
|
job {
|
|
|
|
uid
|
|
|
|
status
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def api_backup(authorized_client, service):
|
|
|
|
response = authorized_client.post(
|
|
|
|
"/graphql",
|
|
|
|
json={
|
|
|
|
"query": API_BACK_UP_MUTATION,
|
|
|
|
"variables": {"service_id": service.get_id()},
|
|
|
|
},
|
|
|
|
).json()
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
2023-06-14 11:14:52 +00:00
|
|
|
def get_data(response):
|
|
|
|
assert response.status_code == 200
|
|
|
|
response = response.json()
|
2023-06-14 11:54:24 +00:00
|
|
|
if (
|
|
|
|
"errors" in response.keys()
|
|
|
|
): # convenience for debugging, this will display error
|
|
|
|
assert response["errors"] == []
|
2023-06-14 11:14:52 +00:00
|
|
|
assert response["data"] is not None
|
|
|
|
data = response["data"]
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2023-06-14 11:52:57 +00:00
|
|
|
def api_snapshots(authorized_client):
|
2023-06-14 11:14:52 +00:00
|
|
|
response = authorized_client.post(
|
|
|
|
"/graphql",
|
|
|
|
json={"query": generate_backup_query([API_SNAPSHOTS_QUERY])},
|
|
|
|
)
|
|
|
|
data = get_data(response)
|
|
|
|
result = data["backup"]["allSnapshots"]
|
|
|
|
assert result is not None
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2023-06-14 12:08:07 +00:00
|
|
|
def test_dummy_service_convertible_to_gql(dummy_service):
|
|
|
|
gql_service = service_to_graphql_service(dummy_service)
|
|
|
|
assert gql_service is not None
|
|
|
|
|
|
|
|
|
2023-06-14 11:14:52 +00:00
|
|
|
def test_snapshots_empty(authorized_client, dummy_service):
|
2023-06-14 11:52:57 +00:00
|
|
|
snaps = api_snapshots(authorized_client)
|
2023-06-14 11:14:52 +00:00
|
|
|
assert snaps == []
|
|
|
|
|
|
|
|
|
2023-06-14 10:09:38 +00:00
|
|
|
def test_start_backup(authorized_client, dummy_service):
|
|
|
|
response = api_backup(authorized_client, dummy_service)
|
|
|
|
assert response["data"]["startBackup"]["success"] is True
|
|
|
|
job = response["data"]["startBackup"]["job"]
|
|
|
|
assert Jobs.get_job(job["uid"]).status == JobStatus.FINISHED
|