Skip to content

Commit

Permalink
Add test for filling out missing websocket.disconnect code
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Mar 22, 2023
1 parent 8810e35 commit 3e39873
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,22 @@ async def app(scope, receive, send):
with pytest.raises(RuntimeError):
with client.websocket_connect("/") as websocket:
websocket.send({"type": "websocket.connect"})


def test_send_disconnect_no_code(test_client_factory):
close_msg: Message = {}

async def app(scope: Scope, receive: Receive, send: Send) -> None:
nonlocal close_msg
websocket = WebSocket(scope, receive=receive, send=send)
await websocket.accept()
close_msg = await websocket.receive()

client = test_client_factory(app)
with client.websocket_connect("/") as websocket:
websocket.send({"type": "websocket.disconnect"})

assert close_msg == {
"type": "websocket.disconnect",
"code": status.WS_1005_NO_STATUS_RCVD,
}

0 comments on commit 3e39873

Please sign in to comment.