test(tokens-repo): break out assert_ok() and assert_errorcode() in graphql

redis/connection-pool
Houkime 2023-01-04 14:01:23 +00:00 committed by Inex Code
parent d8c78cc14c
commit 7f5236701e
1 changed files with 18 additions and 10 deletions

View File

@ -62,6 +62,22 @@ def assert_original(client):
assert device["isCaller"] is False
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
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
def test_graphql_tokens_info(authorized_client, tokens_file):
assert_original(authorized_client)
@ -114,11 +130,7 @@ def test_graphql_delete_token(authorized_client, tokens_file):
},
},
)
assert response.status_code == 200
assert response.json().get("data") is not None
assert response.json()["data"]["deleteDeviceApiToken"]["success"] is True
assert response.json()["data"]["deleteDeviceApiToken"]["message"] is not None
assert response.json()["data"]["deleteDeviceApiToken"]["code"] == 200
assert_ok(response, "deleteDeviceApiToken")
devices = graphql_get_devices(authorized_client)
assert_same(devices, test_devices)
@ -134,11 +146,7 @@ def test_graphql_delete_self_token(authorized_client, tokens_file):
},
},
)
assert response.status_code == 200
assert response.json().get("data") is not None
assert response.json()["data"]["deleteDeviceApiToken"]["success"] is False
assert response.json()["data"]["deleteDeviceApiToken"]["message"] is not None
assert response.json()["data"]["deleteDeviceApiToken"]["code"] == 400
assert_errorcode(response, "deleteDeviceApiToken", 400)
assert_original(authorized_client)