Skip to content

Commit 3a2aef8

Browse files
author
Joel Collins
committed
Added basic fake websocket client
1 parent 6d8e351 commit 3a2aef8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/conftest.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,38 @@ def schemas_path(app):
127127
@pytest.fixture
128128
def extensions_path(app):
129129
return os.path.join(os.path.dirname(__file__), "extensions")
130+
131+
132+
class FakeWebsocket:
133+
def __init__(self, message: str, recieve_once=True):
134+
self.message = message
135+
self.response = None
136+
self.closed = False
137+
self.recieve_once = recieve_once
138+
139+
def receive(self):
140+
# Get message
141+
message_to_send = self.message
142+
# If only sending a message to the server once
143+
if self.recieve_once:
144+
# Clear our message
145+
self.message = None
146+
return message_to_send
147+
148+
def send(self, response):
149+
self.response = response
150+
self.closed = True
151+
return response
152+
153+
154+
@pytest.fixture
155+
def fake_websocket():
156+
"""
157+
Return a fake websocket client
158+
that sends a given message, waits for a response, then closes
159+
"""
160+
161+
def _foo(msg, recieve_once=True):
162+
return FakeWebsocket(msg, recieve_once=recieve_once)
163+
164+
return _foo

0 commit comments

Comments
 (0)