test(tokens-repo): move token utils to graphql common

redis/connection-pool
Houkime 2023-01-06 11:46:17 +00:00 committed by Inex Code
parent 137ae58b42
commit de27032191
2 changed files with 42 additions and 32 deletions

View File

@ -1,3 +1,6 @@
from tests.common import generate_api_query
def assert_ok(response, request):
data = assert_data(response)
data[request]["success"] is True
@ -22,3 +25,36 @@ def assert_data(response):
data = response.json().get("data")
assert data is not None
return data
API_DEVICES_QUERY = """
devices {
creationDate
isCaller
name
}
"""
def request_devices(client):
return client.post(
"/graphql",
json={"query": generate_api_query([API_DEVICES_QUERY])},
)
def graphql_get_devices(client):
response = request_devices(client)
data = assert_data(response)
devices = data["api"]["devices"]
assert devices is not None
return devices
def set_client_token(client, token):
client.headers.update({"Authorization": "Bearer " + token})
def assert_token_valid(client, token):
set_client_token(client, token)
assert graphql_get_devices(client) is not None

View File

@ -13,29 +13,15 @@ from tests.test_graphql.common import (
assert_empty,
assert_ok,
assert_errorcode,
assert_token_valid,
graphql_get_devices,
request_devices,
set_client_token,
API_DEVICES_QUERY,
)
ORIGINAL_DEVICES = TOKENS_FILE_CONTENTS["tokens"]
API_DEVICES_QUERY = """
devices {
creationDate
isCaller
name
}
"""
def graphql_get_devices(client):
response = client.post(
"/graphql",
json={"query": generate_api_query([API_DEVICES_QUERY])},
)
data = assert_data(response)
devices = data["api"]["devices"]
assert devices is not None
return devices
def graphql_get_caller_token_info(client):
devices = graphql_get_devices(client)
@ -65,15 +51,6 @@ def assert_original(client):
assert device["isCaller"] is False
def set_client_token(client, token):
client.headers.update({"Authorization": "Bearer " + token})
def assert_token_valid(client, token):
set_client_token(client, token)
assert graphql_get_devices(client) is not None
def graphql_get_new_device_key(authorized_client) -> str:
response = authorized_client.post(
"/graphql",
@ -113,10 +90,7 @@ def test_graphql_tokens_info(authorized_client, tokens_file):
def test_graphql_tokens_info_unauthorized(client, tokens_file):
response = client.post(
"/graphql",
json={"query": generate_api_query([API_DEVICES_QUERY])},
)
response = request_devices(client)
assert_empty(response)