From c4aa757ca4f23b1fd1d7a47825a7f5bcd31e8efa Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 15 May 2024 13:01:07 +0000 Subject: [PATCH] test(jobs): test Graphql job getting --- tests/common.py | 4 +++ tests/test_graphql/test_jobs.py | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/test_graphql/test_jobs.py diff --git a/tests/common.py b/tests/common.py index 5f69f3f..8c81f48 100644 --- a/tests/common.py +++ b/tests/common.py @@ -69,6 +69,10 @@ def generate_backup_query(query_array): return "query TestBackup {\n backup {" + "\n".join(query_array) + "}\n}" +def generate_jobs_query(query_array): + return "query TestJobs {\n jobs {" + "\n".join(query_array) + "}\n}" + + def generate_service_query(query_array): return "query TestService {\n services {" + "\n".join(query_array) + "}\n}" diff --git a/tests/test_graphql/test_jobs.py b/tests/test_graphql/test_jobs.py new file mode 100644 index 0000000..8dfb102 --- /dev/null +++ b/tests/test_graphql/test_jobs.py @@ -0,0 +1,48 @@ +from tests.common import generate_jobs_query +from tests.test_graphql.common import ( + assert_ok, + assert_empty, + assert_errorcode, + get_data, +) + +API_JOBS_QUERY = """ +getJobs { + uid + typeId + name + description + status + statusText + progress + createdAt + updatedAt + finishedAt + error + result +} +""" + + +def graphql_send_query(client, query: str, variables: dict = {}): + return client.post("/graphql", json={"query": query, "variables": variables}) + + +def api_jobs(authorized_client): + response = graphql_send_query( + authorized_client, generate_jobs_query([API_JOBS_QUERY]) + ) + data = get_data(response) + result = data["jobs"]["getJobs"] + assert result is not None + return result + + +def test_all_jobs_unauthorized(client): + response = graphql_send_query(client, generate_jobs_query([API_JOBS_QUERY])) + assert_empty(response) + + +def test_all_jobs_when_none(authorized_client): + output = api_jobs(authorized_client) + assert output == []