Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix websockets tests for new Starlette #1151

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading