test(websocket.py): add tests for websocket connection, chat history and sending message
This commit is contained in:
parent
e4d0a39b0b
commit
18b3583850
9 changed files with 226 additions and 37 deletions
30
tests/test_websocket.py
Normal file
30
tests/test_websocket.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import json
|
||||
|
||||
|
||||
def test_websocket_connection(client):
|
||||
with client.websocket_connect("/ws") as websocket:
|
||||
assert websocket.client == client
|
||||
assert websocket.url.path == "/ws"
|
||||
|
||||
|
||||
def test_chat_history(client):
|
||||
chat_history = ["Test message 1", "Test message 2"]
|
||||
|
||||
with client.websocket_connect("/ws") as websocket:
|
||||
received_history = websocket.receive_text()
|
||||
received_history = json.loads(received_history)
|
||||
|
||||
assert received_history == chat_history
|
||||
|
||||
|
||||
def test_send_message(client, basic_graph):
|
||||
with client.websocket_connect("/ws") as websocket:
|
||||
# Send the JSON payload through the WebSocket connection
|
||||
websocket.send_text(basic_graph)
|
||||
|
||||
# Receive and parse the response from the server
|
||||
response = websocket.receive_text()
|
||||
response = json.loads(response)
|
||||
|
||||
# Test that the response is as expected
|
||||
assert response == "Your response message here"
|
||||
Loading…
Add table
Add a link
Reference in a new issue