Skip to content

Commit

Permalink
Fix websockets tests for new Starlette (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp authored Feb 5, 2024
1 parent df300a4 commit 146e7d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tests/asgi/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,13 @@ def test_init_wait_timeout_graphql_transport_ws(
app = GraphQL(schema, websocket_handler=websocket_handler)
client = TestClient(app)

with pytest.raises(WebSocketDisconnect, match="4408"):
with pytest.raises(WebSocketDisconnect) as exc_info:
with client.websocket_connect("/", ["graphql-transport-ws"]) as ws:
time.sleep(0.1)
ws.receive_json()

assert exc_info.value.code == 4408


@pytest.mark.xfail(reason="sometimes fails due to a race condition")
def test_handle_connection_init_timeout_handler_executed_graphql_transport_ws(
Expand Down
15 changes: 12 additions & 3 deletions tests/asgi/test_websockets_graphql_transport_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,12 @@ def test_too_many_connection_init_messages_graphql_transport_ws(
response = ws.receive_json()
assert response["type"] == GraphQLTransportWSHandler.GQL_CONNECTION_ACK
ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT})
with pytest.raises(WebSocketDisconnect, match="4429"):

with pytest.raises(WebSocketDisconnect) as exc_info:
ws.receive_json()

assert exc_info.value.code == 4429


def test_get_operation_type():
graphql_document = parse("subscription ping {ping} query other { dummy }")
Expand All @@ -796,9 +799,12 @@ def test_connection_not_acknowledged_graphql_transport_ws(
"payload": {"query": "subscription { ping }"},
}
)
with pytest.raises(WebSocketDisconnect, match="4401"):

with pytest.raises(WebSocketDisconnect) as exc_info:
ws.receive_json()

assert exc_info.value.code == 4401


def test_duplicate_operation_id_graphql_transport_ws(
client_graphql_transport_ws,
Expand All @@ -822,9 +828,12 @@ def test_duplicate_operation_id_graphql_transport_ws(
}
)
ws.receive_json()
with pytest.raises(WebSocketDisconnect, match="4409"):

with pytest.raises(WebSocketDisconnect) as exc_info:
ws.receive_json()

assert exc_info.value.code == 4409


def test_invalid_operation_id_is_handled_graphql_transport_ws(
client_graphql_transport_ws,
Expand Down

0 comments on commit 146e7d7

Please sign in to comment.