Skip to content

Commit

Permalink
make websockets backend use sync .send like base (#27)
Browse files Browse the repository at this point in the history
* make websockets backend use sync .send like base

* fix tests now that websocket backend send is sync

* flake8!
  • Loading branch information
Matt Kafonek authored Aug 11, 2022
1 parent 043ebec commit 4164ef7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sending/backends/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def on_auth(self, message: Any):
"""
self.authed_ws.set_result(self.unauth_ws.result())

async def send(self, message: Any):
def send(self, message: Any):
"""
Override the default Sending behavior to only accept a message instead of topic + message.
Topic is not a concept supported in this Backend.
Expand Down
12 changes: 6 additions & 6 deletions tests/test_websocket_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def test_basic_send(manager: WebsocketManager):
"""
await manager.initialize()
assert manager.auth_hook is None
await manager.send(json.dumps({"type": "unauthed_echo_request", "text": "Hello plain_manager"}))
manager.send(json.dumps({"type": "unauthed_echo_request", "text": "Hello plain_manager"}))
await asyncio.wait_for(manager.next_event.wait(), 1)
reply = json.loads(manager.last_seen_message)
assert reply == {"type": "unauthed_echo_reply", "text": "Hello plain_manager"}
Expand All @@ -77,7 +77,7 @@ async def test_message_hooks(json_manager: WebsocketManager):
Test that the inbound and outbound message hooks serialize/deserialize json
"""
await json_manager.initialize()
await json_manager.send({"type": "unauthed_echo_request", "text": "Hello json_manager"})
json_manager.send({"type": "unauthed_echo_request", "text": "Hello json_manager"})
reply = await run_until_message_type(json_manager, "unauthed_echo_reply")
assert reply == {"type": "unauthed_echo_reply", "text": "Hello json_manager"}

Expand All @@ -88,7 +88,7 @@ async def test_init_hook(json_manager: WebsocketManager):
"""

async def init_hook(mgr: WebsocketManager):
await mgr.send({"type": "unauthed_echo_request", "text": "Hello init_hook"})
mgr.send({"type": "unauthed_echo_request", "text": "Hello init_hook"})

json_manager.init_hook = init_hook
await json_manager.initialize()
Expand Down Expand Up @@ -159,7 +159,7 @@ async def auth_hook(mgr: WebsocketManager):
)
await json_manager.initialize()
# test that we're authenticated on the server side
await json_manager.send({"type": "authed_echo_request", "text": "Hello auth"})
json_manager.send({"type": "authed_echo_request", "text": "Hello auth"})
reply = await run_until_message_type(json_manager, "authed_echo_reply")
assert reply == {"type": "authed_echo_reply", "text": "Hello auth"}

Expand All @@ -168,7 +168,7 @@ async def auth_hook(mgr: WebsocketManager):
resp = await client.get(f"/disconnect/{token}")
assert resp.status_code == 204

await json_manager.send({"type": "authed_echo_request", "text": "Hello auth2"})
json_manager.send({"type": "authed_echo_request", "text": "Hello auth2"})
reply = await run_until_message_type(json_manager, "authed_echo_reply")
assert reply == {"type": "authed_echo_reply", "text": "Hello auth2"}

Expand Down Expand Up @@ -202,7 +202,7 @@ async def auth_hook(self, mgr):

mgr = Sub(ws_url=websocket_server.ws_base + "/ws")
await mgr.initialize()
await mgr.send({"type": "authed_echo_request", "text": "Hello subclass"})
mgr.send({"type": "authed_echo_request", "text": "Hello subclass"})
reply = await run_until_message_type(mgr, "authed_echo_reply")
assert reply == {"type": "authed_echo_reply", "text": "Hello subclass"}
await mgr.shutdown()

0 comments on commit 4164ef7

Please sign in to comment.