From 4676e364a69f18eab960fb31b0e46fcf3d55ac4a Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 4 Jan 2023 14:22:14 +0000 Subject: [PATCH] test(tokens-repo): break out assert_data() --- tests/test_graphql/test_api_devices.py | 30 +++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/test_graphql/test_api_devices.py b/tests/test_graphql/test_api_devices.py index 90f1685..3104874 100644 --- a/tests/test_graphql/test_api_devices.py +++ b/tests/test_graphql/test_api_devices.py @@ -34,9 +34,8 @@ def graphql_get_devices(client): "/graphql", json={"query": generate_api_query([API_DEVICES_QUERY])}, ) - assert response.status_code == 200 - assert response.json().get("data") is not None - devices = response.json()["data"]["api"]["devices"] + data = assert_data(response) + devices = data["api"]["devices"] assert devices is not None return devices @@ -63,19 +62,17 @@ def assert_original(client): def assert_ok(response, request): - assert response.status_code == 200 - assert response.json().get("data") is not None - assert response.json()["data"][request]["success"] is True - assert response.json()["data"][request]["message"] is not None - assert response.json()["data"][request]["code"] == 200 + data = assert_data(response) + data[request]["success"] is True + data[request]["message"] is not None + data[request]["code"] == 200 def assert_errorcode(response, request, code): - assert response.status_code == 200 - assert response.json().get("data") is not None - assert response.json()["data"][request]["success"] is False - assert response.json()["data"][request]["message"] is not None - assert response.json()["data"][request]["code"] == code + data = assert_data(response) + data[request]["success"] is False + data[request]["message"] is not None + data[request]["code"] == code def assert_empty(response): @@ -83,6 +80,13 @@ def assert_empty(response): assert response.json().get("data") is None +def assert_data(response): + assert response.status_code == 200 + data = response.json().get("data") + assert data is not None + return data + + def test_graphql_tokens_info(authorized_client, tokens_file): assert_original(authorized_client)