test(tokens-repo): move token utils to graphql common
parent
137ae58b42
commit
de27032191
|
@ -1,3 +1,6 @@
|
||||||
|
from tests.common import generate_api_query
|
||||||
|
|
||||||
|
|
||||||
def assert_ok(response, request):
|
def assert_ok(response, request):
|
||||||
data = assert_data(response)
|
data = assert_data(response)
|
||||||
data[request]["success"] is True
|
data[request]["success"] is True
|
||||||
|
@ -22,3 +25,36 @@ def assert_data(response):
|
||||||
data = response.json().get("data")
|
data = response.json().get("data")
|
||||||
assert data is not None
|
assert data is not None
|
||||||
return data
|
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
|
||||||
|
|
|
@ -13,29 +13,15 @@ from tests.test_graphql.common import (
|
||||||
assert_empty,
|
assert_empty,
|
||||||
assert_ok,
|
assert_ok,
|
||||||
assert_errorcode,
|
assert_errorcode,
|
||||||
|
assert_token_valid,
|
||||||
|
graphql_get_devices,
|
||||||
|
request_devices,
|
||||||
|
set_client_token,
|
||||||
|
API_DEVICES_QUERY,
|
||||||
)
|
)
|
||||||
|
|
||||||
ORIGINAL_DEVICES = TOKENS_FILE_CONTENTS["tokens"]
|
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):
|
def graphql_get_caller_token_info(client):
|
||||||
devices = graphql_get_devices(client)
|
devices = graphql_get_devices(client)
|
||||||
|
@ -65,15 +51,6 @@ def assert_original(client):
|
||||||
assert device["isCaller"] is False
|
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:
|
def graphql_get_new_device_key(authorized_client) -> str:
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
|
@ -113,10 +90,7 @@ def test_graphql_tokens_info(authorized_client, tokens_file):
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_tokens_info_unauthorized(client, tokens_file):
|
def test_graphql_tokens_info_unauthorized(client, tokens_file):
|
||||||
response = client.post(
|
response = request_devices(client)
|
||||||
"/graphql",
|
|
||||||
json={"query": generate_api_query([API_DEVICES_QUERY])},
|
|
||||||
)
|
|
||||||
assert_empty(response)
|
assert_empty(response)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue