test(websocket): remove some duplication

This commit is contained in:
Houkime 2024-05-27 21:28:29 +00:00
parent 17ae162156
commit cb2a1421bf

View file

@ -34,6 +34,18 @@ jobUpdates {
"""
def api_subscribe(websocket, id, subscription):
websocket.send_json(
{
"id": id,
"type": "subscribe",
"payload": {
"query": "subscription TestSubscription {" + subscription + "}",
},
}
)
def connect_ws_authenticated(authorized_client) -> WebSocketTestSession:
token = "Bearer " + str(DEVICE_WE_AUTH_TESTS_WITH["token"])
return authorized_client.websocket_connect(
@ -104,24 +116,9 @@ def test_websocket_graphql_ping(authorized_client):
assert pong == {"type": "pong"}
def api_subscribe(websocket, id, subscription):
websocket.send_json(
{
"id": id,
"type": "subscribe",
"payload": {
"query": "subscription TestSubscription {" + subscription + "}",
},
}
)
def test_websocket_subscription_minimal(authorized_client):
def test_websocket_subscription_minimal(authorized_client, authenticated_websocket):
# Test a small endpoint that exists specifically for tests
client = authorized_client
with client.websocket_connect(
"/graphql", subprotocols=["graphql-transport-ws"]
) as websocket:
websocket = authenticated_websocket
init_graphql(websocket)
arbitrary_id = "3aaa2445"
api_subscribe(websocket, arbitrary_id, "count")