2024-05-15 18:15:16 +00:00
|
|
|
from tests.common import generate_jobs_subscription
|
|
|
|
from selfprivacy_api.graphql.queries.jobs import Job as _Job
|
|
|
|
from selfprivacy_api.jobs import Jobs
|
|
|
|
|
|
|
|
# JOBS_SUBSCRIPTION = """
|
|
|
|
# jobUpdates {
|
|
|
|
# uid
|
|
|
|
# typeId
|
|
|
|
# name
|
|
|
|
# description
|
|
|
|
# status
|
|
|
|
# statusText
|
|
|
|
# progress
|
|
|
|
# createdAt
|
|
|
|
# updatedAt
|
|
|
|
# finishedAt
|
|
|
|
# error
|
|
|
|
# result
|
|
|
|
# }
|
|
|
|
# """
|
|
|
|
|
2024-05-15 11:29:20 +00:00
|
|
|
|
|
|
|
def test_websocket_connection_bare(authorized_client):
|
2024-05-15 18:15:16 +00:00
|
|
|
client = authorized_client
|
|
|
|
with client.websocket_connect(
|
|
|
|
"/graphql", subprotocols=["graphql-transport-ws", "graphql-ws"]
|
|
|
|
) as websocket:
|
2024-05-15 11:29:20 +00:00
|
|
|
assert websocket is not None
|
|
|
|
assert websocket.scope is not None
|
2024-05-15 18:15:16 +00:00
|
|
|
|
|
|
|
|
2024-05-15 18:36:17 +00:00
|
|
|
def test_websocket_graphql_init(authorized_client):
|
2024-05-15 18:15:16 +00:00
|
|
|
client = authorized_client
|
|
|
|
with client.websocket_connect(
|
|
|
|
"/graphql", subprotocols=["graphql-transport-ws"]
|
|
|
|
) as websocket:
|
|
|
|
websocket.send_json({"type": "connection_init", "payload": {}})
|
|
|
|
ack = websocket.receive_json()
|
|
|
|
assert ack == {"type": "connection_ack"}
|
|
|
|
|
2024-05-15 18:36:17 +00:00
|
|
|
|
|
|
|
def test_websocket_graphql_ping(authorized_client):
|
|
|
|
client = authorized_client
|
|
|
|
with client.websocket_connect(
|
|
|
|
"/graphql", subprotocols=["graphql-transport-ws"]
|
|
|
|
) as websocket:
|
2024-05-15 18:31:16 +00:00
|
|
|
# https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md#ping
|
|
|
|
websocket.send_json({"type": "ping", "payload": {}})
|
|
|
|
pong = websocket.receive_json()
|
|
|
|
assert pong == {"type": "pong"}
|
|
|
|
|
2024-05-15 18:15:16 +00:00
|
|
|
|
|
|
|
# def test_websocket_subscription(authorized_client):
|
|
|
|
# client = authorized_client
|
|
|
|
# with client.websocket_connect(
|
|
|
|
# "/graphql", subprotocols=["graphql-transport-ws", "graphql-ws"]
|
|
|
|
# ) as websocket:
|
|
|
|
# websocket.send(generate_jobs_subscription([JOBS_SUBSCRIPTION]))
|
|
|
|
# Jobs.add("bogus","bogus.bogus", "yyyaaaaayy")
|
|
|
|
# joblist = websocket.receive_json()
|
|
|
|
# raise NotImplementedError(joblist)
|