Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Websocket testing .recv() #53

Closed
jmgirven opened this issue Aug 10, 2022 · 1 comment
Closed

[Bug] Websocket testing .recv() #53

jmgirven opened this issue Aug 10, 2022 · 1 comment

Comments

@jmgirven
Copy link

I am trying to test a websocket endpoint that uses websocket.recv() inside, but this method is throwing an exception.

Error

ERROR    sanic.error:handlers.py:183 Exception occurred while handling uri: 'http:///ws'
Traceback (most recent call last):
  File "/worker/.local/lib/python3.7/site-packages/sanic/app.py", line 971, in _websocket_handler
    await fut
  File "/app/application_tests/test_sanic_testing.py", line 18, in handler
    await ws.recv()
  File "/worker/.local/lib/python3.7/site-packages/sanic/server/websockets/connection.py", line 49, in recv
    if message["type"] == "websocket.receive":
KeyError: 'type'

How to reproduce

  1. Create new venv and install packages
  2. Create test_test.py file with this contents
import pytest
from sanic import Sanic

from sanic_testing import TestManager


@pytest.fixture
def app():
    sanic_app = Sanic("test")
    TestManager(sanic_app)
    return sanic_app


@pytest.mark.asyncio
async def test_websocket_route(app):
    @app.websocket("/ws")
    async def handler(request, ws):
        await ws.recv()

    await app.asgi_client.websocket("/ws")
  1. Run pytest and see the error message

Requirements

Python 3.7

pytest-asyncio==0.19.0
sanic==22.6.1
sanic-testing==22.6.0
@ahopkins
Copy link
Member

Resolved by sanic-org/sanic#2640

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants