Skip to content

Commit c7a79a5

Browse files
author
Joel Collins
committed
Improved socket coverage
1 parent 9be22f0 commit c7a79a5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_server_sockets.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,23 @@ def http_view_func():
129129
assert c.connect("/", message="hello") == ["hello"]
130130

131131

132+
def test_socket_middleware_add_view(app, ws_client):
133+
socket = gsocket.Sockets(app)
134+
135+
def ws_view_func(ws):
136+
msg = ws.recieve()
137+
ws.send(msg)
138+
139+
socket.add_view("/", ws_view_func)
140+
141+
# Assert ws_view_func was added to the Sockets URL map
142+
with ws_client as c:
143+
assert c.connect("/", message="hello") == ["hello"]
144+
145+
132146
def test_socket_middleware_http_fallback(app, ws_client):
147+
gsocket.Sockets(app)
148+
133149
@app.route("/")
134150
def http_view_func():
135151
return "GET"
@@ -139,6 +155,20 @@ def http_view_func():
139155
assert c.get("/").data == b"GET"
140156

141157

158+
def test_socket_middleware_ws_http_cookie(app, ws_client):
159+
socket = gsocket.Sockets(app)
160+
161+
@socket.route("/")
162+
def ws_view_func(ws):
163+
msg = ws.recieve()
164+
ws.send(msg)
165+
166+
# Assert ws_view_func was added to the Sockets URL map
167+
with ws_client as c:
168+
c.environ_base["HTTP_COOKIE"] = {"key": "value"}
169+
assert c.connect("/", message="hello") == ["hello"]
170+
171+
142172
def test_socket_handler_loop(fake_websocket):
143173
ws = fake_websocket("hello", recieve_once=True)
144174

0 commit comments

Comments
 (0)